patch a632ad5590ca682a3409d25be72768761aff0b95 Author: E. Bosch Date: Fri Feb 5 00:38:22 CET 2021 * irc: Add WHO command diff -rN -u old-irgramd/irc.py new-irgramd/irc.py --- old-irgramd/irc.py 2024-10-23 06:30:42.559520883 +0200 +++ new-irgramd/irc.py 2024-10-23 06:30:42.567520870 +0200 @@ -29,6 +29,7 @@ IRC_PRIVMSG_RX = re.compile(PREFIX + r'PRIVMSG( +|\n)(?P[^ ]+)( +:| +|\n)(?P[^\n]+|)') IRC_USER_RX = re.compile(PREFIX + r'USER( +|\n)(?P[^ ]+) +[^ ]+ +[^ ]+( +:| +|\n)(?P[^\n]+|)') IRC_JOIN_RX = re.compile(PREFIX + r'JOIN( +|\n)(?P[^ ]+)') +IRC_WHO_RX = re.compile(PREFIX + r'WHO( +:| +|\n)(?P[^\n]+|)') # IRC Handler @@ -94,6 +95,7 @@ (IRC_PRIVMSG_RX, self.handle_irc_privmsg, True), (IRC_USER_RX, self.handle_irc_user, False), (IRC_JOIN_RX, self.handle_irc_join, True), + (IRC_WHO_RX, self.handle_irc_who, True), ) self.iid_to_tid = {} self.irc_channels = collections.defaultdict(set) @@ -159,6 +161,27 @@ self.hostname, self.hostname, payload )) + async def handle_irc_who(self, user, target): + self.logger.debug('Handling WHO: %s', target) + tgt = target.lower() + if tgt in self.irc_channels.keys(): + users = self.irc_channels[tgt] + chan = target + elif tgt in self.users.keys(): + users = (self.users[tgt],) + chan = '*' + else: + await self.reply_code(user, 'ERR_NOSUCHSERVER', (target,)) + return + for usr in users: + if not isinstance(usr,IRCUser): + usr = self.users[usr.lower()] + op = self.get_irc_op(usr.irc_nick, chan) + await self.reply_code(user, 'RPL_WHOREPLY', (chan, usr.irc_username, + usr.address, self.hostname, usr.irc_nick, op, usr.irc_realname + )) + await self.reply_code(user, 'RPL_ENDOFWHO', (chan,)) + async def handle_irc_privmsg(self, user, nick, message): self.logger.debug('Handling PRIVMSG: %s, %s', nick, message) diff -rN -u old-irgramd/irc_replies.py new-irgramd/irc_replies.py --- old-irgramd/irc_replies.py 2024-10-23 06:30:42.567520870 +0200 +++ new-irgramd/irc_replies.py 2024-10-23 06:30:42.567520870 +0200 @@ -6,11 +6,13 @@ 'RPL_CREATED': ('003', ':This server was created {}'), 'RPL_MYINFO': ('004', '{} irgramd-{} o nt'), 'RPL_ISUPPORT': ('005', 'CASEMAPPING=ascii CHANLIMIT=#&+: CHANTYPES=&#+ CHANMODES=,,,nt CHANNELLEN={} NICKLEN={} SAFELIST :are supported by this server'), + 'RPL_ENDOFWHO': ('315', '{} :End of WHO list'), + 'RPL_WHOREPLY': (352, '{} {} {} {} {} H{} :0 {}'), 'RPL_MOTDSTART': ('375', ':- {} Message of the day - '), 'RPL_MOTD': ('372', ':- {}'), 'RPL_ENDOFMOTD': (376, 'End of MOTD command'), 'ERR_NOSUCHNICK': ('401', 'No such nick'), - 'ERR_NOSUCHSERVER': ('402', 'No such server'), + 'ERR_NOSUCHSERVER': ('402', '{} :Target not found'), 'ERR_NOSUCHCHANNEL': ('403', 'No such channel'), 'ERR_CANNOTSENDTOCHAN': ('404', 'Cannot send to channel'), 'ERR_TOOMANYCHANNELS': ('405', 'Too many channels'),