5
""" dispatch web request onto the plugins dispatcher .. return json data """
7
__copyright__ = 'this file is in the public domain'
9
from gozerbot.generic import waitforqueue, handle_exception, rlog
10
from gozerbot.fleet import fleet
11
from gozerbot.ircevent import Ircevent
12
from gozerbot.plugins import plugins
13
from gozerbot.thr import start_new_thread
14
from gozerplugs.plugs.webserver import httpd
15
from gozerbot.contrib.simplejson import dumps
16
from urllib import unquote_plus
19
def handle_json(event):
20
""" dispatch web request .. return json """
21
input = unquote_plus(event.path)
22
bot = fleet.getfirstbot()
25
what = input.split('?', 1)[1]
27
return ["dispatch what ?", ]
28
if what.startswith("command="):
32
ievent.userhost = 'web@web'
33
ievent.channel = 'web'
35
ievent.queues.append(q)
39
if plugins.woulddispatch(bot, ievent):
40
start_new_thread(plugins.trydispatch, (bot, ievent))
42
return ["can't dispatch %s" % ievent.txt, ]
43
result = waitforqueue(q, 3)
44
rlog(10, 'json', str(result))
53
httpd.addhandler('json', handle_json)