def onmessage(self, msg): Irc.onmessage(self, msg) # chan = message's channel or None chan = getattr(msg, "target", None) if chan and not ischannel(chan): chan = None # get a list of handlers handlers = list(self._get_handlers(chan)) iscommand = lambda word: any(word in handler for handler in handlers) # command = "title" for Privmsgs with "♥title" / "bot: title" / pm "title" # command = 123 for Numerics command = None if type(msg) is Privmsg and len(msg): first = msg[0] if msg.tomyself: if iscommand(first): # "cmd hello" in private command = msg.command = first msg.splitmsg = msg.splitmsg[1:] elif first[0] == conf.get("prefix", tag=self.tag, chan=chan): if iscommand(first[1:]): # "♥cmd hello" in #chan command = msg.command = first[1:] msg.splitmsg = msg.splitmsg[1:] elif len(msg) > 1 and first[:-1] == self.me[0] and first[-1] in (",", ":"): if iscommand(msg[1]): # "bot: hello" in #chan command = msg.command = msg[1] msg.splitmsg = msg.splitmsg[2:] elif type(msg) is Numeric: command = msg.num # assemble the list of functions that are to be run # together with their arguments funcs = [] for handler in handlers: for mtype in reversed(msg.__class__.__mro__[:-1]): if mtype in handler: funcs.append((handler[mtype], None)) if command and command in handler: funcs.append((handler[command], chan)) # sort functions according to their priority # and launch them funcs.sort(key=lambda tu: tu[0].priority) try: for func, chan in funcs: self._onmessage(func, msg, chan) except HaltMessage as e: self.onexception(e) return