def on_message(self, server, event, private): """process incoming messages""" req = Request(message=event.arguments()[0]) req.nick = irclib.nm_to_n(event.source()) req.channel = event.target() req.private = private if private: req.sendTo = req.nick req.addressed = True else: req.sendTo = req.channel req.addressed = False # strip control codes from incoming lines req.message = self.colorlib.strip_color(req.message) # strip adressing and set req attributes self.checkAddressing(req) # lines that start with ^ will have their output rainbowed if req.message.startswith('^'): req.message = req.message[1:] req.colorize = True else: req.colorize = False # send to bot subsystem for processing self.process_message(req)
def response(self, nick, args, kwargs): testmod = args[0] results = {} for mod_name, obj in self.madcow.modules: if testmod is not None and mod_name != testmod: continue try: test = tests[mod_name] except: continue if not test: continue if isinstance(test, dict): test = [test] passed = True sys.stderr.write('testing %s ... ' % mod_name) for t in test: try: response = '' req = Request(message=t['request']) req.nick = 'test' req.channel = 'test' req.private = True req.sendTo = 'test' req.addressed = True req.colorize = False req.correction = True try: args = obj.pattern.search(req.message).groups() except: print "\n* args didn't match" passed = False break kwargs = {'req': req} kwargs.update(req.__dict__) response = obj.response(req.nick, args, kwargs) if isinstance(t['result'], str): if response != t['result']: passed = False print "\n* string object didn't match" break elif isinstance(t['result'], retype): if t['result'].search(response) is None: passed = False print "\n* regex didn't match" break except Exception, e: print "\n* exception: %s" % e passed = False if passed: sys.stderr.write('ok\r\n') else: sys.stderr.write('fail [%s]\r\n' % repr(response)) results[mod_name] = passed