diff --git a/modules/IrcAdmin.py b/modules/IrcAdmin.py index aa9b76a..95ba396 100644 --- a/modules/IrcAdmin.py +++ b/modules/IrcAdmin.py @@ -77,6 +77,8 @@ class IrcAdmin(Module): return self.sub_save_config(connection, event, nick, userhost, replypath, what, admin_unlocked) elif whats[0] == 'nick' and admin_unlocked and len(whats) >= 2: return self.sub_change_nick(connection, event, nick, userhost, replypath, what, admin_unlocked) + elif whats[0] == 'load' and admin_unlocked and len(whats) >= 2: + 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) @@ -148,6 +150,35 @@ class IrcAdmin(Module): replystr = 'changed nickname' return self.reply(connection, replypath, replystr) + def sub_load_module(self, connection, event, nick, userhost, replypath, what, admin_unlocked): + """ + Load a module (in both the python and dr.botzo sense) if not already loaded. + """ + + whats = what.split(' ') + + modname = whats[1] + for module in self.modlist: + if modname == module.__class__.__name__: + return self.reply(connection, replypath, 'Module ' + modname + ' is already loaded.') + + # not loaded, let's get to work + try: + modstr = 'modules.'+modname + __import__(modstr) + module = sys.modules[modstr] + botmod = eval('module.' + modname + '(self.config, self.server, self.modlist)') + botmod.register_handlers(self.server) + + # might as well add it to the list + modset = set(self.config.get('dr.botzo', 'module_list').split(',')) + modset.add(modname) + self.config.set('dr.botzo', 'module_list', ','.join(modset)) + + return self.reply(connection, replypath, 'Module ' + modname + ' loaded.') + except ImportError: + return self.reply(connection, replypath, 'Module ' + modname + ' not found.') + def sub_reload_module(self, connection, event, nick, userhost, replypath, what, admin_unlocked): """ Attempt to reload a module, by seeing if it's loaded and, if so, calling its reload()