telegram: Add support for showing deleted messages
patch cee19ae7322cdc3235ad93d1666e9d44669ed16d
Author: E. Bosch <presidev@AT@gmail.com>
Date: Mon Apr 10 23:31:19 CEST 2023
* telegram: Add support for showing deleted messages
hunk ./telegram.py 89
+ (self.handle_telegram_deleted , telethon.events.MessageDeleted),
hunk ./telegram.py 307
+ async def handle_telegram_deleted(self, event):
+ self.logger.debug('Handling Telegram Message Deleted: %s', event)
+
+ for deleted_id in event.original_update.messages:
+ if deleted_id in self.cache:
+ recovered_text = self.cache[deleted_id]['rendered_text']
+ text = '|Deleted| {}'.format(recovered_text)
+ user = self.cache[deleted_id]['user']
+ chan = self.cache[deleted_id]['channel']
+ await self.relay_telegram_message(event=None, user=user, message=text, channel=chan)
+ else:
+ mid = self.mid.num_to_id_offset(deleted_id)
+ text = 'Message id {} deleted not in cache'.format(mid)
+ await self.relay_telegram_private_message(self.irc.service_user, text)
+
hunk ./telegram.py 333
- if self.mid.mesg_base is None:
- self.mid.mesg_base = event.message.id
-
hunk ./telegram.py 334
- mid = self.mid.num_to_id(event.message.id - self.mid.mesg_base)
+ mid = self.mid.num_to_id_offset(event.message.id)
hunk ./telegram.py 421
- message = '[{}]'.format(self.mid.num_to_id(replied.id - self.mid.mesg_base))
+ message = '[{}]'.format(self.mid.num_to_id_offset(replied.id))
hunk ./telegram.py 621
+ def num_to_id_offset(self, num):
+ if self.mesg_base is None:
+ self.mesg_base = num
+ return self.num_to_id(num - self.mesg_base)
+