irc: Move valid_nick() to IRCUser class
patch 7ae0aa39e474aa8974b0da88ffe14125da15ec66
Author: E. Bosch <presidev@AT@gmail.com>
Date: Thu Jan 28 14:07:44 CET 2021
* irc: Move valid_nick() to IRCUser class
diff -rN -u old-irgramd/irc.py new-irgramd/irc.py
--- old-irgramd/irc.py 2024-11-23 02:25:11.651258318 +0100
+++ new-irgramd/irc.py 2024-11-23 02:25:11.651258318 +0100
@@ -112,7 +112,7 @@
async def handle_irc_nick(self, user, nick):
self.logger.debug('Handling NICK: %s', nick)
- if not self.valid_nick(nick):
+ if not user.valid_nick(nick):
await self.reply(user, 'ERR_ERRONEUSNICKNAME')
elif nick in [x.irc_nick for x in self.users if x is not user]:
await self.reply(user, 'ERR_NICKNAMEINUSE')
@@ -234,14 +234,6 @@
self.get_irc_user_mask(user.irc_nick), channel
))
- def valid_nick(self, nick):
- if len(nick) <= NICK_MAX_LENGTH and nick[0] in VALID_IRC_NICK_FIRST_CHARS:
- for x in nick[1:]:
- if x not in VALID_IRC_NICK_CHARS:
- return 0
- return 1
- else: return 0
-
class IRCUser(object):
def __init__(self, stream, address):
self.stream = stream
@@ -252,3 +244,11 @@
self.registered = True
self.password = ''
self.recv_pass = ''
+
+ def valid_nick(self, nick):
+ if len(nick) <= NICK_MAX_LENGTH and nick[0] in VALID_IRC_NICK_FIRST_CHARS:
+ for x in nick[1:]:
+ if x not in VALID_IRC_NICK_CHARS:
+ return 0
+ return 1
+ else: return 0