irc: Add MODE command
patch 8f98a1d6a3608b31de2c9251491c1a51e5c64124
Author: E. Bosch <presidev@AT@gmail.com>
Date: Thu Mar 4 01:08:27 CET 2021
* irc: Add MODE command
Convert params_required from boolean to min number of parameters required
(num_params_required).
hunk ./irc.py 21
+ALL_PARAMS = 16
hunk ./irc.py 29
+IRC_MODE_RX = re.compile(PREFIX + r'MODE( +|\n)(?P<target>[^ ]+( +|\n)|)(?P<mode>[^ ]+( +|\n)|)(?P<arguments>[^\n]+|)')
hunk ./irc.py 77
- for pattern, handler, register_required, params_required in self.irc_handlers:
+ for pattern, handler, register_required, num_params_required in self.irc_handlers:
hunk ./irc.py 86
- if num_params >= num_params_expected or not params_required:
+ if num_params >= self.num_params_necessary(num_params_required,
+ num_params_expected):
hunk ./irc.py 105
- # pattern handle register_required params_required
- (IRC_JOIN_RX, self.handle_irc_join, True, True),
- (IRC_MOTD_RX, self.handle_irc_motd, True, False),
- (IRC_NAMES_RX, self.handle_irc_names, True, True),
- (IRC_NICK_RX, self.handle_irc_nick, False, True),
- (IRC_PASS_RX, self.handle_irc_pass, False, True),
- (IRC_PING_RX, self.handle_irc_ping, True, True),
- (IRC_PRIVMSG_RX, self.handle_irc_privmsg, True, True),
- (IRC_QUIT_RX, self.handle_irc_quit, False, False),
- (IRC_TOPIC_RX, self.handle_irc_topic, True, True),
- (IRC_USER_RX, self.handle_irc_user, False, True),
- (IRC_VERSION_RX, self.handle_irc_version, True, False),
- (IRC_WHO_RX, self.handle_irc_who, True, True),
- (IRC_WHOIS_RX, self.handle_irc_whois, True, True),
+ # pattern handle register_required num_params_required
+ (IRC_JOIN_RX, self.handle_irc_join, True, ALL_PARAMS),
+ (IRC_MODE_RX, self.handle_irc_mode, True, 1),
+ (IRC_MOTD_RX, self.handle_irc_motd, True, 0),
+ (IRC_NAMES_RX, self.handle_irc_names, True, ALL_PARAMS),
+ (IRC_NICK_RX, self.handle_irc_nick, False, ALL_PARAMS),
+ (IRC_PASS_RX, self.handle_irc_pass, False, ALL_PARAMS),
+ (IRC_PING_RX, self.handle_irc_ping, True, ALL_PARAMS),
+ (IRC_PRIVMSG_RX, self.handle_irc_privmsg, True, ALL_PARAMS),
+ (IRC_QUIT_RX, self.handle_irc_quit, False, 0),
+ (IRC_TOPIC_RX, self.handle_irc_topic, True, ALL_PARAMS),
+ (IRC_USER_RX, self.handle_irc_user, False, ALL_PARAMS),
+ (IRC_VERSION_RX, self.handle_irc_version, True, 0),
+ (IRC_WHO_RX, self.handle_irc_who, True, ALL_PARAMS),
+ (IRC_WHOIS_RX, self.handle_irc_whois, True, ALL_PARAMS),
hunk ./irc.py 197
+ async def handle_irc_mode(self, user, target, mode, arguments):
+ self.logger.debug('Handling MODE: %s, %s, %s', target, mode, arguments)
+
+ if not mode:
+ tgt = target.lower()
+ if tgt in self.users.keys():
+ if tgt == user.irc_nick:
+ await self.mode_user(user, user, False)
+ else:
+ await self.reply_code(user, 'ERR_USERSDONTMATCH')
+ elif tgt[0] == '#':
+ if tgt in self.irc_channels.keys():
+ await self.mode_channel(user, target, False)
+ else:
+ await self.reply_code(user, 'ERR_NOSUCHCHANNEL', (target,))
+ else:
+ await self.reply_code(user, 'ERR_NOSUCHNICK', (target,))
+
hunk ./irc.py 340
+ await self.mode_user(user, user, True)
hunk ./irc.py 363
+ async def mode_user(self, user, usr, com):
+ modes = ''
+ if usr.oper: modes += 'o'
+ if usr.tls: modes += 'S'
+ if modes: modes = '+' + modes
+ if com:
+ await self.reply_command(user, usr, 'MODE', (usr.irc_nick, modes))
+ else:
+ await self.reply_code(user, 'RPL_UMODEIS', (modes,))
+
+ async def mode_channel(self, user, channel, com):
+ modes = '+nt'
+ if com:
+ await self.reply_command(user, user, 'MODE', (channel, modes))
+ else:
+ await self.reply_code(user, 'RPL_CHANNELMODEIS', (channel, modes,''))
+
hunk ./irc.py 437
+ def num_params_necessary(self, num_params_required, num_params_expected):
+ if num_params_required == ALL_PARAMS:
+ npn = num_params_expected
+ else:
+ npn = num_params_required
+ return npn
+
hunk ./irc_replies.py 7
- 'RPL_MYINFO': ('004', '{} irgramd-{} o nt'),
+ 'RPL_MYINFO': ('004', '{} irgramd-{} oS nt'),
hunk ./irc_replies.py 9
+ 'RPL_UMODEIS': ('221', ':{}'),
hunk ./irc_replies.py 17
+ 'RPL_CHANNELMODEIS': ('324', '{} {} {}'),