]> jfr.im git - erebus.git/commitdiff
bot - allow hooks for numerics/commands that get sent without source
authorJohn Runyon <redacted>
Fri, 16 Jun 2023 21:57:27 +0000 (15:57 -0600)
committerJohn Runyon <redacted>
Fri, 16 Jun 2023 21:57:27 +0000 (15:57 -0600)
bot.py

diff --git a/bot.py b/bot.py
index b92495dea253e709ccb5691c2b6733d20b18a46e..793e27f6b6c923ad162e0f70ee41317c105a40b1 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -92,13 +92,13 @@ class Bot(object):
                        self.log('I', line)
                pieces = line.split()
 
+               if pieces[0][0] == ":":
+                       numeric = pieces[1]
+               else:
+                       numeric = pieces[0]
+
                # dispatch dict
-               zero = { #things to look for without source
-                       'NOTICE': self._gotconnected,
-                       'PING': self._gotping,
-                       'ERROR': self._goterror,
-               }
-               one = { #things to look for after source
+               dispatch = { #things to look for after source
                        'NOTICE': self._gotconnected,
                        '001': self._got001,
                        '004': self._got004,
@@ -115,20 +115,20 @@ class Bot(object):
                        'QUIT': self._gotquit,
                        'NICK': self._gotnick,
                        'MODE': self._gotmode,
+                       'PING': self._gotping,
+                       'ERROR': self._goterror,
                }
 
-               if self.parent.hasnumhook(pieces[1]):
-                       hooks = self.parent.getnumhook(pieces[1])
+               if self.parent.hasnumhook(numeric):
+                       hooks = self.parent.getnumhook(numeric)
                        for callback in hooks:
                                try:
                                        callback(self, line)
                                except Exception:
                                        self.__debug_cbexception("numhook", line)
 
-               if pieces[0] in zero:
-                       zero[pieces[0]](pieces)
-               elif pieces[1] in one:
-                       one[pieces[1]](pieces)
+               if numeric in dispatch:
+                       dispatch[numeric](pieces)
 
        def _gotconnected(self, pieces):
                if not self.conn.registered():