+ if target == self.nick:
+ if msg.startswith("\001"): #ctcp
+ msg = msg.strip("\001")
+ if msg == "VERSION":
+ self.msg(user, "\001VERSION Erebus v%d.%d - http://github.com/zonidjan/erebus" % (self.parent.APIVERSION, self.parent.RELEASE))
+ return
+
+ if target != self.nick: # message was sent to a channel
+ 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
+ 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 or callback.wantchan):
+ chan = chanparam
+ pieces.pop(1)
+ if chan is None and callback.needchan:
+ rancmd = True
+ self.msg(user, "You need to specify a channel for that command.")
+ elif user.glevel >= callback.reqglevel and (not callback.needchan or chan.levelof(user.auth) >= callback.reqclevel):
+ rancmd = True
+ try:
+ cbret = callback(self, user, chan, target, *pieces[1:])
+ except NotImplementedError:
+ self.msg(user, "Command not implemented.")
+ except Exception:
+ self.msg(user, "Command failed. Code: CBEXC%09.3f" % (time.time() % 100000))
+ self.__debug_cbexception("hook", user=user, target=target, msg=msg)
+ except SystemExit as e:
+ curs = self.parent.db.cursor()
+ curs.execute("UPDATE bots SET connected = 0")
+ curs.close()
+ raise e
+ else:
+ rancmd = True
+ self.msg(user, "I don't know that command.")
+ if not rancmd:
+ self.msg(user, "You don't have enough access to run that command.")
+
+ def __debug_nomsg(self, target, msg):
+ if int(self.parent.cfg.get('debug', 'nomsg', default=0)) == 1:
+ self.conn.send("PRIVMSG %s :%09.3f \ 34\1f!!! NOMSG\1f\ 3 %r, %r" % (self.parent.cfg.get('debug', 'owner'), time.time() % 100000, target, msg))
+ self.log('!', "!!! NOMSG")
+# print "%09.3f %s [!] %s" % (time.time() % 100000, self.nick, "!!! NOMSG")
+ __import__('traceback').print_stack()