irc: Add MOTD command
patch 96d42ed534ad22a1d5ef012cb679b3ab6550151c
Author: E. Bosch <presidev@AT@gmail.com>
Date: Wed Feb 17 21:24:00 CET 2021
* irc: Add MOTD command
Add support for commands without parameters
hunk ./irc.py 28
+IRC_MOTD_RX = re.compile(PREFIX + r'MOTD( +:| +|\n)(?P<target>[^\n]+|)')
hunk ./irc.py 69
- for pattern, handler, register_required in self.irc_handlers:
+ for pattern, handler, register_required, params_required in self.irc_handlers:
hunk ./irc.py 78
- if num_params >= num_params_expected:
+ if num_params >= num_params_expected or not params_required:
hunk ./irc.py 96
- # pattern handle register_required
- (IRC_JOIN_RX, self.handle_irc_join, True),
- (IRC_NAMES_RX, self.handle_irc_names, True),
- (IRC_NICK_RX, self.handle_irc_nick, False),
- (IRC_PASS_RX, self.handle_irc_pass, False),
- (IRC_PING_RX, self.handle_irc_ping, True),
- (IRC_PRIVMSG_RX, self.handle_irc_privmsg, True),
- (IRC_USER_RX, self.handle_irc_user, False),
- (IRC_WHO_RX, self.handle_irc_who, True),
- (IRC_WHOIS_RX, self.handle_irc_whois, True),
+ # 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_USER_RX, self.handle_irc_user, False, True),
+ (IRC_WHO_RX, self.handle_irc_who, True, True),
+ (IRC_WHOIS_RX, self.handle_irc_whois, True, True),
hunk ./irc.py 180
+ async def handle_irc_motd(self, user, target):
+ self.logger.debug('Handling MOTD: %s', target)
+
+ if not target or target == self.hostname:
+ await self.send_motd(user)
+ else:
+ await self.reply_code(user, 'ERR_NOSUCHSERVER', (target,))
+