Add !enablemodule and !disablemodule to modules.py
This commit is contained in:
parent
b4397071ed
commit
1eed727bc5
3 changed files with 40 additions and 6 deletions
|
@ -78,10 +78,10 @@ class ModuleManager(object):
|
||||||
else:
|
else:
|
||||||
self.bot.log.error("Module '%s' not loaded", [name])
|
self.bot.log.error("Module '%s' not loaded", [name])
|
||||||
|
|
||||||
def load_modules(self, whitelist=None):
|
def load_modules(self, whitelist=[], blacklist=[]):
|
||||||
for path in self.list_modules():
|
for path in self.list_modules():
|
||||||
name = self._module_name(path)
|
name = self._module_name(path)
|
||||||
if whitelist == None or name in whitelist:
|
if name in whitelist or (not whitelist and not name in blacklist):
|
||||||
self.load_module(name)
|
self.load_module(name)
|
||||||
|
|
||||||
def unload_module(self, name):
|
def unload_module(self, name):
|
||||||
|
|
|
@ -13,6 +13,13 @@ class Module(object):
|
||||||
min_args=1, permission="reload-module", help="Reload a module",
|
min_args=1, permission="reload-module", help="Reload a module",
|
||||||
usage="<module-name>")
|
usage="<module-name>")
|
||||||
|
|
||||||
|
events.on("received.command.enablemodule").hook(self.enable,
|
||||||
|
min_args=1, permission="enable-module", help="Enable a module",
|
||||||
|
usage="<module-name>")
|
||||||
|
events.on("received.command.disablemodule").hook(self.disable,
|
||||||
|
min_args=1, permission="disable-module", help="Disable a module",
|
||||||
|
usage="<module-name>")
|
||||||
|
|
||||||
def load(self, event):
|
def load(self, event):
|
||||||
name = event["args_split"][0].lower()
|
name = event["args_split"][0].lower()
|
||||||
if name in self.bot.modules.modules:
|
if name in self.bot.modules.modules:
|
||||||
|
@ -37,3 +44,31 @@ class Module(object):
|
||||||
self.bot.modules.unload_module(name)
|
self.bot.modules.unload_module(name)
|
||||||
self.bot.modules.load_module(name)
|
self.bot.modules.load_module(name)
|
||||||
event["stdout"].write("Reloaded '%s'" % name)
|
event["stdout"].write("Reloaded '%s'" % name)
|
||||||
|
|
||||||
|
def enable(self, event):
|
||||||
|
name = event["args_split"][0].lower()
|
||||||
|
blacklist = self.bot.get_setting("module-blacklist", [])
|
||||||
|
if not name in blacklist:
|
||||||
|
event["stderr"].write("Module '%s' isn't disabled" % name)
|
||||||
|
return
|
||||||
|
|
||||||
|
blacklist.remove(name)
|
||||||
|
event["stdout"].write("Module '%s' has been enabled and can now "
|
||||||
|
"be loaded" % name)
|
||||||
|
|
||||||
|
def disable(self, event):
|
||||||
|
name = event["args_split"][0].lower()
|
||||||
|
and_unloaded = ""
|
||||||
|
if name in self.bot.modules.modules:
|
||||||
|
self.bot.modules.unload_module(name)
|
||||||
|
and_unloaded = " and unloaded"
|
||||||
|
|
||||||
|
blacklist = self.bot.get_setting("module-blacklist", [])
|
||||||
|
if name in blacklist:
|
||||||
|
event["stderr"].write("Module '%s' is already disabled" % name)
|
||||||
|
return
|
||||||
|
|
||||||
|
blacklist.append(name)
|
||||||
|
self.bot.set_setting("module-blacklist", blacklist)
|
||||||
|
event["stdout"].write("Module '%s' has been disabled%s" % (
|
||||||
|
name, and_unloaded))
|
||||||
|
|
7
start.py
7
start.py
|
@ -25,10 +25,9 @@ bot.database = database
|
||||||
bot.config = config.load_config()
|
bot.config = config.load_config()
|
||||||
bot.args = args
|
bot.args = args
|
||||||
|
|
||||||
whitelist = bot.config.get("module_whitelist", None)
|
whitelist = bot.get_setting("module-whitelist", [])
|
||||||
if not whitelist == None:
|
blacklist = bot.get_setting("module-blacklist", [])
|
||||||
whitelist = whitelist.split(",")
|
bot.modules.load_modules(whitelist=whitelist, blacklist=blacklist)
|
||||||
bot.modules.load_modules(whitelist=whitelist)
|
|
||||||
|
|
||||||
server_details = database.servers.get_all()
|
server_details = database.servers.get_all()
|
||||||
servers = []
|
servers = []
|
||||||
|
|
Loading…
Reference in a new issue