Glob2Chan: Add HTTP callback for the YOG server.
parent
9d7dbfff9a
commit
d434bb3f80
|
@ -29,14 +29,59 @@
|
|||
###
|
||||
|
||||
import supybot.utils as utils
|
||||
import supybot.world as world
|
||||
from supybot.commands import *
|
||||
import supybot.plugins as plugins
|
||||
import supybot.ircmsgs as ircmsgs
|
||||
import supybot.ircutils as ircutils
|
||||
import supybot.callbacks as callbacks
|
||||
import supybot.httpserver as httpserver
|
||||
|
||||
class Glob2ChanCallback(httpserver.SupyHTTPServerCallback):
|
||||
name = "Glob2 server notifications"
|
||||
defaultResponse = """
|
||||
You shouldn't be there, this subfolder is not for you. Go back to the
|
||||
index and try out other plugins (if any)."""
|
||||
def doGet(self, handler, path):
|
||||
host = handler.address_string()
|
||||
if host == 'localhost':
|
||||
assert path.startswith('/status/')
|
||||
status = path[len('/status/'):].replace('/', ' ')
|
||||
self.plugin._announce(ircutils.bold('[YOG]') +
|
||||
' YOG server at %s is %s.' % (host, status))
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/plain')
|
||||
self.end_headers()
|
||||
self.wfile.write('Channel notified.')
|
||||
else:
|
||||
self.send_response(403)
|
||||
self.send_header('Content-type', 'text/plain')
|
||||
self.end_headers()
|
||||
self.wfile.write('Not authorized.')
|
||||
|
||||
instance = None
|
||||
|
||||
class Glob2Chan(callbacks.Plugin):
|
||||
def __init__(self, irc):
|
||||
global instance
|
||||
self.__parent = super(Glob2Chan, self)
|
||||
callbacks.Plugin.__init__(self, irc)
|
||||
instance = self
|
||||
|
||||
callback = Glob2ChanCallback()
|
||||
callback.plugin = self
|
||||
httpserver.hook('glob2', callback)
|
||||
def die(self):
|
||||
self.__parent.die()
|
||||
httpserver.unhook('glob2')
|
||||
|
||||
def _announce(self, message):
|
||||
for irc in world.ircs:
|
||||
if '#glob2' in irc.state.channels:
|
||||
break
|
||||
assert '#glob2' in irc.state.channels
|
||||
irc.queueMsg(ircmsgs.privmsg('#glob2', message))
|
||||
|
||||
def doJoin(self, irc, msg):
|
||||
channel = msg.args[0]
|
||||
if channel != '#glob2':
|
||||
|
|
Loading…
Reference in New Issue