patch 89bc0957a4fb31bf8066e338bc4548cd2d52c821 Author: E. Bosch Date: Sat Nov 2 20:20:45 CET 2024 * telegram, irc: Set topic in IRC with Telegram channel/chat description patch 86ef89f9f9220ecde8477db2aa673f94f32656ab Author: E. Bosch Date: Sat Oct 26 20:43:28 CEST 2024 * telegram: Fix op and founder detection in channels patch 6d99fce9643fbdda1594f99331f4a4642ecc7f0f Author: E. Bosch Date: Sat Oct 26 20:35:11 CEST 2024 * telegram: Fix handler for next reactions when the event is empty patch efaf8df4b3fa314997615e2fc07a3decb3a7cfba Author: E. Bosch Date: Sat Oct 26 13:01:02 CEST 2024 * exclam: Reorder handler list so commands are listed ordered in help patch 0cfc7e59b24fb1a1b279fc593f8d04d0648e3880 Author: E. Bosch Date: Mon Oct 21 00:54:16 CEST 2024 * README update patch abf1d31ddcf3cddd55844900065a3c3dd6bf9c67 Author: E. Bosch Date: Sun Oct 20 02:32:44 CEST 2024 * exclam: Add "-" parameter to "!react" to remove a reaction patch 5c1687a16a1e49af7b5f70e9449c447bbf7c9df9 Author: E. Bosch Date: Sat Oct 19 22:56:31 CEST 2024 * telegram: On emoticon->emoji conversions for reactions, when several emoticons can be mapped to an emoji, keep first elements that are more probable allowed for reactions patch 7db9d9a07af099b00a32a6ee0197c400a52240e5 Author: E. Bosch Date: Sun Oct 13 23:00:24 CEST 2024 * telegram: Limit text length for reactions to twice as replies diff -rN -u old-irgramd/README.md new-irgramd/README.md --- old-irgramd/README.md 2024-11-22 15:53:18.539503257 +0100 +++ new-irgramd/README.md 2024-11-22 15:53:18.547503244 +0100 @@ -50,7 +50,7 @@ - Forwards (receive, send) - Deletions (receive, do) - Editions (receive, do) -- Reactions (receive, send) +- Reactions (receive, send, remove) - Polls (receive, show) - Actions [pin message, channel photo] (receive) - Dialogs management diff -rN -u old-irgramd/emoji2emoticon.py new-irgramd/emoji2emoticon.py --- old-irgramd/emoji2emoticon.py 2024-11-22 15:53:18.543503251 +0100 +++ new-irgramd/emoji2emoticon.py 2024-11-22 15:53:18.547503244 +0100 @@ -89,8 +89,8 @@ '\U0001f970': '":)e>"', } -emo_inv = {} -for k in emo: +emo_inv = { '-': None } +for k in reversed(emo): emo_inv[emo[k][1:-1]] = k def replace_mult(line, emo): diff -rN -u old-irgramd/exclam.py new-irgramd/exclam.py --- old-irgramd/exclam.py 2024-11-22 15:53:18.543503251 +0100 +++ new-irgramd/exclam.py 2024-11-22 15:53:18.547503244 +0100 @@ -18,13 +18,13 @@ def __init__(self, telegram): self.commands = \ { # Command Handler Arguments Min Max Maxsplit - '!re': (self.handle_command_re, 2, 2, 2), - '!ed': (self.handle_command_ed, 2, 2, 2), '!del': (self.handle_command_del, 1, 1, -1), + '!ed': (self.handle_command_ed, 2, 2, 2), '!fwd': (self.handle_command_fwd, 2, 2, -1), - '!upl': (self.handle_command_upl, 1, 2, 2), - '!reupl': (self.handle_command_reupl, 2, 3, 3), + '!re': (self.handle_command_re, 2, 2, 2), '!react': (self.handle_command_react, 2, 2, -1), + '!reupl': (self.handle_command_reupl, 2, 3, 3), + '!upl': (self.handle_command_upl, 1, 2, 2), } self.tg = telegram self.irc = telegram.irc @@ -199,7 +199,7 @@ if chk_msg is not None: if act in emo_inv: utf8_emo = emo_inv[act] - reaction = [ tgty.ReactionEmoji(emoticon=utf8_emo) ] + reaction = [ tgty.ReactionEmoji(emoticon=utf8_emo) ] if utf8_emo else None try: update = await self.tg.telegram_client(SendReactionRequest(self.tmp_telegram_id, id, reaction=reaction)) except ReactionInvalidError: @@ -216,8 +216,9 @@ if help == HELP.desc: # rest of HELP.desc reply += \ ( - ' !react ', + ' !react |-', 'React with to a message with ,', 'irgramd will translate emoticon to closest emoji.', + 'Use - to remove a previous reaction.', ) return reply diff -rN -u old-irgramd/include.py new-irgramd/include.py --- old-irgramd/include.py 2024-11-22 15:53:18.543503251 +0100 +++ new-irgramd/include.py 2024-11-22 15:53:18.547503244 +0100 @@ -11,3 +11,4 @@ VERSION = '0.2' NICK_MAX_LENGTH = 20 CHAN_MAX_LENGTH = 50 +MAX_LINE = 400 diff -rN -u old-irgramd/irc.py new-irgramd/irc.py --- old-irgramd/irc.py 2024-11-22 15:53:18.543503251 +0100 +++ new-irgramd/irc.py 2024-11-22 15:53:18.551503238 +0100 @@ -18,7 +18,7 @@ # Local modules -from include import VERSION, CHAN_MAX_LENGTH, NICK_MAX_LENGTH +from include import VERSION, CHAN_MAX_LENGTH, NICK_MAX_LENGTH, MAX_LINE from irc_replies import irc_codes from utils import chunks, set_replace, split_lines from service import service @@ -259,7 +259,7 @@ real_chan = self.get_realcaps_name(chan) users_count = len(self.irc_channels[chan]) topic = await self.tg.get_channel_topic(chan, [None]) - await self.reply_code(user, 'RPL_LIST', (real_chan, users_count, topic)) + await self.reply_code(user, 'RPL_LIST', (real_chan, users_count, topic[:MAX_LINE])) await self.reply_code(user, 'RPL_LISTEND') async def handle_irc_names(self, user, channels): @@ -612,7 +612,7 @@ founder = list(self.irc_channels_founder[chan])[0] else: founder = self.service_user.irc_nick - await self.reply_code(user, 'RPL_TOPIC', (channel, topic)) + await self.reply_code(user, 'RPL_TOPIC', (channel, topic[:MAX_LINE])) await self.reply_code(user, 'RPL_TOPICWHOTIME', (channel, founder, timestamp)) async def irc_namelist(self, user, channel): diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py --- old-irgramd/telegram.py 2024-11-22 15:53:18.543503251 +0100 +++ new-irgramd/telegram.py 2024-11-22 15:53:18.551503238 +0100 @@ -15,7 +15,8 @@ import collections import telethon from telethon import types as tgty, utils as tgutils -from telethon.tl.functions.messages import GetMessagesReactionsRequest +from telethon.tl.functions.messages import GetMessagesReactionsRequest, GetFullChatRequest +from telethon.tl.functions.channels import GetFullChannelRequest # Local modules @@ -181,10 +182,12 @@ if not user.is_self: self.irc.irc_channels[chan].add(user_nick) # Add admin users as ops in irc - if isinstance(user.participant, tgty.ChatParticipantAdmin): + if isinstance(user.participant, tgty.ChatParticipantAdmin) or \ + isinstance(user.participant, tgty.ChannelParticipantAdmin): self.irc.irc_channels_ops[chan].add(user_nick) # Add creator users as founders in irc - elif isinstance(user.participant, tgty.ChatParticipantCreator): + elif isinstance(user.participant, tgty.ChatParticipantCreator) or \ + isinstance(user.participant, tgty.ChannelParticipantCreator): self.irc.irc_channels_founder[chan].add(user_nick) def get_telegram_nick(self, user): @@ -307,8 +310,16 @@ else: entity = await self.telegram_client.get_entity(tid) entity_cache[0] = entity + if isinstance(entity, tgty.Channel): + full = await self.telegram_client(GetFullChannelRequest(channel=entity)) + elif isinstance(entity, tgty.Chat): + full = await self.telegram_client(GetFullChatRequest(chat_id=tid)) + else: + return '' entity_type = self.get_entity_type(entity, format='long') - return 'Telegram ' + entity_type + ' ' + str(tid) + ': ' + entity.title + topic = full.full_chat.about + sep = ': ' if topic else '' + return entity_type + sep + topic async def get_channel_creation(self, channel, entity_cache): tid = self.get_tid(channel) @@ -505,8 +516,9 @@ self.sorted_len_usernames.sort(key=lambda k: len(k), reverse=True) def format_reaction(self, msg, message_rendered, edition_case, reaction): - if len(message_rendered) > self.quote_len and not msg.is_reply: - text_old = '{}...'.format(message_rendered[:self.quote_len]) + react_quote_len = self.quote_len * 2 + if len(message_rendered) > react_quote_len: + text_old = '{}...'.format(message_rendered[:react_quote_len]) text_old = fix_braces(text_old) else: text_old = message_rendered @@ -573,9 +585,9 @@ self.logger.debug('Handling Telegram Next Reaction (2nd, 3rd, ...): %s', pretty(event)) reactions = event.reactions.recent_reactions - react = max(reactions, key=lambda y: y.date) - - if self.last_reaction != react.date: + react = max(reactions, key=lambda y: y.date) if reactions else None + + if react and self.last_reaction != react.date: self.last_reaction = react.date id = event.msg_id msg = await self.telegram_client.get_messages(entity=event.peer, ids=id) diff -rN -u old-irgramd/utils.py new-irgramd/utils.py --- old-irgramd/utils.py 2024-11-22 15:53:18.547503244 +0100 +++ new-irgramd/utils.py 2024-11-22 15:53:18.551503238 +0100 @@ -20,6 +20,8 @@ FILENAME_INVALID_CHARS = re.compile('[/{}<>()"\'\\|&#%?]') SIMPLE_URL = re.compile('http(|s)://[^ ]+') +from include import MAX_LINE + # Utilities class command: @@ -61,9 +63,8 @@ return (x + mark if n != length else x for n, x in enumerate(items, start=1)) def split_lines(message): - MAX = 400 messages_limited = [] - wr = textwrap.TextWrapper(width=MAX) + wr = textwrap.TextWrapper(width=MAX_LINE) # Split when Telegram original message has breaks messages = message.splitlines()