diff --git a/modules/IrcAdmin.py b/modules/IrcAdmin.py index 95ba396..2880087 100644 --- a/modules/IrcAdmin.py +++ b/modules/IrcAdmin.py @@ -81,6 +81,8 @@ class IrcAdmin(Module): return self.sub_load_module(connection, event, nick, userhost, replypath, what, admin_unlocked) elif whats[0] == 'reload' and admin_unlocked and len(whats) >= 2: return self.sub_reload_module(connection, event, nick, userhost, replypath, what, admin_unlocked) + elif whats[0] == 'unload' and admin_unlocked and len(whats) >= 2: + return self.sub_unload_module(connection, event, nick, userhost, replypath, what, admin_unlocked) def sub_join_channel(self, connection, event, nick, userhost, replypath, what, admin_unlocked): whats = what.split(' ') @@ -192,6 +194,27 @@ class IrcAdmin(Module): module.reload() return self.reply(connection, replypath, modname + ' reloaded.') + def sub_unload_module(self, connection, event, nick, userhost, replypath, what, admin_unlocked): + """ + Attempt to unload and del a module if it's loaded. + """ + + whats = what.split(' ') + + modname = whats[1] + for module in self.modlist: + if modname == module.__class__.__name__: + # remove module references + self.modlist.remove(module) + module.unregister_handlers() + + # del it + del module + return self.reply(connection, replypath, modname + ' unloaded.') + + # guess it was never loaded + return self.reply(connection, replypath, modname + ' is not loaded.') + # Save the config file. def save_config(self): with open('dr.botzo.cfg', 'w') as cfg: