~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to debian/gozerbot/usr/lib/python2.5/site-packages/gozerplugs/web/direct.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2009-09-14 09:00:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914090029-uval0ekt72kmklxw
Tags: 0.9.1.3-3
Changed dependency on python-setuptools to python-pkg-resources
(Closes: #546435) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# web/dispatch.py
2
 
#
3
 
#
4
 
 
5
 
""" dispatch web request onto the plugins dispatcher """
6
 
 
7
 
__copyright__ = 'this file is in the public domain'
8
 
 
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
16
 
import Queue
17
 
 
18
 
def handle_dispatch(event):
19
 
    """ dispatch web request """
20
 
    input = unquote_plus(event.path)
21
 
    bot = fleet.getfirstbot()
22
 
    ievent = Ircevent()
23
 
    try:
24
 
        what = input.split('?', 1)[1]
25
 
    except IndexError:
26
 
        return ["dispatch what ?", ]
27
 
    if what.startswith("command="):
28
 
        what = what[8:]
29
 
    ievent.txt = what
30
 
    ievent.nick = 'web'
31
 
    ievent.userhost = 'web@web'
32
 
    ievent.channel = 'web'
33
 
    q = Queue.Queue()
34
 
    ievent.queues.append(q)
35
 
    ievent.speed = 3
36
 
    ievent.bot = bot
37
 
    result = []
38
 
    if plugins.woulddispatch(bot, ievent):
39
 
        start_new_thread(plugins.trydispatch, (bot, ievent))
40
 
    else:
41
 
        return ["can't dispatch %s" % what, ]
42
 
    result = waitforqueue(q, 60)
43
 
    if not result:
44
 
        return ["can't dispatch %s" % what, ]
45
 
    return result
46
 
 
47
 
if httpd:
48
 
    httpd.addhandler('dispatch', handle_dispatch)