irc: Improve reply function
patch ff5ce787fa94beaa0cb7d3dff7849ba4386da021
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Jan 31 01:39:07 CET 2021
* irc: Improve reply function
Fix replies for errors in nick command
hunk ./irc.py 75
- await self.reply(user, 'ERR_NEEDMOREPARAMS')
+ await self.reply_code(user, 'ERR_NEEDMOREPARAMS')
hunk ./irc.py 78
- await self.reply(user, 'ERR_UNKNOWNCOMMAND')
+ await self.reply_code(user, 'ERR_UNKNOWNCOMMAND')
hunk ./irc.py 113
- await self.reply(user, 'ERR_ALREADYREGISTRED')
+ await self.reply_code(user, 'ERR_ALREADYREGISTRED')
hunk ./irc.py 121
- await self.reply(user, 'ERR_ERRONEUSNICKNAME')
+ await self.reply_code(user, 'ERR_ERRONEUSNICKNAME', (nick,), '*')
hunk ./irc.py 123
- await self.reply(user, 'ERR_NICKNAMEINUSE')
+ await self.reply_code(user, 'ERR_NICKNAMEINUSE', (nick,), '*')
hunk ./irc.py 137
- await self.reply(user, 'ERR_PASSWDMISMATCH')
+ await self.reply_code(user, 'ERR_PASSWDMISMATCH')
hunk ./irc.py 170
- async def reply(self, user, code):
+ async def reply_code(self, user, code, params=None, client=None):
hunk ./irc.py 172
- await self.send_irc_command(user, ':{} {} {} :{}'.format(
- self.hostname, num, user.irc_nick, tail
- ))
-
- async def reply_param(self, user, num, rest):
- await self.send_irc_command(user, ':{} {} {} {}'.format(
- self.hostname, num, user.irc_nick, rest
- ))
+ if params:
+ nick = client if client else user.irc_nick
+ rest = tail.format(*params)
+ stri = ':{} {} {} {}'.format(self.hostname, num, nick, rest)
+ else:
+ stri = ':{} {} {} :{}'.format(self.hostname, num, user.irc_nick, tail)
+ await self.send_irc_command(user, stri)
hunk ./irc.py 181
- num, rest = irc_codes['RPL_WELCOME']
- await self.reply_param(user, num, rest.format(user.irc_nick))
- num, rest = irc_codes['RPL_YOURHOST']
- await self.reply_param(user, num, rest.format(self.hostname, VERSION))
- num, rest = irc_codes['RPL_CREATED']
- await self.reply_param(user, num, rest.format(self.start_time))
- num, rest = irc_codes['RPL_MYINFO']
- await self.reply_param(user, num, rest.format(self.hostname, VERSION))
- num, rest = irc_codes['RPL_ISUPPORT']
- await self.reply_param(user, num, rest.format(str(CHAN_MAX_LENGHT), str(NICK_MAX_LENGTH)))
+ await self.reply_code(user, 'RPL_WELCOME', (user.irc_nick,))
+ await self.reply_code(user, 'RPL_YOURHOST', (self.hostname, VERSION))
+ await self.reply_code(user, 'RPL_CREATED', (self.start_time,))
+ await self.reply_code(user, 'RPL_MYINFO', (self.hostname, VERSION))
+ await self.reply_code(user, 'RPL_ISUPPORT', (str(CHAN_MAX_LENGHT), str(NICK_MAX_LENGTH)))
hunk ./irc.py 189
- num, rest = irc_codes['RPL_MOTDSTART']
- await self.reply_param(user, num, rest.format(self.hostname))
- num, rest = irc_codes['RPL_MOTD']
- await self.reply_param(user, num, rest.format('Welcome to the irgramd server'))
- await self.reply_param(user, num, rest.format(''))
- await self.reply_param(user, num, rest.format('This is not a normal IRC server, it\'s a gateway that'))
- await self.reply_param(user, num, rest.format('allows connecting from an IRC client (the program that'))
- await self.reply_param(user, num, rest.format('you are [probably] using right now) to the Telegram instant'))
- await self.reply_param(user, num, rest.format('messaging network as a regular user account (not bot)'))
- await self.reply_param(user, num, rest.format(''))
- await self.reply_param(user, num, rest.format('irgramd is an open source project that you can find on'))
- await self.reply_param(user, num, rest.format('git repository: https://github.com/prsai/irgramd'))
- await self.reply_param(user, num, rest.format('darcs repository: https://src.presi.org/darcs/irgramd'))
- await self.reply(user, 'RPL_ENDOFMOTD')
+ await self.reply_code(user, 'RPL_MOTDSTART', (self.hostname,))
+ await self.reply_code(user, 'RPL_MOTD', ('Welcome to the irgramd server',))
+ await self.reply_code(user, 'RPL_MOTD', ('',))
+ await self.reply_code(user, 'RPL_MOTD', ('This is not a normal IRC server, it\'s a gateway that',))
+ await self.reply_code(user, 'RPL_MOTD', ('allows connecting from an IRC client (the program that',))
+ await self.reply_code(user, 'RPL_MOTD', ('you are [probably] using right now) to the Telegram instant',))
+ await self.reply_code(user, 'RPL_MOTD', ('messaging network as a regular user account (not bot)',))
+ await self.reply_code(user, 'RPL_MOTD', ('',))
+ await self.reply_code(user, 'RPL_MOTD', ('irgramd is an open source project that you can find on',))
+ await self.reply_code(user, 'RPL_MOTD', ('git repository: https://github.com/prsai/irgramd',))
+ await self.reply_code(user, 'RPL_MOTD', ('darcs repository: https://src.presi.org/darcs/irgramd',))
+ await self.reply_code(user, 'RPL_ENDOFMOTD')
hunk ./irc_replies.py 29
- 'ERR_ERRONEUSNICKNAME': ('432', 'Erroneus nickname'),
- 'ERR_NICKNAMEINUSE': ('433', 'Nickname in use'),
+ 'ERR_ERRONEUSNICKNAME': ('432', '{} :Erroneus nickname'),
+ 'ERR_NICKNAMEINUSE': ('433', '{} :Nickname in use'),