irc: update user mask generation
patch 056e5b5a8b6235ebdca9d0524b1d8a5d50e41837
Author: E. Bosch <presidev@AT@gmail.com>
Date: Mon Feb 1 19:48:42 CET 2021
* irc: update user mask generation
diff -rN -u old-irgramd/irc.py new-irgramd/irc.py
--- old-irgramd/irc.py 2024-11-23 02:00:15.761617647 +0100
+++ new-irgramd/irc.py 2024-11-23 02:00:15.761617647 +0100
@@ -96,8 +96,6 @@
self.irc_channels = collections.defaultdict(set)
self.start_time = time.strftime('%a %d %b %Y %H:%M:%S %z')
- def get_irc_user_mask(self, nick):
- return '{}!{}@{}'.format(nick, nick, self.hostname)
async def send_irc_command(self, user, command):
self.logger.debug('Send IRC Command: %s', command)
@@ -204,7 +202,7 @@
# Join Channel
await self.send_irc_command(user, ':{} JOIN :{}'.format(
- self.get_irc_user_mask(user.irc_nick), channel
+ user.get_irc_mask(), channel
))
if not full_join:
@@ -217,7 +215,7 @@
# Set channel topic
topic = (await self.tg.telegram_client.get_entity(tid)).title
await self.send_irc_command(user, ':{} TOPIC {} :{}'.format(
- self.get_irc_user_mask(user.irc_nick), channel, topic
+ user.get_irc_mask(), channel, topic
))
# Send NAMESLIST
@@ -229,7 +227,7 @@
async def part_irc_channel(self, user, channel):
self.irc_channels[channel].remove(user.irc_nick)
await self.send_irc_command(user, ':{} PART {} :'.format(
- self.get_irc_user_mask(user.irc_nick), channel
+ user.get_irc_mask(), channel
))
class IRCUser(object):
@@ -243,6 +241,9 @@
self.password = ''
self.recv_pass = ''
+ def get_irc_mask(self):
+ return '{}!{}@{}'.format(self.irc_nick, self.irc_username, self.address)
+
def valid_nick(self, nick):
if len(nick) <= NICK_MAX_LENGTH and nick[0] in VALID_IRC_NICK_FIRST_CHARS:
for x in nick[1:]:
diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py
--- old-irgramd/telegram.py 2024-11-23 02:00:15.761617647 +0100
+++ new-irgramd/telegram.py 2024-11-23 02:00:15.761617647 +0100
@@ -108,6 +108,10 @@
def get_telegram_channel(self, chat):
return '#' + chat.title.replace(' ', '-')
+ def get_irc_user_from_telegram(self, tid):
+ nick = self.tid_to_iid[tid]
+ return self.irc.users[nick.lower()]
+
async def get_irc_nick_from_telegram_id(self, tid, entity=None):
if tid not in self.tid_to_iid:
user = entity or await self.telegram_client.get_entity(tid)
@@ -148,11 +152,11 @@
async def handle_telegram_private_message(self, event):
self.logger.debug('Handling Telegram Private Message: %s', event)
- nick = await self.get_irc_nick_from_telegram_id(event.sender_id)
+ user = self.get_irc_user_from_telegram(event.sender_id)
for message in event.message.message.splitlines():
- for user in [x for x in self.irc.users.values() if x.stream]:
- await self.irc.send_irc_command(user, ':{} PRIVMSG {} :{}'.format(
- self.irc.get_irc_user_mask(nick), user.irc_nick, message
+ for irc_user in [x for x in self.irc.users.values() if x.stream]:
+ await self.irc.send_irc_command(irc_user, ':{} PRIVMSG {} :{}'.format(
+ user.get_irc_mask(), irc_user.irc_nick, message
))
async def handle_telegram_channel_message(self, event):
@@ -164,7 +168,8 @@
# if channel not in self.irc.irc_channels:
# await self.irc.join_irc_channel(self.irc.irc_nick, channel, True)
- nick = await self.get_irc_nick_from_telegram_id(event.sender_id)
+ user = self.get_irc_user_from_telegram(event.sender_id)
+
# if nick not in self.irc.irc_channels[channel]:
# await self.irc.join_irc_channel(nick, channel, False)
@@ -179,9 +184,9 @@
# Send all messages to IRC
for message in messages:
- for user in [x for x in self.irc.users.values() if x.stream]:
- await self.irc.send_irc_command(user, ':{} PRIVMSG {} :{}'.format(
- self.irc.get_irc_user_mask(nick), channel, message
+ for irc_user in [x for x in self.irc.users.values() if x.stream]:
+ await self.irc.send_irc_command(irc_user, ':{} PRIVMSG {} :{}'.format(
+ user.get_irc_mask(), channel, message
))
async def handle_telegram_chat_action(self, event):