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:
return func
return realhook
- def hook(self, cmd=None, needchan=True, glevel=ANYONE, clevel=PUBLIC):
+ def hook(self, cmd=None, needchan=True, glevel=ANYONE, clevel=PUBLIC, wantchan=None):
+ if wantchan is None: wantchan = needchan
_cmd = cmd #save this since it gets wiped out...
def realhook(func):
cmd = _cmd #...and restore it
cmd = (cmd,)
func.needchan = needchan
+ func.wantchan = wantchan
func.reqglevel = glevel
func.reqclevel = clevel
func.cmd = cmd