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 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',