def testasync(self, txt, timeout=0, kw={}): """ run txt with test ievent. don't close queues on exit.""" txt = txt.strip() ievent = Ircevent() ievent.bot = self ievent.cmnd = 'PRIVMSG' ievent.nick = 'test' ievent.userhost = 'test@test' ievent.origtxt = txt ievent.txt = ievent.origtxt ievent.channel = '#test' ievent.allowqueue = False ievent.closequeue = False if kw: for i, j in kw.iteritems(): setattr(ievent, i, j) if timeout: result = plugins.cmnd(self, ievent, timeout) else: result = plugins.cmnd(self, ievent, 10) rlog(100, self.name, str(result)) return result
def handle_timer(bot, ievent): """ do a timing of a command """ if not ievent.rest: ievent.reply('<cmnd>') return ievent.txt = ievent.rest starttime = time.time() result = plugins.cmnd(bot, ievent, 60) stoptime = time.time() if not result: ievent.reply('no result for %s' % ievent.rest) return result.insert(0, "%s seconds ==>" % str(stoptime-starttime)) ievent.reply('timer results: ', result)
def handle_timer(bot, ievent): """ do a timing of a command """ if not ievent.rest: ievent.reply("<cmnd>") return ievent.txt = ievent.rest starttime = time.time() result = plugins.cmnd(bot, ievent, 60) stoptime = time.time() if not result: ievent.reply("no result for %s" % ievent.rest) return result.insert(0, "%s seconds ==>" % str(stoptime - starttime)) ievent.reply("timer results: ", result)
def run(self, bot, event): """ run the test on bot with event. """ if config['loadlist'] and self.plugin not in config['loadlist']: return bot.userhosts['bottest'] = 'bottest@test' bot.userhosts['mtest'] = 'mekker@test' self.error = "" self.response = "" self.groups = [] origexec = self.execstring origexpect = self.expect if self.fakein: bot.fakein(self.fakein) return self if self.prev and self.prev.groups: try: execstring = self.execstring % self.prev.groups self.execstring = execstring except TypeError: pass try: expect = self.expect % self.prev.groups self.expect = expect except TypeError: pass self.execstring = self.execstring.replace('{{ me }}', event.nick) event.txt = event.origtxt = str(self.execstring) from gozerbot.plugins import plugins self.response = plugins.cmnd(bot, event) if self.response and self.expect: self.expect = self.expect.replace('{{ me }}', event.nick) regex = re.compile(self.expect) result = regex.search(str(self.response)) if not result: self.error = 'invalid response' else: self.groups = result.groups() or self.prev and self.prev.groups self.execstring = origexec self.expect = origexpect return self
def handle_inform(bot, ievent): """ prepend nick: to the output of command to another user """ if ievent.msg: ievent.reply('inform can only be used in a channel') return try: nick, cmnd = ievent.rest.split(' ', 1) except ValueError: ievent.missing('<nick> <command>') return ievent.txt = cmnd result = plugins.cmnd(bot, ievent) if not result: ievent.reply("no result for %s" % cmnd) return ievent.reply("%s: " % nick, result, dot=True)
def handle_tell(bot, ievent): """ send output of command to another user """ if ievent.msg: ievent.reply('tell can only be used in a channel') return try: nick, cmnd = ievent.rest.split(' ', 1) except ValueError: ievent.missing('<nick> <command>') return ievent.txt = cmnd #if not plugins.woulddispatch(bot, ievent): # ievent.reply("can't execute %s" % cmnd) # return result = plugins.cmnd(bot, ievent) if not result: ievent.reply("no result for %s" % cmnd) return ievent.reply("%s sends your this: " % ievent.nick, result, nick=nick, \ dot=True) ievent.reply("%s item(s) send" % len(result))