Added quit/shutdown call to RPC/core
This commit is contained in:
parent
f0a495161b
commit
f1a7d54208
|
@ -52,6 +52,9 @@ class PyIRCBot(asynchat.async_chat):
|
||||||
self.buffer = StringIO()
|
self.buffer = StringIO()
|
||||||
"""cSTringIO used as a buffer"""
|
"""cSTringIO used as a buffer"""
|
||||||
|
|
||||||
|
self.alive = True
|
||||||
|
""" True if we should try to stay connected"""
|
||||||
|
|
||||||
# IRC Messages are terminated with \r\n
|
# IRC Messages are terminated with \r\n
|
||||||
self.set_terminator(b"\r\n")
|
self.set_terminator(b"\r\n")
|
||||||
|
|
||||||
|
@ -81,6 +84,10 @@ class PyIRCBot(asynchat.async_chat):
|
||||||
|
|
||||||
#Close all modules
|
#Close all modules
|
||||||
self.closeAllModules()
|
self.closeAllModules()
|
||||||
|
# Mark for shutdown
|
||||||
|
self.alive = False
|
||||||
|
# Exit
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
" Net related code here on down "
|
" Net related code here on down "
|
||||||
|
|
||||||
|
@ -118,10 +125,10 @@ class PyIRCBot(asynchat.async_chat):
|
||||||
self.log.debug("handle_close")
|
self.log.debug("handle_close")
|
||||||
self.connected=False
|
self.connected=False
|
||||||
self.close()
|
self.close()
|
||||||
|
if self.alive:
|
||||||
self.log.warning("Connection was lost. Reconnecting in 5 seconds.")
|
self.log.warning("Connection was lost. Reconnecting in 5 seconds.")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
self._connect()
|
self._connect()
|
||||||
|
|
||||||
def handle_error(self, *args, **kwargs):
|
def handle_error(self, *args, **kwargs):
|
||||||
"""Called on fatal network errors."""
|
"""Called on fatal network errors."""
|
||||||
|
@ -652,3 +659,10 @@ class PyIRCBot(asynchat.async_chat):
|
||||||
:type comment: str"""
|
:type comment: str"""
|
||||||
self.sendRaw("KICK %s %s :%s" % (channel, who, comment))
|
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)
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ class BotRPC(Thread):
|
||||||
self.server.register_function( self.pluginCommand )
|
self.server.register_function( self.pluginCommand )
|
||||||
self.server.register_function( self.setPluginVar )
|
self.server.register_function( self.setPluginVar )
|
||||||
self.server.register_function( self.getPluginVar )
|
self.server.register_function( self.getPluginVar )
|
||||||
|
self.server.register_function( self.quit )
|
||||||
|
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
|
@ -144,3 +145,12 @@ class BotRPC(Thread):
|
||||||
setattr(plugin, moduleVarName, value)
|
setattr(plugin, moduleVarName, value)
|
||||||
return (True, "Var set")
|
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…
Reference in New Issue