home · contact · privacy
Simplify _NickUserHost comparisons.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 5 Sep 2025 12:45:22 +0000 (14:45 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 5 Sep 2025 12:45:22 +0000 (14:45 +0200)
ircplom/client.py

index e11b1e773ac60cfe91010aa284d7d68b709a53a2..e36f46102c9a19a52b2622a7179163250f872a18 100644 (file)
@@ -392,14 +392,6 @@ class _Channel:
 
 class _NickUserHost(NickUserHost):
 
-    def __eq__(self, other) -> bool:
-        if not isinstance(other, NickUserHost):
-            return False
-        for key in NickUserHost.__annotations__:
-            if getattr(self, key) != getattr(other, key):
-                return False
-        return True
-
     def __setattr__(self, key: str, value: NickUserHost | str) -> None:
         if key == 'nickuserhost' and isinstance(value, _NickUserHost):
             for annotated_key in NickUserHost.__annotations__:
@@ -714,8 +706,10 @@ class Client(ABC, ClientQueueMixin):
         if '_verb' not in ret:
             self._log(f'PLEASE IMPLEMENT HANDLER FOR: {msg.raw}')
             return
-        for nickuserhost in ret['_nickuserhosts']:
-            self.db.userid_for_nickuserhost(nickuserhost, allow_none=True)
+        for nuh in ret['_nickuserhosts']:  # update, ensure identities
+            if (id_ := self.db.userid_for_nickuserhost(nuh, allow_none=True)):
+                for ret_name in [k for k in ret if ret[k] is nuh]:
+                    ret[ret_name] = self.db.users[id_]
         for verb in ('setattr', 'do', 'doafter'):
             for task, tok_names in [t for t in ret['_tasks'].items()
                                     if t[0].verb == verb]:
@@ -769,8 +763,7 @@ class Client(ABC, ClientQueueMixin):
                     self.send(IrcMessage('AUTHENTICATE', ('PLAIN',)))
                 else:
                     self.caps.end_negotiation()
-        elif ret['_verb'] == 'JOIN'\
-                and ret['joiner'].nick != self.db.users['me'].nick:
+        elif ret['_verb'] == 'JOIN' and ret['joiner'] != self.db.users['me']:
             self.db.channels[ret['channel']].append_nick(ret['joiner'])
         elif ret['_verb'] == 'NICK':
             user_id = self.db.userid_for_nickuserhost(ret['named'])