patch 09a140b7b20de47995143a94a5f2991ebfaeb0c5
Author: Peter Bui <pbui@bx612.space>
Date: Sun Jul 21 02:45:18 CEST 2019
* Add self.get_irc_channel_from_telegram_id
Refactor get_irc_* functions to take an entity object (fallback to
get_entity when none is provided).
hunk ./irtelegramd.py 26
+ ''' Return iterable consisting of a sequence of n-length chunks '''
hunk ./irtelegramd.py 273
- async def get_irc_nick_from_telegram_id(self, tid):
+ async def get_irc_nick_from_telegram_id(self, tid, entity=None):
hunk ./irtelegramd.py 275
- user = await self.telegram_client.get_entity(tid)
+ user = entity or await self.telegram_client.get_entity(tid)
hunk ./irtelegramd.py 282
+ async def get_irc_channel_from_telegram_id(self, tid, entity=None):
+ if tid not in self.tid_to_iid:
+ chat = entity or await self.telegram_client.get_entity(tid)
+ channel = self.get_telegram_channel(chat)
+ self.tid_to_iid[tid] = channel
+ self.iid_to_tid[channel] = tid
+
+ return self.tid_to_iid[tid]
+
hunk ./irtelegramd.py 296
- if user.id not in self.tid_to_iid:
- user_nick = self.get_telegram_nick(user)
- self.tid_to_iid[user.id] = user_nick
- self.iid_to_tid[user_nick] = user.id
- else:
- user_nick = self.tid_to_iid[user.id]
+ user_nick = await self.get_irc_nick_from_telegram_id(user.id, user)
hunk ./irtelegramd.py 326
- # Retrieve IRC channel name from Telegram ID
- if event.message.chat_id not in self.tid_to_iid:
- chat = await event.message.get_chat()
- channel = self.get_telegram_channel(chat)
- self.tid_to_iid[chat.id] = channel
- self.iid_to_tid[channel] = chat.id
- else:
- channel = self.tid_to_iid[event.message.chat_id]
-
hunk ./irtelegramd.py 327
+ entity = await event.message.get_chat()
+ channel = await self.get_irc_channel_from_telegram_id(event.message.chat_id, entity)
hunk ./irtelegramd.py 352
- self.logger.info('Handling Telegram Chat Action: %s', event)
+ self.logger.debug('Handling Telegram Chat Action: %s', event)
hunk ./irtelegramd.py 359
- irc_channel = self.tid_to_iid[tid]
+ irc_channel = await self.get_irc_channel_from_telegram_id(tid)