def emit(self, event, *p, **kw): """es.emit(str, ...) Throws the event and calls the callbacks for it. Any additional parameters are passed to the callbacks. """ try: calls = self.__calls[event] except KeyError: return for func, thread in calls.items(): if thread: startdaemon(func, self, *p, **kw) else: try: func(self, *p, **kw) except KeyboardInterrupt: raise except: print >> sys.stderr, "Error in event %s, ignored" % event traceback.print_exc()
def dispatch(self, origin, args): bytes, event, args = args[0], args[1], args[2:] text = decode(bytes) if os.environ.get('SHOW_DISPATCH'): print "Dispatch: %r %r %r %r" % (event, args, origin, text) # File away activity if event in ('PRIVMSG', 'NOTICE'): #args[0] is the origin of the message as reported by IRC self.activity[args[0]] = (time.time(), origin) for priority in ('high', 'medium', 'low'): items = self.commands[priority].items() for regexp, funcs in items: for func in funcs: if event != func.event: continue match = regexp.match(text) if match: if self.limit(origin, func): print "Limited!" continue phenny = self.wrapped(origin, text, match) input = self.input(origin, text, bytes, match, event, args) if func.thread: startdaemon(self.call, func, origin, phenny, input) else: self.call(func, origin, phenny, input) for source in [origin.sender, origin.nick]: # XXX: Should this be moved to a service module? try: self.stats[(func.name, source)] += 1 except KeyError: self.stats[(func.name, source)] = 1
def dispatch(self, origin, args): bytes, event, args = args[0], args[1], args[2:] text = decode(bytes) if os.environ.get("SHOW_DISPATCH"): print "Dispatch: %r %r %r %r" % (event, args, origin, text) # File away activity if event in ("PRIVMSG", "NOTICE"): # args[0] is the origin of the message as reported by IRC self.activity[args[0]] = (time.time(), origin) for priority in ("high", "medium", "low"): items = self.commands[priority].items() for regexp, funcs in items: for func in funcs: if event != func.event: continue match = regexp.match(text) if match: if self.limit(origin, func): print "Limited!" continue phenny = self.wrapped(origin, text, match) input = self.input(origin, text, bytes, match, event, args) if func.thread: startdaemon(self.call, func, origin, phenny, input) else: self.call(func, origin, phenny, input) for source in [origin.sender, origin.nick]: # XXX: Should this be moved to a service module? try: self.stats[(func.name, source)] += 1 except KeyError: self.stats[(func.name, source)] = 1