irc: Add support for multiple irc connections (users) with new IRCUser class
patch 615f063fdfeb239ec0ce302102ba69c73ebfe4c4
Author: E. Bosch <presidev@AT@gmail.com>
Date: Wed Jan 20 01:13:37 CET 2021
* irc: Add support for multiple irc connections (users) with new IRCUser class
hunk ./irc.py 32
+ self.users = []
hunk ./irc.py 39
- self.stream = stream
- self.address = '{}:{}'.format(address[0], address[1])
-
- self.logger.debug('Running client connection from %s', self.address)
+ user = IRCUser(stream, address)
+ self.users.append(user)
+
+ self.logger.debug('Running client connection from %s', user.address)
hunk ./irc.py 45
- message = await self.stream.read_until(b'\n')
+ message = await user.stream.read_until(b'\n')
hunk ./irc.py 52
- await handler(**matches.groupdict())
+ await handler(user, **matches.groupdict())
hunk ./irc.py 70
- self.irc_nick = None
hunk ./irc.py 74
- async def send_irc_command(self, command):
+ async def send_irc_command(self, user, command):
hunk ./irc.py 77
- self.stream.write(command.encode())
-
- async def handle_irc_nick(self, nick):
+ user.stream.write(command.encode())
+
+ async def handle_irc_nick(self, user, nick):
hunk ./irc.py 82
- if self.irc_nick in self.iid_to_tid:
- tid = self.iid_to_tid[self.irc_nick]
- self.tg.tid_to_iid[tid] = nick
+ if user.irc_nick in self.iid_to_tid:
+ tid = self.iid_to_tid[user.irc_nick]
+ self.tg.tid_to_iid[tid] = nick
hunk ./irc.py 87
- self.irc_nick = nick
-
- async def handle_irc_user(self, username, realname):
+ user.irc_nick = nick
+
+ async def handle_irc_user(self, user, username, realname):
hunk ./irc.py 92
- self.irc_nick = username
-
- await self.send_irc_command(':{} 001 {} :{}'.format(
- self.hostname, self.irc_nick, 'Welcome to irgramd'
+ user.irc_username = username
+ user.irc_realname = realname
+
+ await self.send_irc_command(user, ':{} 001 {} :{}'.format(
+ self.hostname, user.irc_nick, 'Welcome to irgramd'
hunk ./irc.py 98
- await self.send_irc_command(':{} 376 {} :{}'.format(
- self.hostname, self.irc_nick, 'End of MOTD command'
+ await self.send_irc_command(user, ':{} 376 {} :{}'.format(
+ self.hostname, user.irc_nick, 'End of MOTD command'
hunk ./irc.py 102
- async def handle_irc_join(self, channel):
+ async def handle_irc_join(self, user, channel):
hunk ./irc.py 105
- await self.join_irc_channel(self.irc_nick, channel, True)
-
- async def handle_irc_pass(self, app_id, app_hash):
+ await self.join_irc_channel(user, channel, True)
+
+ async def handle_irc_pass(self, user, app_id, app_hash):
hunk ./irc.py 110
- async def handle_irc_ping(self, payload):
+ async def handle_irc_ping(self, user, payload):
hunk ./irc.py 112
- await self.send_irc_command(':{} PONG {} :{}'.format(
+ await self.send_irc_command(user, ':{} PONG {} :{}'.format(
hunk ./irc.py 116
- async def handle_irc_privmsg(self, nick, message):
+ async def handle_irc_privmsg(self, user, nick, message):
hunk ./irc.py 125
- async def join_irc_channel(self, nick, channel, full_join=False):
- self.irc_channels[channel].add(nick)
+ async def join_irc_channel(self, user, channel, full_join=False):
+ self.irc_channels[channel].add(user.irc_nick)
hunk ./irc.py 129
- await self.send_irc_command(':{} JOIN :{}'.format(
- self.get_irc_user_mask(nick), channel
+ await self.send_irc_command(user, ':{} JOIN :{}'.format(
+ self.get_irc_user_mask(user.irc_nick), channel
hunk ./irc.py 142
- await self.send_irc_command(':{} TOPIC {} :{}'.format(
- self.get_irc_user_mask(nick), channel, topic
+ await self.send_irc_command(user, ':{} TOPIC {} :{}'.format(
+ self.get_irc_user_mask(user.irc_nick), channel, topic
hunk ./irc.py 148
- await self.send_irc_command(':{} 353 {} = {} :{}'.format(
- self.hostname, self.irc_nick, channel, ' '.join(chunk)
+ await self.send_irc_command(user, ':{} 353 {} = {} :{}'.format(
+ self.hostname, user.irc_nick, channel, ' '.join(chunk)
hunk ./irc.py 152
- async def part_irc_channel(self, nick, channel):
- self.irc_channels[channel].remove(nick)
- await self.send_irc_command(':{} PART {} :'.format(
- self.get_irc_user_mask(nick), channel
+ 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
hunk ./irc.py 157
+
+class IRCUser(object):
+ def __init__(self, stream, address):
+ self.stream = stream
+ self.address = '{}:{}'.format(address[0], address[1])
+ self.irc_nick = None
+ self.irc_username = None
+ self.irc_realname = None
hunk ./telegram.py 120
- await self.irc.send_irc_command(':{} PRIVMSG {} :{}'.format(
- self.irc.get_irc_user_mask(nick), self.irc.irc_nick, message
- ))
+ for user in self.irc.users:
+ await self.irc.send_irc_command(user, ':{} PRIVMSG {} :{}'.format(
+ self.irc.get_irc_user_mask(nick), user.irc_nick, message
+ ))
hunk ./telegram.py 149
- await self.irc.send_irc_command(':{} PRIVMSG {} :{}'.format(
- self.irc.get_irc_user_mask(nick), channel, message
- ))
+ for user in self.irc.users:
+ await self.irc.send_irc_command(user, ':{} PRIVMSG {} :{}'.format(
+ self.irc.get_irc_user_mask(nick), channel, message
+ ))