Browse Source

Added quit/shutdown call to RPC/core

dave/xdcc
dave 8 years ago
parent
commit
f1a7d54208
  1. 22
      pyircbot/core/pyircbot.py
  2. 10
      pyircbot/core/rpc.py

22
pyircbot/core/pyircbot.py

@ -52,6 +52,9 @@ class PyIRCBot(asynchat.async_chat):
self.buffer = StringIO()
"""cSTringIO used as a buffer"""
self.alive = True
""" True if we should try to stay connected"""
# IRC Messages are terminated with \r\n
self.set_terminator(b"\r\n")
@ -81,6 +84,10 @@ class PyIRCBot(asynchat.async_chat):
#Close all modules
self.closeAllModules()
# Mark for shutdown
self.alive = False
# Exit
sys.exit(0)
" Net related code here on down "
@ -118,10 +125,10 @@ class PyIRCBot(asynchat.async_chat):
self.log.debug("handle_close")
self.connected=False
self.close()
self.log.warning("Connection was lost. Reconnecting in 5 seconds.")
time.sleep(5)
self._connect()
if self.alive:
self.log.warning("Connection was lost. Reconnecting in 5 seconds.")
time.sleep(5)
self._connect()
def handle_error(self, *args, **kwargs):
"""Called on fatal network errors."""
@ -652,3 +659,10 @@ class PyIRCBot(asynchat.async_chat):
:type comment: str"""
self.sendRaw("KICK %s %s :%s" % (channel, who, comment))
def act_QUIT(self, message):
"""Use the `/quit` command
:param message: quit message
:type message: str"""
self.sendRaw("QUIT :%s" % message)

10
pyircbot/core/rpc.py

@ -28,6 +28,7 @@ class BotRPC(Thread):
self.server.register_function( self.pluginCommand )
self.server.register_function( self.setPluginVar )
self.server.register_function( self.getPluginVar )
self.server.register_function( self.quit )
self.start()
@ -143,4 +144,13 @@ class BotRPC(Thread):
self.log.info("RPC: setting %s.%s = %s )" % (moduleName, moduleVarName, value))
setattr(plugin, moduleVarName, value)
return (True, "Var set")
def quit(self, message):
"""Tell the bot to quit IRC and exir
:param message: Quit message
:type moduleName: str"""
self.bot.act_QUIT(message)
self.bot.kill()
return (True, "Shutdown ordered")
Loading…
Cancel
Save