Skip to content

Instantly share code, notes, and snippets.

@EntityReborn
Created June 2, 2011 15:55
Show Gist options
  • Save EntityReborn/1004677 to your computer and use it in GitHub Desktop.
Save EntityReborn/1004677 to your computer and use it in GitHub Desktop.
from socbot.pluginbase import Base
from twisted.application import internet
from twisted.web import resource, server
class Plugin(Base):
class Simple(resource.Resource):
isLeaf = True
def render_GET(self, request):
line = "<html><head><title>Ohai2</title></head><body>Hello, world 2!</body></html>"
self.log.info(line)
return line
def initialize(self, *args, **kwargs):
self.simple = self.Simple()
self.simple.log = self.log
self.site = server.Site(self.simple)
self.server = internet.TCPServer(8080, self.site)
self.startServer()
def startServer(self):
if self.server.running:
self.log.error("Tried to run again.")
return
self.server.startService()
def stopServer(self):
if not self.server.running:
self.log.error("Tried to stop what is already stopped.")
return
retn = self.server.stopService()
return retn
@Base.trigger("WEBDOWN")
def on_down(self, *args):
if self.server.running:
self.stopServer()
return True
return "Not running."
@Base.trigger("WEBUP")
def on_up(self, *args):
if not self.server.running:
self.startServer()
return True
return "Already running."
def disabling(self, *args, **kwargs):
if self.server.running:
return self.stopServer()
def beforeReload(self, *args, **kwargs):
if self.server.running:
return self.stopServer()
@EntityReborn
Copy link
Author

socbot.local - DEBUG - command `PRIVMSG`, from prefix `EntityReborn!Entity@rox-9B67C928`
pluginmanager - DEBUG - triggering 'PRIVMSG'
socbot.local - DEBUG - trigger: WEBDOWN
pluginmanager - DEBUG - triggering 'WEBDOWN'
socbot.local - DEBUG - sending line `PRIVMSG EntityReborn :Done.`
socbot.local - DEBUG - command `PRIVMSG`, from prefix `EntityReborn!Entity@rox-9B67C928`
pluginmanager - DEBUG - triggering 'PRIVMSG'
socbot.local - DEBUG - trigger: WEBDOWN
pluginmanager - DEBUG - triggering 'WEBDOWN'
socbot.local - DEBUG - sending line `PRIVMSG EntityReborn :Not running.`
socbot.local - DEBUG - command `PRIVMSG`, from prefix `EntityReborn!Entity@rox-9B67C928`
pluginmanager - DEBUG - triggering 'PRIVMSG'
socbot.local - DEBUG - trigger: WEBUP
pluginmanager - DEBUG - triggering 'WEBUP'
socbot.local - DEBUG - sending line `PRIVMSG EntityReborn :Done.`
plugins.website - INFO - <html><head><title>Ohai2</title></head><body>Hello, world 2!</body></html>
plugins.website - INFO - <html><head><title>Ohai2</title></head><body>Hello, world 2!</body></html>
socbot.local - DEBUG - command `PRIVMSG`, from prefix `EntityReborn!Entity@rox-9B67C928`
pluginmanager - DEBUG - triggering 'PRIVMSG'
socbot.local - DEBUG - trigger: WEBDOWN
pluginmanager - DEBUG - triggering 'WEBDOWN'
socbot.local - DEBUG - sending line `PRIVMSG EntityReborn :Done.`
plugins.website - INFO - <html><head><title>Ohai2</title></head><body>Hello, world 2!</body></html>
plugins.website - INFO - <html><head><title>Ohai2</title></head><body>Hello, world 2!</body></html>

@EntityReborn
Copy link
Author

socbot.local - DEBUG - command `PRIVMSG`, from prefix `EntityReborn!Entity@rox-9B67C928`
pluginmanager - DEBUG - triggering 'PRIVMSG'
socbot.local - DEBUG - trigger: WEBDOWN
pluginmanager - DEBUG - triggering 'WEBDOWN'
plugins.website - INFO - WEBDOWN called
plugins.website - INFO - Stopping server
socbot.local - DEBUG - sending line `PRIVMSG EntityReborn :Done.`

socbot.local - DEBUG - command `PRIVMSG`, from prefix `EntityReborn!Entity@rox-9B67C928`
pluginmanager - DEBUG - triggering 'PRIVMSG'
socbot.local - DEBUG - trigger: WEBUP
pluginmanager - DEBUG - triggering 'WEBUP'
plugins.website - INFO - WEBUP called
plugins.website - INFO - Starting server
socbot.local - DEBUG - sending line `PRIVMSG EntityReborn :Done.`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment