patch 4b63ac15d2b61f2c0da0686ba1936c79d7136444
Author: E. Bosch <presidev@AT@gmail.com>
Date: Fri Feb 12 03:09:58 CET 2021
* irc: Fix JOIN command
hunk ./irc.py 32
-IRC_JOIN_RX = re.compile(PREFIX + r'JOIN( +|\n)(?P<channel>[^ ]+)')
+IRC_JOIN_RX = re.compile(PREFIX + r'JOIN( +|\n)(?P<channels>[^ ]+)')
hunk ./irc.py 156
- async def handle_irc_join(self, user, channel):
- self.logger.debug('Handling JOIN: %s', channel)
-
- await self.join_irc_channel(user, channel, True)
+ async def handle_irc_join(self, user, channels):
+ self.logger.debug('Handling JOIN: %s', channels)
+
+ if channels == '0':
+ #part all
+ pass
+ else:
+ for channel in channels.split(','):
+ if channel.lower() in self.irc_channels.keys():
+ await self.join_irc_channel(user, channel, True)
+ else:
+ await reply_code(user, 'ERR_NOSUCHCHANNEL', (channel,))
hunk ./irc.py 278
+ entity_cache = [None]
hunk ./irc.py 280
- self.irc_channels[chan].add(user.irc_nick)
+ real_chan = self.get_realcaps_name(chan)
+
+ if full_join: self.irc_channels[chan].add(user.irc_nick)
+
+ # Notify IRC users in this channel
+ for usr in [self.users[x.lower()] for x in self.irc_channels[chan] if self.users[x.lower()].stream]:
+ await self.reply_command(usr, user, 'JOIN', (real_chan,))
+
+ if not full_join:
+ return
+
hunk ./irc.py 295
- # Join Channel
- await self.send_irc_command(user, ':{} JOIN :{}'.format(
- user.get_irc_mask(), channel
- ))
-
- if not full_join:
- return
-
- # Get all users from channel
- tid = self.iid_to_tid[channel.lower()]
- nicks = self.irc_channels[channel.lower()]
-
- # Set channel topic
- topic = (await self.tg.telegram_client.get_entity(tid)).title
- await self.send_irc_command(user, ':{} TOPIC {} :{}'.format(
- user.get_irc_mask(), channel, topic
- ))
-
- # Send NAMESLIST
+ date = await self.tg.get_channel_creation(channel, entity_cache)
+ await self.reply_code(user, 'RPL_CREATIONTIME', (real_chan, date))
+ await self.irc_channel_topic(user, real_chan, entity_cache)
+ await self.irc_namelist(user, real_chan)
+
+ async def irc_channel_topic(self, user, channel, entity_cache):
+ topic = await self.tg.get_channel_topic(channel, entity_cache)
+ timestamp = await self.tg.get_channel_creation(channel, entity_cache)
+ founder = list(self.irc_channels_founder[channel.lower()])[0]
+ await self.reply_code(user, 'RPL_TOPIC', (channel, topic))
+ await self.reply_code(user, 'RPL_TOPICWHOTIME', (channel, founder, timestamp))
+
+ async def irc_namelist(self, user, channel):
+ nicks = [self.get_irc_op(x, channel) + x for x in self.irc_channels[channel.lower()]]
+ status = '='
hunk ./irc.py 311
- await self.send_irc_command(user, ':{} 353 {} = {} :{}'.format(
- self.hostname, user.irc_nick, channel, ' '.join(chunk)
- ))
+ await self.reply_code(user, 'RPL_NAMREPLY', (status, channel, ' '.join(chunk)))
+ await self.reply_code(user, 'RPL_ENDOFNAMES', (channel,))
hunk ./irc.py 329
+ def get_realcaps_name(self, name):
+ # name must be in lower
+ return self.tg.tid_to_iid[self.iid_to_tid[name]]
+
hunk ./irc_replies.py 16
+ 'RPL_CREATIONTIME': ('329', '{} {}'),
hunk ./irc_replies.py 18
+ 'RPL_TOPIC': ('332', '{} :{}'),
+ 'RPL_TOPICWHOTIME': ('333', '{} {} {}'),
hunk ./irc_replies.py 22
+ 'RPL_NAMREPLY': ('353', '{} {} :{}'),
+ 'RPL_ENDOFNAMES': ('366', '{} :End of NAME reply'),
hunk ./irc_replies.py 29
- 'ERR_NOSUCHCHANNEL': ('403', 'No such channel'),
+ 'ERR_NOSUCHCHANNEL': ('403', '{} :Channel not found'),
hunk ./telegram.py 5
+import re
hunk ./telegram.py 14
+# Constants
+
+TL_TYPES_IDENT = re.compile(r"<class 'telethon.tl.types.([^']+)'>")
+
hunk ./telegram.py 37
+ self.channels_date = {}
hunk ./telegram.py 197
- def get_tid(self, irc_nick, tid=None):
+ async def get_channel_topic(self, channel, entity_cache=[None]):
+ tid = self.get_tid(channel)
+ if entity_cache[0]:
+ entity = entity_cache[0]
+ else:
+ entity = await self.telegram_client.get_entity(tid)
+ entity_cache[0] = entity
+ entity_type = self.get_entity_type(entity)
+ return 'Telegram ' + entity_type + ' ' + str(tid) + ': ' + entity.title
+
+ async def get_channel_creation(self, channel, entity_cache=[None]):
+ tid = self.get_tid(channel)
+ if tid in self.channels_date.keys():
+ timestamp = self.channels_date[tid]
+ else:
+ if entity_cache[0]:
+ entity = entity_cache[0]
+ else:
+ entity = await self.telegram_client.get_entity(tid)
+ entity_cache[0] = entity
+ timestamp = entity.date.timestamp()
+ self.channels_date[tid] = timestamp
+ return int(timestamp)
+
+ def get_tid(self, irc_item, tid=None):
+ it = irc_item.lower()
hunk ./telegram.py 225
- elif irc_nick in self.irc.iid_to_tid:
- tid = self.irc.iid_to_tid[irc_nick.lower()]
+ elif it in self.irc.iid_to_tid:
+ tid = self.irc.iid_to_tid[it]
hunk ./telegram.py 231
+ def get_entity_type(self, entity):
+ return TL_TYPES_IDENT.match(str(type(entity))).groups()[0]
+