use get_list and set_list to move dynamic module en/disabling to bot.conf
This commit is contained in:
parent
3bf2f86702
commit
3028759c86
2 changed files with 24 additions and 25 deletions
|
@ -77,41 +77,46 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write(result.message)
|
event["stderr"].write(result.message)
|
||||||
|
|
||||||
@utils.hook("received.command.enablemodule", min_args=1)
|
def _get_blacklist(self):
|
||||||
|
return self.bot.config.get_list("module-blacklist")
|
||||||
|
def _save_blacklist(self, modules):
|
||||||
|
self.bot.config.set_list("module-blacklist", modules)
|
||||||
|
self.bot.config.save()
|
||||||
|
|
||||||
|
@utils.hook("received.command.enablemodule")
|
||||||
|
@utils.kwarg("min_args", 1)
|
||||||
|
@utils.kwarg("help", "Remove a module from the module blacklist")
|
||||||
|
@utils.kwarg("usage", "<module>")
|
||||||
|
@utils.kwarg("permission", "enable-module")
|
||||||
def enable(self, event):
|
def enable(self, event):
|
||||||
"""
|
|
||||||
:help: Remove a module from the module blacklist
|
|
||||||
:usage: <module name>
|
|
||||||
:permission: enable-module
|
|
||||||
"""
|
|
||||||
name = event["args_split"][0].lower()
|
name = event["args_split"][0].lower()
|
||||||
blacklist = self.bot.get_setting("module-blacklist", [])
|
|
||||||
|
blacklist = self._get_blacklist()
|
||||||
if not name in blacklist:
|
if not name in blacklist:
|
||||||
raise utils.EventError("Module '%s' isn't disabled" % name)
|
raise utils.EventError("Module '%s' isn't disabled" % name)
|
||||||
|
|
||||||
blacklist.remove(name)
|
blacklist.remove(name)
|
||||||
self.bot.set_setting("module-blacklist", blacklist)
|
self._save_blacklist(blacklist)
|
||||||
event["stdout"].write("Module '%s' has been enabled and can now "
|
event["stdout"].write("Module '%s' has been enabled and can now "
|
||||||
"be loaded" % name)
|
"be loaded" % name)
|
||||||
|
|
||||||
@utils.hook("received.command.disablemodule", min_args=1)
|
@utils.hook("received.command.disablemodule")
|
||||||
|
@utils.kwarg("min_args", 1)
|
||||||
|
@utils.kwarg("help", "Add a module to the module blacklist")
|
||||||
|
@utils.kwarg("usage", "<module>")
|
||||||
|
@utils.kwarg("permission", "disable-module")
|
||||||
def disable(self, event):
|
def disable(self, event):
|
||||||
"""
|
|
||||||
:help: Add a module to the module blacklist
|
|
||||||
:usage: <module name>
|
|
||||||
:permission: disable-module
|
|
||||||
"""
|
|
||||||
name = event["args_split"][0].lower()
|
name = event["args_split"][0].lower()
|
||||||
and_unloaded = ""
|
and_unloaded = ""
|
||||||
if name in self.bot.modules.modules:
|
if name in self.bot.modules.modules:
|
||||||
self.bot.modules.unload_module(name)
|
self.bot.modules.unload_module(name)
|
||||||
and_unloaded = " and unloaded"
|
and_unloaded = " and unloaded"
|
||||||
|
|
||||||
blacklist = self.bot.get_setting("module-blacklist", [])
|
blacklist = self._get_blacklist()
|
||||||
if name in blacklist:
|
if name in blacklist:
|
||||||
raise utils.EventError("Module '%s' is already disabled" % name)
|
raise utils.EventError("Module '%s' is already disabled" % name)
|
||||||
|
|
||||||
blacklist.append(name)
|
blacklist.append(name)
|
||||||
self.bot.set_setting("module-blacklist", blacklist)
|
self._save_blacklist(blacklist)
|
||||||
event["stdout"].write("Module '%s' has been disabled%s" % (
|
event["stdout"].write("Module '%s' has been disabled%s" % (
|
||||||
name, and_unloaded))
|
name, and_unloaded))
|
||||||
|
|
|
@ -147,16 +147,10 @@ class Bot(object):
|
||||||
sys.exit(20)
|
sys.exit(20)
|
||||||
|
|
||||||
def _module_lists(self):
|
def _module_lists(self):
|
||||||
db_whitelist = set(self.get_setting("module-whitelist", []))
|
whitelist = self.config.get_list("module-whitelist")
|
||||||
db_blacklist = set(self.get_setting("module-blacklist", []))
|
blacklist = self.config.get_list("module-blacklist")
|
||||||
|
|
||||||
conf_whitelist = self.config.get("module-whitelist", "").split(",")
|
return whitelist, blacklist
|
||||||
conf_blacklist = self.config.get("module-blacklist", "").split(",")
|
|
||||||
|
|
||||||
conf_whitelist = set(filter(None, conf_whitelist))
|
|
||||||
conf_blacklist = set(filter(None, conf_blacklist))
|
|
||||||
|
|
||||||
return (db_whitelist|conf_whitelist, db_blacklist|conf_blacklist)
|
|
||||||
|
|
||||||
def load_modules(self
|
def load_modules(self
|
||||||
) -> typing.Tuple[typing.List[str], typing.List[str]]:
|
) -> typing.Tuple[typing.List[str], typing.List[str]]:
|
||||||
|
|
Loading…
Reference in a new issue