patch b2f185685325aa61a06179c5079a49f837f12a2f
Author: Peter Bui <pbui@bx612.space>
Date: Fri Jul 19 16:42:42 CEST 2019
* Update channel participants on Chat Action
get_entity does not work reliable (for new users), but get_participants
does, so simply call get_participants on ChatAction. This must happen
before we perform user resolution to ensure the information is in the
cache.
hunk ./irtelegramd.py 16
-import telethon.utils
-from telethon import TelegramClient, events
-from telethon.tl.types import User, UserStatusOnline
+import telethon
hunk ./irtelegramd.py 162
- async def join_irc_channel(self, nick, channel):
+ async def join_irc_channel(self, nick, channel, full_join=False):
hunk ./irtelegramd.py 170
+ if not full_join:
+ return
+
hunk ./irtelegramd.py 174
- tid = self.iid_to_tid[channel]
- nicks = []
- voices = []
- async for user in self.telegram_client.iter_participants(tid):
- 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]
-
- if isinstance(user.status, UserStatusOnline):
- voices.append(user_nick)
-
- nicks.append(user_nick)
- self.irc_channels[channel].add(user_nick)
+ tid = self.iid_to_tid[channel]
+ nicks, voices = await self.get_telegram_channel_participants(tid)
hunk ./irtelegramd.py 206
- if isinstance(user.status, UserStatusOnline):
+ if isinstance(user.status, telethon.types.UserStatusOnline):
hunk ./irtelegramd.py 229
- self.telegram_client = TelegramClient(telegram_session,
+ self.telegram_client = telethon.TelegramClient(telegram_session,
hunk ./irtelegramd.py 239
- (self.handle_telegram_message , events.NewMessage),
- (self.handle_telegram_chat_action, events.ChatAction),
+ (self.handle_telegram_message , telethon.events.NewMessage),
+ (self.handle_telegram_chat_action, telethon.events.ChatAction),
hunk ./irtelegramd.py 279
+ async def get_telegram_channel_participants(self, tid):
+ channel = self.tid_to_iid[tid]
+ nicks = []
+ voices = []
+ async for user in self.telegram_client.iter_participants(tid):
+ 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]
+
+ if isinstance(user.status, telethon.types.UserStatusOnline):
+ voices.append(user_nick)
+
+ nicks.append(user_nick)
+ self.irc_channels[channel].add(user_nick)
+
+ return nicks, voices
+
hunk ./irtelegramd.py 330
- await self.join_irc_channel(self.irc_nick, channel)
+ await self.join_irc_channel(self.irc_nick, channel, True)
hunk ./irtelegramd.py 334
- await self.join_irc_channel(nick, channel)
+ await self.join_irc_channel(nick, channel, False)
hunk ./irtelegramd.py 362
- irc_channel = self.tid_to_iid[event.action_message.to_id.channel_id]
+ tid = event.action_message.to_id.channel_id
hunk ./irtelegramd.py 364
- irc_channel = self.tid_to_iid[event.action_message.to_id.chat_id]
+ tid = event.action_message.to_id.chat_id
+ finally:
+ irc_channel = self.tid_to_iid[tid]
+ await get_telegram_channel_participants(tid)
hunk ./irtelegramd.py 378
- await self.join_irc_channel(irc_nick, irc_channel)
+ await self.join_irc_channel(irc_nick, irc_channel, False)
hunk ./irtelegramd.py 385
- if not isinstance(chat, User):
+ if not isinstance(chat, telethon.types.User):
hunk ./irtelegramd.py 389
- await self.join_irc_channel(self.irc_nick, channel)
+ await self.join_irc_channel(self.irc_nick, channel, True)