telegram: Change interface for received messages, use message instead event
patch 7fbbd73b77d52696b7d3ebdee564c07cea280f8a
Author: E. Bosch <presidev@AT@gmail.com>
Date: Tue May 2 23:37:17 CEST 2023
* telegram: Change interface for received messages, use message instead event
object if possible, this will be necessary to inject messages from future
history functionality
hunk ./telegram.py 378
- message_rendered = await self.render_text(event, mid, upd_to_webpend=None)
+ message_rendered = await self.render_text(event.message, mid, upd_to_webpend=None)
hunk ./telegram.py 447
- event = self.webpending.pop(update.webpage.id, None)
- if event:
- await self.handle_telegram_message(event, update.webpage)
-
- async def handle_telegram_message(self, event, upd_to_webpend=None):
- self.logger.debug('Handling Telegram Message: %s', event)
-
- user = self.get_irc_user_from_telegram(event.sender_id)
- mid = self.mid.num_to_id_offset(event.message.id)
-
- message = await self.render_text(event, mid, upd_to_webpend)
-
- chan = await self.relay_telegram_message(event, user, message)
-
- self.to_cache(event.message.id, mid, event.message.message, message, user, chan, event.message.media)
+ message = self.webpending.pop(update.webpage.id, None)
+ if message:
+ await self.handle_telegram_message(event=None, message=message, upd_to_webpend=update.webpage)
+
+ async def handle_telegram_message(self, event, message=None, upd_to_webpend=None):
+ self.logger.debug('Handling Telegram Message: %s', event or message)
+
+ if event:
+ msg = event.message
+ else:
+ msg = message
+
+ user = self.get_irc_user_from_telegram(msg.sender_id)
+ mid = self.mid.num_to_id_offset(msg.id)
+ text = await self.render_text(msg, mid, upd_to_webpend)
+ chan = await self.relay_telegram_message(msg, user, text)
+
+ self.to_cache(msg.id, mid, msg.message, text, user, chan, msg.media)
hunk ./telegram.py 468
- async def render_text(self, event, mid, upd_to_webpend):
+ async def render_text(self, message, mid, upd_to_webpend):
hunk ./telegram.py 470
- text = await self.handle_webpage(upd_to_webpend, event.message)
- elif event.message.media:
- text = await self.handle_telegram_media(event)
+ text = await self.handle_webpage(upd_to_webpend, message)
+ elif message.media:
+ text = await self.handle_telegram_media(message)
hunk ./telegram.py 474
- text = event.message.message
-
- 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)
+ text = message.message
+
+ if message.is_reply:
+ refwd_text = await self.handle_telegram_reply(message)
+ elif message.forward:
+ refwd_text = await self.handle_telegram_forward(message)
hunk ./telegram.py 483
- message = '[{}] {}{}'.format(mid, refwd_text, text)
- message = e.replace_mult(message, e.emo)
- return message
-
- async def relay_telegram_message(self, event, user, message, channel=None):
- private = (event and event.message.is_private) or (not event and not channel)
+ final_text = '[{}] {}{}'.format(mid, refwd_text, text)
+ final_text = e.replace_mult(final_text, e.emo)
+ return final_text
+
+ async def relay_telegram_message(self, message, user, text, channel=None):
+ private = (message and message.is_private) or (not message and not channel)
hunk ./telegram.py 490
- await self.relay_telegram_private_message(user, message)
+ await self.relay_telegram_private_message(user, text)
hunk ./telegram.py 493
- chan = await self.relay_telegram_channel_message(event, user, message, channel)
+ chan = await self.relay_telegram_channel_message(message, user, text, channel)
hunk ./telegram.py 501
- async def relay_telegram_channel_message(self, event, user, message, channel=None):
- self.logger.debug('Handling Telegram Channel Message: %s', event)
-
- if event:
- entity = await event.message.get_chat()
- chan = await self.get_irc_channel_from_telegram_id(event.message.chat_id, entity)
+ async def relay_telegram_channel_message(self, message, user, text, channel=None):
+ self.logger.debug('Handling Telegram Channel Message: %s', message or text)
+
+ if message:
+ entity = await message.get_chat()
+ chan = await self.get_irc_channel_from_telegram_id(message.chat_id, entity)
hunk ./telegram.py 509
- await self.irc.send_msg(user, chan, message)
+ await self.irc.send_msg(user, chan, text)
hunk ./telegram.py 545
- async def handle_telegram_reply(self, event):
+ async def handle_telegram_reply(self, message):
hunk ./telegram.py 547
- replied = await event.message.get_reply_message()
- message = replied.message
- if not message:
- message = '[{}]'.format(self.mid.num_to_id_offset(replied.id))
- elif len(message) > self.quote_len:
- message = message[:self.quote_len]
+ replied = await message.get_reply_message()
+ replied_msg = replied.message
+ if not replied_msg:
+ replied_msg = '[{}]'.format(self.mid.num_to_id_offset(replied.id))
+ elif len(replied_msg) > self.quote_len:
+ replied_msg = replied_msg[:self.quote_len]
hunk ./telegram.py 561
- return '|Re {}: {}{}| '.format(replied_nick, message, trunc)
-
- async def handle_telegram_forward(self, event):
- forwarded_nick = self.get_irc_nick_from_telegram_forward(event.message.fwd_from)
- forwarded_peer = event.forward.saved_from_peer
+ return '|Re {}: {}{}| '.format(replied_nick, replied_msg, trunc)
+
+ async def handle_telegram_forward(self, message):
+ forwarded_nick = self.get_irc_nick_from_telegram_forward(message.fwd_from)
+ forwarded_peer = message.fwd_from.saved_from_peer
hunk ./telegram.py 579
- async def handle_telegram_media(self, event):
- message = event.message
+ async def handle_telegram_media(self, message):
hunk ./telegram.py 593
- self.webpending[message.media.webpage.id] = event
+ self.webpending[message.media.webpage.id] = message