def handle_dispatch(event): """ dispatch web request """ input = unquote_plus(event.path) bot = fleet.getfirstbot() ievent = Ircevent() try: what = input.split('?', 1)[1] except IndexError: return [ "dispatch what ?", ] if what.startswith("command="): what = what[8:] ievent.txt = what ievent.nick = 'web' ievent.userhost = 'web@web' ievent.channel = 'web' q = Queue.Queue() ievent.queues.append(q) ievent.speed = 3 ievent.bot = bot result = [] if plugins.woulddispatch(bot, ievent): start_new_thread(plugins.trydispatch, (bot, ievent)) else: return [ "can't dispatch %s" % what, ] result = waitforqueue(q, 60) if not result: return [ "can't dispatch %s" % what, ] return result
def handle_dispatch(event): """ dispatch web request """ input = unquote_plus(event.path) bot = fleet.getfirstbot() ievent = Ircevent() try: what = input.split('?', 1)[1] except IndexError: return ["dispatch what ?", ] if what.startswith("command="): what = what[8:] ievent.txt = what ievent.nick = 'web' ievent.userhost = 'web@web' ievent.channel = 'web' q = Queue.Queue() ievent.queues.append(q) ievent.speed = 3 ievent.bot = bot result = [] if plugins.woulddispatch(bot, ievent): start_new_thread(plugins.trydispatch, (bot, ievent)) else: return ["can't dispatch %s" % what, ] result = waitforqueue(q, 60) if not result: return ["can't dispatch %s" % what, ] return result
def handle_json(event): """ dispatch web request .. return json """ input = unquote_plus(event.path) bot = fleet.getfirstbot() ievent = Ircevent() try: what = input.split('?', 1)[1] except IndexError: return ["dispatch what ?", ] if what.startswith("command="): what = what[8:] ievent.txt = what ievent.nick = 'web' ievent.userhost = 'web@web' ievent.channel = 'web' q = Queue.Queue() ievent.queues.append(q) ievent.speed = 3 ievent.bot = bot result = [] if plugins.woulddispatch(bot, ievent): start_new_thread(plugins.trydispatch, (bot, ievent)) else: return ["can't dispatch %s" % ievent.txt, ] result = waitforqueue(q, 3) rlog(10, 'json', str(result)) try: res = dumps(result) except Exception, ex: handle_exception() res = []
def dispatch_POST(server, request): """ dispatch request into the cloud """ try: (host, port) = request.client_address except: return [ "can't determine host/port", ] try: input = getpostdata(request) cmnd = input['cmnd'] except KeyError: return dumps([ 'need cmnd value', ]) try: channel = input['channel'] except KeyError: channel = "#cloud" if not channel: channel = '#cloud' bot = fleet.getfirstbot() ievent = Ircevent() ievent.txt = cmnd ievent.nick = 'cloud' ievent.userhost = "cloud@%s" % host ievent.channel = channel q = Queue.Queue() ievent.queues.append(q) ievent.speed = 3 ievent.bot = bot result = [] if plugins.woulddispatch(bot, ievent): start_new_thread(plugins.trydispatch, (bot, ievent)) else: return dumps([ "can't dispatch %s" % cmnd, ]) result = waitforqueue(q, 10) if not result: return dumps([ "no result", ]) res = [] for item in result: res.append(str(item)) return dumps(res)
def handle_at(bot, ievent): """ start a job at a certain time. """ if len(ievent.args) < 2: ievent.missing('<time> <command>') return nevent = Ircevent() nevent.copyin(ievent) nevent.txt = ' '.join(ievent.args[1:]) nevent.origtxt = u'!' + nevent.txt if plugins.woulddispatch(bot, nevent): try: when = int(ievent.args[0]) except ValueError, e: when = ievent.args[0] try: AtJob(when, bot, nevent) except JobError: ievent.reply('wrong date/time') return ievent.reply('job scheduled')
def dispatch_POST(server, request): """ dispatch request into the cloud """ try: (host, port) = request.client_address except: return ["can't determine host/port", ] try: input = getpostdata(request) cmnd = input['cmnd'] except KeyError: return dumps(['need cmnd value', ]) try: channel = input['channel'] except KeyError: channel = "#cloud" if not channel: channel = '#cloud' bot = fleet.getfirstbot() ievent = Ircevent() ievent.txt = cmnd ievent.nick = 'cloud' ievent.userhost = "cloud@%s" % host ievent.channel = channel q = Queue.Queue() ievent.queues.append(q) ievent.speed = 3 ievent.bot = bot result = [] if plugins.woulddispatch(bot, ievent): start_new_thread(plugins.trydispatch, (bot, ievent)) else: return dumps(["can't dispatch %s" % cmnd, ]) result = waitforqueue(q, 10) if not result: return dumps(["no result", ]) res = [] for item in result: res.append(str(item)) return dumps(res)
continue skip = False for dont in donot: if dont in example: skip = True if skip: continue if bot.jabber: from gozerbot.jabber.jabbermsg import Jabbermsg newmessage = Jabbermsg(msg.orig) newmessage.copyin(msg) newmessage.txt = '!' + example msg.reply('command: ' + example) bot.domsg(newmessage) else: newmessage = Ircevent(msg.orig) newmessage.copyin(msg) newmessage.txt = '!' + example msg.reply('command: ' + example) bot.domsg(newmessage) try: time.sleep(int(msg.options['--sleep'])) except (KeyError, ValueError): pass gozerbot.utils.url.geturl = oldgeturl gozerbot.utils.url.geturl2 = oldgeturl2 gozerbot.generic.geturl = oldgeturl gozerbot.generic.geturl2 = oldgeturl2 cmnds.add('test-plugs',