5
""" dispatch web request onto the plugins dispatcher """
7
__copyright__ = 'this file is in the public domain'
9
from gozerbot.generic import waitforqueue, handle_exception
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 urllib import unquote_plus
18
def handle_dispatch(event):
19
""" dispatch web request """
20
input = unquote_plus(event.path)
21
bot = fleet.getfirstbot()
24
what = input.split('?', 1)[1]
26
return ["dispatch what ?", ]
27
if what.startswith("command="):
31
ievent.userhost = 'web@web'
32
ievent.channel = 'web'
34
ievent.queues.append(q)
38
if plugins.woulddispatch(bot, ievent):
39
start_new_thread(plugins.trydispatch, (bot, ievent))
41
return ["can't dispatch %s" % what, ]
42
result = waitforqueue(q, 60)
44
return ["can't dispatch %s" % what, ]
48
httpd.addhandler('dispatch', handle_dispatch)