]> jfr.im git - erebus.git/blobdiff - bot.py
help - remove debug prints
[erebus.git] / bot.py
diff --git a/bot.py b/bot.py
index d1eed6c6e43d6f20a7e16df7ee863d1e61faa5b7..11b7ac50636ccfeab7cc88b1b39a37d4fd1de03c 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -35,7 +35,7 @@ class Bot(object):
                self.conn = BotConnection(self, bind, server, port)
 
                self.lastreceived = time.time() #time we last received a line from the server
-               self.watchdogtimer = MyTimer(self.parent.cfg.get('watchdog', 'interval', default=30), self.watchdog)
+               self.watchdog()
 
                self.msgqueue = deque()
                self.slowmsgqueue = deque()
@@ -50,7 +50,7 @@ class Bot(object):
        def watchdog(self):
                if time.time() > self.parent.cfg.get('watchdog', 'maxtime', default=300)+self.lastreceived:
                        self.parse("ERROR :Fake-error from watchdog timer.")
-
+               self.watchdogtimer = MyTimer(self.parent.cfg.get('watchdog', 'interval', default=30), self.watchdog)
 
        def log(self, *args, **kwargs):
                self.parent.log(self.nick, *args, **kwargs)
@@ -270,37 +270,41 @@ class Bot(object):
                                if msg == "VERSION":
                                        self.msg(user, "\001VERSION Erebus v%d.%d - http://github.com/zonidjan/erebus" % (self.parent.APIVERSION, self.parent.RELEASE))
                                return
-               if len(pieces) > 1:
-                       chanword = pieces[1]
-                       if chanword.startswith('#'):
-                               chanparam = self.parent.channel(chanword)
 
                if target != self.nick: # message was sent to a channel
-                       chan = self.parent.channel(target)
                        try:
                                if msg.startswith('*'): # message may be addressed to bot by "*BOTNICK" trigger?
                                        if pieces[0][1:].lower() == self.nick.lower():
                                                pieces.pop(0) # command actually starts with next word
                                                msg = ' '.join(pieces) # command actually starts with next word
-                               elif not triggerused:
-                                       if self.parent.haschanhook(target.lower()):
-                                               for callback in self.parent.getchanhook(target.lower()):
-                                                       try:
-                                                               cbret = callback(self, user, chan, *pieces)
-                                                       except NotImplementedError:
-                                                               self.msg(user, "Command not implemented.")
-                                                       except:
-                                                               self.msg(user, "Command failed. Code: CBEXC%09.3f" % (time.time() % 100000))
-                                                               self.__debug_cbexception("chanhook", user=user, target=target, msg=msg)
-                                       return # not to bot, don't process!
+                                               triggerused = True
                        except IndexError:
                                return # "message" is empty
 
+               if len(pieces) > 1:
+                       chanword = pieces[1]
+                       if chanword.startswith('#'):
+                               chanparam = self.parent.channel(chanword)
+
+               if target != self.nick: # message was sent to a channel
+                       chan = self.parent.channel(target)
+                       if not triggerused:
+                               if self.parent.haschanhook(target.lower()):
+                                       for callback in self.parent.getchanhook(target.lower()):
+                                               try:
+                                                       cbret = callback(self, user, chan, *pieces)
+                                               except NotImplementedError:
+                                                       self.msg(user, "Command not implemented.")
+                                               except:
+                                                       self.msg(user, "Command failed. Code: CBEXC%09.3f" % (time.time() % 100000))
+                                                       self.__debug_cbexception("chanhook", user=user, target=target, msg=msg)
+                               return # not to bot, don't process!
+
                cmd = pieces[0].lower()
                rancmd = False
                if self.parent.hashook(cmd):
                        for callback in self.parent.gethook(cmd):
-                               if chanparam is not None and callback.needchan:
+                               if chanparam is not None and (callback.needchan or callback.wantchan):
                                        chan = chanparam
                                        pieces.pop(1)
                                if chan is None and callback.needchan: