Added quit/shutdown call to RPC/core

This commit is contained in:
dave 2014-10-12 21:33:10 -07:00
parent f0a495161b
commit f1a7d54208
2 changed files with 28 additions and 4 deletions

View File

@ -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,7 +125,7 @@ class PyIRCBot(asynchat.async_chat):
self.log.debug("handle_close")
self.connected=False
self.close()
if self.alive:
self.log.warning("Connection was lost. Reconnecting in 5 seconds.")
time.sleep(5)
self._connect()
@ -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)

View File

@ -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()
@ -144,3 +145,12 @@ class BotRPC(Thread):
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")