patch 9fdc513df921e5f956b93feb4f061add2c55c548
Author: E. Bosch <presidev@AT@gmail.com>
Date: Wed Apr 26 20:45:17 CEST 2023
* telegram: Rename option 'reply_length' as 'quote_length' and use it for quotes in reactions as well (not only for replies)
diff -rN -u old-irgramd/irgramd new-irgramd/irgramd
--- old-irgramd/irgramd 2024-11-22 15:38:38.684909747 +0100
+++ new-irgramd/irgramd 2024-11-22 15:38:38.684909747 +0100
@@ -80,7 +80,7 @@
tornado.options.define('pam', default=False, help='Use PAM for IRC authentication, if not set you should set `irc_password`')
tornado.options.define('pam_group', default=None, metavar='GROUP', help='Unix group allowed if `pam` enabled, if empty any user is allowed')
tornado.options.define('phone', default=None, metavar='PHONE_NUMBER', help='Phone number associated with the Telegram account to receive the authorization codes if necessary')
- tornado.options.define('reply_length', default=50, metavar='LENGTH', help='Max length of the text refered in replies, if longer is truncated')
+ tornado.options.define('quote_length', default=50, metavar='LENGTH', help='Max length of the text quoted in replies and reactions, if longer is truncated')
tornado.options.define('service_user', default='TelegramServ', metavar='SERVICE_NICK', help='Nick of the service/control user, must be a nick not used by a real Telegram user')
tornado.options.define('test', default=False, help='Connect to Telegram test environment')
tornado.options.define('test_datacenter', default=2, metavar='DATACENTER_NUMBER', help='Datacenter to connect to Telegram test environment')
diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py
--- old-irgramd/telegram.py 2024-11-22 15:38:38.684909747 +0100
+++ new-irgramd/telegram.py 2024-11-22 15:38:38.688909741 +0100
@@ -22,7 +22,7 @@
from include import CHAN_MAX_LENGHT, NICK_MAX_LENGTH
from irc import IRCUser
-from utils import sanitize_filename, is_url_equiv, extract_url, get_human_size, get_human_duration, get_highlighted
+from utils import sanitize_filename, is_url_equiv, extract_url, get_human_size, get_human_duration, get_highlighted, fix_braces
from emoji2emoticon import emo
# Test IP table
@@ -47,7 +47,7 @@
self.test_ip = settings['test_host'] if settings['test_host'] else TEST_IPS[self.test_dc]
self.test_port = settings['test_port']
self.ask_code = settings['ask_code']
- self.reply_len = settings['reply_length']
+ self.quote_len = settings['quote_length']
self.media_cn = 0
self.irc = irc
self.authorized = False
@@ -387,8 +387,9 @@
# Reactions
else:
action = 'React'
- if len(message_rendered) > 50:
- text_old = '{}...'.format(message_rendered[:50])
+ if len(message_rendered) > self.quote_len:
+ text_old = '{}...'.format(message_rendered[:self.quote_len])
+ text_old = fix_braces(text_old)
else:
text_old = message_rendered
@@ -528,8 +529,8 @@
message = replied.message
if not message:
message = '[{}]'.format(self.mid.num_to_id_offset(replied.id))
- elif len(message) > self.reply_len:
- message = message[:self.reply_len]
+ elif len(message) > self.quote_len:
+ message = message[:self.quote_len]
trunc = '...'
replied_user = self.get_irc_user_from_telegram(replied.sender_id)
if replied_user is None:
diff -rN -u old-irgramd/utils.py new-irgramd/utils.py
--- old-irgramd/utils.py 2024-11-22 15:38:38.684909747 +0100
+++ new-irgramd/utils.py 2024-11-22 15:38:38.688909741 +0100
@@ -163,3 +163,11 @@
highlighted = False
return res, highlighted
+
+def fix_braces(text):
+ # Remove braces not closed, if the text was truncated
+ if text.endswith(' {...'):
+ subtext = text[:-5]
+ if not '{}' in subtext:
+ return '{}...'.format(subtext)
+ return text