Extract telegram code from class IRCHandler into class TelegramHandler
patch ee4d2179cb01dca538617a8da0a5e5220a590f36
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Nov 21 00:31:39 CET 2020
* Extract telegram code from class IRCHandler into class TelegramHandler
hunk ./irc.py 40
+ self.tg = TelegramHandler(self, config_dir)
hunk ./irc.py 88
- self.tid_to_iid[tid] = nick
+ self.tg.tid_to_iid[tid] = nick
hunk ./irc.py 105
- await self.initialize_telegram()
+ await self.tg.initialize_telegram()
hunk ./irc.py 109
- self.telegram_app_id = int(app_id)
- self.telegram_app_hash = app_hash
+ self.tg.telegram_app_id = int(app_id)
+ self.tg.telegram_app_hash = app_hash
hunk ./irc.py 125
- await self.telegram_client.send_message(telegram_id, message)
+ await self.tg.telegram_client.send_message(telegram_id, message)
hunk ./irc.py 140
- nicks, voices = await self.get_telegram_channel_participants(tid)
+ nicks, voices = await self.tg.get_telegram_channel_participants(tid)
hunk ./irc.py 143
- topic = (await self.telegram_client.get_entity(tid)).title
+ topic = (await self.tg.telegram_client.get_entity(tid)).title
hunk ./irc.py 167
- _, voices = await self.get_telegram_channel_participants(tid)
+ _, voices = await self.tg.get_telegram_channel_participants(tid)
hunk ./irc.py 188
+class TelegramHandler(object):
+ def __init__(self, irc, config_dir):
+ self.logger = logging.getLogger()
+ self.config_dir = config_dir
+ self.irc = irc
+
hunk ./irc.py 206
- telegram_session = os.path.join(self.telegram_session_dir, self.irc_nick)
+ telegram_session = os.path.join(self.telegram_session_dir, self.irc.irc_nick)
hunk ./irc.py 228
- iid = self.irc_nick
+ iid = self.irc.irc_nick
hunk ./irc.py 231
- self.iid_to_tid[iid] = tid
+ self.irc.iid_to_tid[iid] = tid
hunk ./irc.py 241
- while nick in self.iid_to_tid:
+ while nick in self.irc.iid_to_tid:
hunk ./irc.py 253
- self.iid_to_tid[nick] = tid
+ self.irc.iid_to_tid[nick] = tid
hunk ./irc.py 262
- self.iid_to_tid[channel] = tid
+ self.irc.iid_to_tid[channel] = tid
hunk ./irc.py 277
- self.irc_channels[channel].add(user_nick)
+ self.irc.irc_channels[channel].add(user_nick)
hunk ./irc.py 294
- await self.send_irc_command(':{} PRIVMSG {} :{}'.format(
- self.get_irc_user_mask(nick), self.irc_nick, message
+ await self.irc.send_irc_command(':{} PRIVMSG {} :{}'.format(
+ self.irc.get_irc_user_mask(nick), self.irc.irc_nick, message
hunk ./irc.py 304
- if channel not in self.irc_channels:
- await self.join_irc_channel(self.irc_nick, channel, True)
+ if channel not in self.irc.irc_channels:
+ await self.irc.join_irc_channel(self.irc.irc_nick, channel, True)
hunk ./irc.py 308
- if nick not in self.irc_channels[channel]:
- await self.join_irc_channel(nick, channel, False)
+ if nick not in self.irc.irc_channels[channel]:
+ await self.irc.join_irc_channel(nick, channel, False)
hunk ./irc.py 322
- await self.send_irc_command(':{} PRIVMSG {} :{}'.format(
- self.get_irc_user_mask(nick), channel, message
+ await self.irc.send_irc_command(':{} PRIVMSG {} :{}'.format(
+ self.irc.get_irc_user_mask(nick), channel, message
hunk ./irc.py 346
- await self.join_irc_channel(irc_nick, irc_channel, False)
+ await self.irc.join_irc_channel(irc_nick, irc_channel, False)
hunk ./irc.py 348
- await self.part_irc_channel(irc_nick, irc_channel)
+ await self.irc.part_irc_channel(irc_nick, irc_channel)
hunk ./irc.py 356
- self.iid_to_tid[channel] = chat.id
- await self.join_irc_channel(self.irc_nick, channel, True)
+ self.irc.iid_to_tid[channel] = chat.id
+ await self.irc.join_irc_channel(self.irc.irc_nick, channel, True)