def cmnd(self, bot, ievent, timeout=15): """ launch command and wait for result. """ ii = Ircevent(ievent) q = Queue.Queue() ii.queues.append(q) self.trydispatch(bot, ii) return waitforqueue(q, timeout)
def handle(self, bot, txt): """ fire outmonitor callbacks. """ ievent = Ircevent().parse(bot, txt) if not ievent: rlog(10, 'monitor', "can't make ircevent: %s" % txt) return ievent.nick = bot.nick try: ievent.userhost = bot.userhosts[bot.nick] except KeyError: ievent.userhost = "bot@bot" Monitor.handle(self, bot, ievent)
def multiple(self, bot, ievent): """ execute multiple commands. """ for i in ievent.txt.split(' && '): if not bot.jabber: ie = Ircevent() ie.copyin(ievent) else: from jabber.jabbermsg import Jabbermsg ie = Jabbermsg(ievent) ie.copyin(ievent) ie.txt = i.strip() self.trydispatch(bot, ie)
def splitpipe(self, bot, ievent): """ execute commands in a pipeline. """ origqueues = ievent.queues ievent.queues = [] events = [] txt = ievent.txt.replace(' || ', ' ##') # split commands for i in txt.split(' | '): item = i.replace(' ##', ' | ') if not ievent.jabber: ie = Ircevent() ie.copyin(ievent) else: from jabber.jabbermsg import Jabbermsg ie = Jabbermsg(ievent.orig) ie.copyin(ievent) ie.txt = item.strip() events.append(ie) # loop over events .. chain queues prevq = None for i in events[:-1]: q = Queue.Queue() i.queues.append(q) if prevq: i.inqueue = prevq prevq = q events[-1].inqueue = prevq if origqueues: events[-1].queues = origqueues # check if all commands would dispatch for i in events: if not self.woulddispatch(bot, i): ievent.reply("can't execute %s" % str(i.txt)) return # do the dispatch for i in events: (what, com) = self.dispatchtest(bot, i) if what: self.dispatch(what, com, bot, i)