X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/2591a1c8caad59346f49712a3af24080557b6330..2b2ae2811cec8832a8d9c73e683e183206be283c:/bot.py diff --git a/bot.py b/bot.py index d1eed6c..11b7ac5 100644 --- 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: