have all modules run a shutdown() when quitting, use it to have MegaHAL close the brain

This commit is contained in:
Brian S. Stephan 2010-12-24 10:41:12 -06:00
parent cb54abf2b8
commit f590daf5cd
3 changed files with 16 additions and 0 deletions

View File

@ -92,6 +92,13 @@ class Module(object):
self.server.remove_global_handler('pubmsg', self.on_pubmsg)
self.server.remove_global_handler('privmsg', self.on_privmsg)
def shutdown(self):
"""
Do pre-deletion type cleanup.
Implement this to close databases, write to disk, etc.
"""
def on_pubmsg(self, connection, event):
"""
Handle pubmsg events. Does some variable setup and initial sanity checking before

View File

@ -105,6 +105,9 @@ class IrcAdmin(Module):
def sub_quit_irc(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
whats = what.split(' ')
for module in self.modlist:
module.shutdown()
if replypath is not None:
connection.privmsg(replypath, 'Quitting...')
connection.quit(' '.join(whats[1:]))

View File

@ -41,6 +41,12 @@ class MegaHAL(Module):
except NoOptionError:
self.megahal = megahal.MegaHAL()
def shutdown(self):
"""
Close the megahal brain.
"""
self.megahal.close()
def reload(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
"""
Broken. Don't do anything.