Fixed the authentication

This commit is contained in:
Darks 2022-12-14 23:17:55 +01:00
parent f77f92213d
commit 1b218e3adf
2 changed files with 16 additions and 6 deletions

18
irc.py
View File

@ -27,7 +27,8 @@ class IRC(object):
# Public methods
def start(self, nick, password, sasl_nick=None):
""" Start the IRC layer. Manage authentication as well """
""" Start the IRC layer. Manage authentication as well
Return True if authentication succeed, False if failed"""
sasl_nick = sasl_nick or nick
self.nick = nick
self.running = True
@ -37,10 +38,19 @@ class IRC(object):
self._send(f"USER {nick} * * :{nick}")
self._send(f"NICK {nick}")
self._waitfor(lambda m: "NOTICE" in m and "/AUTH" in m)
self._send(f"AUTH {sasl_nick}:{password}")
self._waitfor(lambda m: "You are now logged in" in m)
self.connected = True
for i in range(3):
self._send(f"AUTH {sasl_nick}:{password}")
msg = self._waitfor(lambda m: "You are now logged in" in m or "Authentication failed" in m)
if "You are now logged in" in msg:
self.connected = True
return True
logging.info(f"Authentication for {nick} ({sasl_nick}) failed")
self.connected = False
self._handler.stop()
return False
def stop(self):
""" Stop the IRC layer """

View File

@ -106,8 +106,8 @@ class Shoutbox(object):
datetime.datetime.now()
]
# Start a thread for new client
self.irc_clients[author][0].start(f"{author}[s]", password, nick)
logging.debug(f"{author} has joined IRC")
if self.irc_clients[author][0].start(f"{author}[s]", password, nick):
logging.debug(f"{author} has joined IRC")
# client is known but AFK
else:
self.irc_clients[author][1] = datetime.datetime.now()