Fix typo in a constant --> to head
patch 89bc0957a4fb31bf8066e338bc4548cd2d52c821
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Nov 2 20:20:45 CET 2024
* telegram, irc: Set topic in IRC with Telegram channel/chat description
hunk ./include.py 14
+MAX_LINE = 400
hunk ./irc.py 21
-from include import VERSION, CHAN_MAX_LENGTH, NICK_MAX_LENGTH
+from include import VERSION, CHAN_MAX_LENGTH, NICK_MAX_LENGTH, MAX_LINE
hunk ./irc.py 262
- 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]))
hunk ./irc.py 615
- await self.reply_code(user, 'RPL_TOPIC', (channel, topic))
+ await self.reply_code(user, 'RPL_TOPIC', (channel, topic[:MAX_LINE]))
hunk ./telegram.py 18
-from telethon.tl.functions.messages import GetMessagesReactionsRequest
+from telethon.tl.functions.messages import GetMessagesReactionsRequest, GetFullChatRequest
+from telethon.tl.functions.channels import GetFullChannelRequest
hunk ./telegram.py 313
+ 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 ''
hunk ./telegram.py 320
- return 'Telegram ' + entity_type + ' ' + str(tid) + ': ' + entity.title
+ topic = full.full_chat.about
+ sep = ': ' if topic else ''
+ return entity_type + sep + topic
hunk ./utils.py 23
+from include import MAX_LINE
+
hunk ./utils.py 66
- MAX = 400
hunk ./utils.py 67
- wr = textwrap.TextWrapper(width=MAX)
+ wr = textwrap.TextWrapper(width=MAX_LINE)
patch 86ef89f9f9220ecde8477db2aa673f94f32656ab
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Oct 26 20:43:28 CEST 2024
* telegram: Fix op and founder detection in channels
hunk ./telegram.py 184
- if isinstance(user.participant, tgty.ChatParticipantAdmin):
+ if isinstance(user.participant, tgty.ChatParticipantAdmin) or \
+ isinstance(user.participant, tgty.ChannelParticipantAdmin):
hunk ./telegram.py 188
- elif isinstance(user.participant, tgty.ChatParticipantCreator):
+ elif isinstance(user.participant, tgty.ChatParticipantCreator) or \
+ isinstance(user.participant, tgty.ChannelParticipantCreator):
patch 6d99fce9643fbdda1594f99331f4a4642ecc7f0f
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Oct 26 20:35:11 CEST 2024
* telegram: Fix handler for next reactions when the event is empty
hunk ./telegram.py 577
- 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:
patch efaf8df4b3fa314997615e2fc07a3decb3a7cfba
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Oct 26 13:01:02 CEST 2024
* exclam: Reorder handler list so commands are listed ordered in help
hunk ./exclam.py 21
- '!re': (self.handle_command_re, 2, 2, 2),
- '!ed': (self.handle_command_ed, 2, 2, 2),
hunk ./exclam.py 22
+ '!ed': (self.handle_command_ed, 2, 2, 2),
hunk ./exclam.py 24
- '!upl': (self.handle_command_upl, 1, 2, 2),
- '!reupl': (self.handle_command_reupl, 2, 3, 3),
+ '!re': (self.handle_command_re, 2, 2, 2),
hunk ./exclam.py 26
+ '!reupl': (self.handle_command_reupl, 2, 3, 3),
+ '!upl': (self.handle_command_upl, 1, 2, 2),
patch 0cfc7e59b24fb1a1b279fc593f8d04d0648e3880
Author: E. Bosch <presidev@AT@gmail.com>
Date: Mon Oct 21 00:54:16 CEST 2024
* README update
hunk ./README.md 53
-- Reactions (receive, send)
+- Reactions (receive, send, remove)
patch abf1d31ddcf3cddd55844900065a3c3dd6bf9c67
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Oct 20 02:32:44 CEST 2024
* exclam: Add "-" parameter to "!react" to remove a reaction
hunk ./emoji2emoticon.py 92
-emo_inv = {}
+emo_inv = { '-': None }
hunk ./exclam.py 202
- reaction = [ tgty.ReactionEmoji(emoticon=utf8_emo) ]
+ reaction = [ tgty.ReactionEmoji(emoticon=utf8_emo) ] if utf8_emo else None
hunk ./exclam.py 219
- ' !react <compact_id> <emoticon reaction>',
+ ' !react <compact_id> <emoticon reaction>|-',
hunk ./exclam.py 222
+ 'Use - to remove a previous reaction.',
patch 5c1687a16a1e49af7b5f70e9449c447bbf7c9df9
Author: E. Bosch <presidev@AT@gmail.com>
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
hunk ./emoji2emoticon.py 93
-for k in emo:
+for k in reversed(emo):
patch 7db9d9a07af099b00a32a6ee0197c400a52240e5
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Oct 13 23:00:24 CEST 2024
* telegram: Limit text length for reactions to twice as replies
hunk ./telegram.py 508
- 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])
patch 42fe2f72d41ed36616e6a19b9388eec356679e38
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Oct 12 23:17:45 CEST 2024
* README update
hunk ./README.md 53
-- Reactions (receive)
+- Reactions (receive, send)
patch 873004141f83b60da113e8967a2148d9d33008be
Author: E. Bosch <presidev@AT@gmail.com>
Date: Thu Oct 10 23:11:40 CEST 2024
* exclam: Add reaction (!react) command to send emoticon->emoji as Telegram reaction
hunk ./emoji2emoticon.py 89
- '\U0001f970': '":)e>"'
+ '\U0001f970': '":)e>"',
hunk ./emoji2emoticon.py 92
+emo_inv = {}
+for k in emo:
+ emo_inv[emo[k][1:-1]] = k
+
hunk ./exclam.py 10
-from telethon.errors.rpcerrorlist import MessageNotModifiedError, MessageAuthorRequiredError
+from telethon.tl.functions.messages import SendReactionRequest
+from telethon import types as tgty
+from telethon.errors.rpcerrorlist import MessageNotModifiedError, MessageAuthorRequiredError, ReactionInvalidError
hunk ./exclam.py 15
+from emoji2emoticon import emo_inv
hunk ./exclam.py 27
+ '!react': (self.handle_command_react, 2, 2, -1),
hunk ./exclam.py 193
+ )
+ return reply
+
+ async def handle_command_react(self, cid=None, act=None, help=None):
+ if not help:
+ id, chk_msg = await self.check_msg(cid)
+ if chk_msg is not None:
+ if act in emo_inv:
+ utf8_emo = emo_inv[act]
+ reaction = [ tgty.ReactionEmoji(emoticon=utf8_emo) ]
+ try:
+ update = await self.tg.telegram_client(SendReactionRequest(self.tmp_telegram_id, id, reaction=reaction))
+ except ReactionInvalidError:
+ reply = ('!react: Reaction not allowed',)
+ else:
+ self.tmp_tg_msg = update.updates[0].message
+ reply = True
+ else:
+ reply = ('!react: Unknown reaction',)
+ else:
+ reply = ('!react: Unknown message to react',)
+ else: # HELP.brief or HELP.desc (first line)
+ reply = (' !react React to a message',)
+ if help == HELP.desc: # rest of HELP.desc
+ reply += \
+ (
+ ' !react <compact_id> <emoticon reaction>',
+ 'React with <emoticon reaction> to a message with <compact_id>,',
+ 'irgramd will translate emoticon to closest emoji.',
patch 69a63d9f5f49ece35c5d552ba8b3081c8277490d
Author: E. Bosch <presidev@AT@gmail.com>
Date: Mon Oct 7 00:07:54 CEST 2024
* telegram, service: Move initial help to service module
add a line for "equivalent command"
hunk ./irc.py 535
- for line in (
- 'Welcome to irgramd service',
- 'use /msg {} help'.format(self.service_user.irc_nick),
- 'to get help',
- ):
+ for line in self.service.initial_help():
hunk ./service.py 28
+ def initial_help(self):
+ return (
+ 'Welcome to irgramd service',
+ 'use /msg {} help'.format(self.irc.service_user.irc_nick),
+ 'or equivalent in your IRC client',
+ 'to get help',
+ )
+
patch c1ffe716a42ea01ca345d7a756b685d7174f99c5
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Oct 6 23:59:23 CEST 2024
* telegram: Fix regression in delete reaction event
hunk ./telegram.py 520
- user = self.get_irc_user_from_telegram(event.sender_id)
+ user = self.get_irc_user_from_telegram(msg.sender_id)
hunk ./telegram.py 558
- if self.last_reaction == reaction.date:
- return
- self.last_reaction = reaction.date
+ if reaction:
+ if self.last_reaction == reaction.date:
+ return
+ self.last_reaction = reaction.date
patch beacde93a685dd954f9823dc0a6fea4594b2c1e4
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Sep 28 02:53:06 CEST 2024
* telegram: Avoid duplicated reactions events in some cases
hunk ./telegram.py 74
+ self.last_reaction = None
hunk ./telegram.py 558
+ if self.last_reaction == reaction.date:
+ return
+ self.last_reaction = reaction.date
hunk ./telegram.py 576
- id = event.msg_id
- msg = await self.telegram_client.get_messages(entity=event.peer, ids=id)
- mid = self.mid.num_to_id_offset(msg.peer_id, id)
- message = self.filters(msg.message)
- message_rendered = await self.render_text(msg, mid, upd_to_webpend=None)
-
- text_old, edition_react, user = self.format_reaction(msg, message_rendered, edition_case='react-add', reaction=react)
-
- text = '|React {}| {}'.format(text_old, edition_react)
-
- chan = await self.relay_telegram_message(msg, user, text)
-
- self.to_cache(id, mid, message, message_rendered, user, chan, msg.media)
- self.to_volatile_cache(self.prev_id, id, text, user, chan, current_date())
+ [_$_]
+ if 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)
+ mid = self.mid.num_to_id_offset(msg.peer_id, id)
+ message = self.filters(msg.message)
+ message_rendered = await self.render_text(msg, mid, upd_to_webpend=None)
+
+ text_old, edition_react, user = self.format_reaction(msg, message_rendered, edition_case='react-add', reaction=react)
+
+ text = '|React {}| {}'.format(text_old, edition_react)
+
+ chan = await self.relay_telegram_message(msg, user, text)
+
+ self.to_cache(id, mid, message, message_rendered, user, chan, msg.media)
+ self.to_volatile_cache(self.prev_id, id, text, user, chan, current_date())
patch b2f8fe9251a26c43e16ba1aadff8d71e64a5a7e9
Author: E. Bosch <presidev@AT@gmail.com>
Date: Fri Sep 27 11:05:53 CEST 2024
* telegram: Add handler for next reactions (2nd, 3rd, etc.) that don't come from
the same events as 1st (why?!)
hunk ./telegram.py 506
+ 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])
+ text_old = fix_braces(text_old)
+ else:
+ text_old = message_rendered
+
+ if edition_case == 'react-add':
+ user = self.get_irc_user_from_telegram(reaction.peer_id.user_id)
+ emoji = reaction.reaction.emoticon
+ react_action = '+'
+ react_icon = e.emo[emoji] if emoji in e.emo else emoji
+ elif edition_case == 'react-del':
+ user = self.get_irc_user_from_telegram(event.sender_id)
+ react_action = '-'
+ react_icon = ''
+ return text_old, '{}{}'.format(react_action, react_icon), user
+
hunk ./telegram.py 558
- if len(message_rendered) > self.quote_len and not event.message.is_reply:
- text_old = '{}...'.format(message_rendered[:self.quote_len])
- text_old = fix_braces(text_old)
- else:
- text_old = message_rendered
-
- if edition_case == 'react-add':
- user = self.get_irc_user_from_telegram(reaction.peer_id.user_id)
- emoji = reaction.reaction.emoticon
- react_action = '+'
- react_icon = e.emo[emoji] if emoji in e.emo else emoji
- elif edition_case == 'react-del':
- user = self.get_irc_user_from_telegram(event.sender_id)
- react_action = '-'
- react_icon = ''
- edition_react = '{}{}'.format(react_action, react_icon)
+ text_old, edition_react, user = self.format_reaction(event.message, message_rendered, edition_case, reaction)
hunk ./telegram.py 567
+ async def handle_next_reaction(self, event):
+ 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)
+ id = event.msg_id
+ msg = await self.telegram_client.get_messages(entity=event.peer, ids=id)
+ mid = self.mid.num_to_id_offset(msg.peer_id, id)
+ message = self.filters(msg.message)
+ message_rendered = await self.render_text(msg, mid, upd_to_webpend=None)
+
+ text_old, edition_react, user = self.format_reaction(msg, message_rendered, edition_case='react-add', reaction=react)
+
+ text = '|React {}| {}'.format(text_old, edition_react)
+
+ chan = await self.relay_telegram_message(msg, user, text)
+
+ self.to_cache(id, mid, message, message_rendered, user, chan, msg.media)
+ self.to_volatile_cache(self.prev_id, id, text, user, chan, current_date())
+
hunk ./telegram.py 610
+ elif isinstance(update, tgty.UpdateMessageReactions):
+ await self.handle_next_reaction(update)
+
patch 8770a66d55d4d1c34e009fe5d0078f77c3be4d34
Author: E. Bosch <presidev@AT@gmail.com>
Date: Wed Sep 25 01:36:06 CEST 2024
* telegram: Fix in reaction handler
hunk ./telegram.py 404
- elif react := next((x for x in reactions if x.date == msg.edit_date), None):
+ elif react := max(reactions, key=lambda y: y.date):
patch 7e550077a65e4737ca30a81e0decbcb4db0485a4
Author: E. Bosch <presidev@AT@gmail.com>
Date: Fri Sep 20 23:50:13 CEST 2024
* telegram: Don't truncate text for reactions of replies
hunk ./telegram.py 540
- if len(message_rendered) > self.quote_len:
+ if len(message_rendered) > self.quote_len and not event.message.is_reply:
patch f9ff84bf789b6bd5109c5953590ca41c438fe123
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Sep 15 23:50:10 CEST 2024
* telegram: Minor improvement in debug of relay methods
hunk ./telegram.py 662
- self.logger.debug('Handling Telegram Private Message: %s, %s', user, message)
+ self.logger.debug('Relaying Telegram Private Message: %s, %s', user, message)
hunk ./telegram.py 670
- self.logger.debug('Handling Telegram Channel Message: %s', pretty(message) or text)
-
hunk ./telegram.py 676
+ self.logger.debug('Relaying Telegram Channel Message: %s, %s', chan, text)
+
patch 1d527812923bdf50653bb371185bec70c2abad40
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Sep 15 01:23:24 CEST 2024
* telegram: Improve a bit reactions handler
hunk ./telegram.py 392
- return react.updates[0].reactions.recent_reactions
+ updates = react.updates
+ r = next((x for x in updates if type(x) is tgty.UpdateMessageReactions), None)
+ return r.reactions.recent_reactions if r else None
patch b43b2bc6a4e9dcf0eaddb66ea3fd5abf7c95082b
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Sep 7 23:20:27 CEST 2024
* Fix typo in a constant
hunk ./include.py 13
-CHAN_MAX_LENGHT = 50
+CHAN_MAX_LENGTH = 50
hunk ./irc.py 21
-from include import VERSION, CHAN_MAX_LENGHT, NICK_MAX_LENGTH
+from include import VERSION, CHAN_MAX_LENGTH, NICK_MAX_LENGTH
hunk ./irc.py 532
- await self.reply_code(user, 'RPL_ISUPPORT', (CHAN_MAX_LENGHT, NICK_MAX_LENGTH))
+ await self.reply_code(user, 'RPL_ISUPPORT', (CHAN_MAX_LENGTH, NICK_MAX_LENGTH))
hunk ./telegram.py 22
-from include import CHAN_MAX_LENGHT, NICK_MAX_LENGTH
+from include import CHAN_MAX_LENGTH, NICK_MAX_LENGTH