telegram: Add support for pin message action
patch 9c00648eaf7c048826dc4fe6bdbd509eabe57f47
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Nov 26 20:07:44 CET 2023
* telegram: Add support for pin message action
irc: Add support for sending CTCP actions (me) to map actions from Telegram
hunk ./irc.py 473
+ async def send_action(self, source, target, message):
+ action_message = '\x01ACTION {}\x01'.format(message)
+ await self.send_msg(source, target, action_message)
+
hunk ./telegram.py 556
- text_send = self.set_history_timestamp(text, history, msg.date)
+ text_send = self.set_history_timestamp(text, history, msg.date, msg.action)
hunk ./telegram.py 571
- if message.is_reply:
+ if message.action:
+ final_text = await self.handle_telegram_action(message)
+ return final_text
+ elif message.is_reply:
hunk ./telegram.py 585
- def set_history_timestamp(self, text, history, date):
+ def set_history_timestamp(self, text, history, date, action):
hunk ./telegram.py 588
- res = '{} {}'.format(timestamp, text)
+ if action:
+ res = '{} {}'.format(text, timestamp)
+ else:
+ res = '{} {}'.format(timestamp, text)
hunk ./telegram.py 598
+ action = (message and message.action)
hunk ./telegram.py 600
- await self.relay_telegram_private_message(user, text)
+ await self.relay_telegram_private_message(user, text, action)
hunk ./telegram.py 603
- chan = await self.relay_telegram_channel_message(message, user, text, channel)
+ chan = await self.relay_telegram_channel_message(message, user, text, channel, action)
hunk ./telegram.py 606
- async def relay_telegram_private_message(self, user, message):
+ async def relay_telegram_private_message(self, user, message, action=None):
hunk ./telegram.py 609
- await self.irc.send_msg(user, None, message)
-
- async def relay_telegram_channel_message(self, message, user, text, channel=None):
+ if action:
+ await self.irc.send_action(user, None, message)
+ else:
+ await self.irc.send_msg(user, None, message)
+
+ async def relay_telegram_channel_message(self, message, user, text, channel, action):
hunk ./telegram.py 622
- await self.irc.send_msg(user, chan, text)
+
+ if action:
+ await self.irc.send_action(user, chan, text)
+ else:
+ await self.irc.send_msg(user, chan, text)
+
hunk ./telegram.py 663
+ async def handle_telegram_action(self, message):
+ if isinstance(message.action, tgty.MessageActionPinMessage):
+ replied = await message.get_reply_message()
+ cid = self.mid.num_to_id_offset(replied.peer_id, replied.id)
+ action_text = 'has pinned message [{}]'.format(cid)
+ else:
+ action_text = ''
+ return action_text
+