home · contact · privacy
Further reduce unwieldy .handle_msg.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 17 Aug 2025 16:00:26 +0000 (18:00 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 17 Aug 2025 16:00:26 +0000 (18:00 +0200)
ircplom/client.py
ircplom/client_tui.py

index b45dabe5a1b49d5be01bba2bcb92dbca796f0ea4..9f166be442d913210a29bca5175ed9638445c016 100644 (file)
@@ -379,6 +379,7 @@ class _ClientDb(_Db, IrcConnSetup):
     isupports: _UpdatingDict
     nickname_confirmed: bool
     user_modes: str
+    sasl_auth_state: str
     _completable_motd: _CompletableStringsList
     _channels: dict[str, _ChannelDb]
 
@@ -490,6 +491,7 @@ class Client(ABC, ClientQueueMixin):
         self.conn = None
         self._db.isupports.clear()
         self._db.nickname_confirmed = False
+        self._db.sasl_auth_state = ''
 
     def on_handled_loop_exception(self, e: IrcConnAbortException) -> None:
         'Gracefully handle broken connection.'
@@ -518,27 +520,24 @@ class Client(ABC, ClientQueueMixin):
             # '@'-split because <https://defs.ircdocs.horse/defs/numerics>
             # claims: "<hostname> can also be in the form <user@hostname>"
             self._db.client_host = msg.params[1].split('@')[-1]
-        elif msg.match('903', 2):  # RPL_SASLSUCESS
-            self._log('SASL auth succeeded')
-            self._caps.end_negotiation()
-        elif msg.match('904', 2):  # ERR_SASLFAIL
-            self._log('SASL auth failed', alert=True)
-            self._caps.end_negotiation()
+        elif msg.match('903', 2) or msg.match('904', 2):  # RPL_SUCESS, or …
+            self._db.sasl_auth_state = 'WIN' if msg.verb == '903' else 'FAIL'
+            self._caps.end_negotiation()                  # … ERR_SASLFAIL
         elif msg.match('AUTHENTICATE') and msg.params[0] == '+':
             auth = b64encode((self._db.nickname + '\0'
                               + self._db.nickname + '\0'
                               + self._db.password
                               ).encode('utf-8')).decode('utf-8')
             self.send(IrcMessage('AUTHENTICATE', (auth,)))
-        elif msg.match('CAP', len_is_min=True)\
-                and self._caps.process_msg(msg.params[1:])\
-                and self._db.caps.has('sasl')\
-                and 'PLAIN' in self._db.caps['sasl'].data.split(','):
-            if self._db.password:
-                self._log('trying to authenticate via SASL/plain')
-                self.send(IrcMessage('AUTHENTICATE', ('PLAIN',)))
-            else:
-                self._caps.end_negotiation()
+        elif msg.match('CAP', len_is_min=True):
+            if (self._caps.process_msg(msg.params[1:])
+                    and self._db.caps.has('sasl')
+                    and 'PLAIN' in self._db.caps['sasl'].data.split(',')):
+                if self._db.password:
+                    self._db.sasl_auth_state = 'attempting'
+                    self.send(IrcMessage('AUTHENTICATE', ('PLAIN',)))
+                else:
+                    self._caps.end_negotiation()
         elif msg.match('ERROR'):
             self.close()
         elif msg.match('MODE', 2) and msg.params[0] == self._db.nickname:
index f82535dfb3eb88434371a26126205a23d1692d6f..f0fbd3f5a213e033fdae5f65d6bf82bb06db6f21 100644 (file)
@@ -177,6 +177,7 @@ class _TuiClientDb(_Db, IrcConnSetup):
     isupports: dict[str, str]
     motd: tuple[str]
     nickname_confirmed: bool
+    sasl_auth_state: str
     user_modes: str
     _channels: dict[str, _ChannelDb]