telegram: Add support for showing replies and forwards of messages
patch 0f6013389cd9efdee9025e5483d1f2d4cde460a8
Author: E. Bosch <presidev@AT@gmail.com>
Date: Tue Mar 28 23:32:36 CEST 2023
* telegram: Add support for showing replies and forwards of messages
hunk ./irc.py 454
+ if self.tg.refwd_me:
+ msg = msg.format(user.irc_nick)
hunk ./telegram.py 55
+ self.refwd_me = False
hunk ./telegram.py 315
- message = '[{}] {}'.format(mid, text)
+ if event.message.is_reply:
+ refwd_text = await self.handle_telegram_reply(event)
+ elif event.message.forward:
+ refwd_text = await self.handle_telegram_forward(event)
+ else:
+ refwd_text = ''
+
+ message = '[{}] {}{}'.format(mid, refwd_text, text)
hunk ./telegram.py 329
+ self.refwd_me = False
+
hunk ./telegram.py 376
+ async def handle_telegram_reply(self, event):
+ trunc = ''
+ replied = await event.message.get_reply_message()
+ message = replied.message
+ if not message:
+ message = '[{}]'.format(self.mid.num_to_id(replied.id - self.mid.mesg_base))
+ elif len(message) > 30:
+ message = message[:30]
+ trunc = '...'
+ replied_user = self.get_irc_user_from_telegram(replied.sender_id)
+ if replied_user is None:
+ replied_nick = '{}'
+ self.refwd_me = True
+ else:
+ replied_nick = replied_user.irc_nick
+
+ return '|Re {}: {}{}| '.format(replied_nick, message, trunc)
+
+ async def handle_telegram_forward(self, event): [_$_]
+ forwarded_user = self.get_irc_user_from_telegram(event.forward.from_id.user_id)
+ if forwarded_user is None:
+ forwarded_nick = '{}'
+ self.refwd_me = True
+ else:
+ forwarded_nick = forwarded_user.irc_nick
+ forwarded_peer = event.forward.saved_from_peer
+ if isinstance(forwarded_peer, tgty.PeerChannel):
+ dest = ' ' + await self.get_irc_channel_from_telegram_id(forwarded_peer.channel_id)
+ elif isinstance(forwarded_peer, tgty.PeerChat):
+ dest = ' ' + await self.get_irc_channel_from_telegram_id(forwarded_peer.chat_id)
+ else:
+ # if it's from me I want to know who was the destination of a message (user)
+ if self.refwd_me:
+ dest = ' ' + self.get_irc_user_from_telegram(forwarded_peer.user_id).irc_nick
+ else:
+ dest = ''
+
+ return '|Fwd {}{}| '.format(forwarded_nick, dest)
+