Move module black/white list to IRCBot, allow "safe" loading of all modules
This commit is contained in:
parent
bb073dcdce
commit
1c296826d7
3 changed files with 23 additions and 5 deletions
|
@ -59,6 +59,13 @@ class Bot(object):
|
|||
elif type == TriggerResult.Return:
|
||||
return returned
|
||||
|
||||
def load_modules(self, safe: bool=False
|
||||
) -> typing.Tuple[typing.List[str], typing.List[str]]:
|
||||
whitelist = self.get_setting("module-whitelist", [])
|
||||
blacklist = self.get_setting("module-blacklist", [])
|
||||
return self.modules.load_modules(self, whitelist=whitelist,
|
||||
blacklist=blacklist, safe=safe)
|
||||
|
||||
def add_server(self, server_id: int, connect: bool = True,
|
||||
connection_param_args: typing.Dict[str, str]={}
|
||||
) -> IRCServer.Server:
|
||||
|
|
|
@ -193,14 +193,26 @@ class ModuleManager(object):
|
|||
return loaded_module
|
||||
|
||||
def load_modules(self, bot: "IRCBot.Bot", whitelist: typing.List[str]=[],
|
||||
blacklist: typing.List[str]=[]):
|
||||
blacklist: typing.List[str]=[], safe: bool=False
|
||||
) -> typing.Tuple[typing.List[str], typing.List[str]]:
|
||||
fail = []
|
||||
success = []
|
||||
for type, path in self.list_modules():
|
||||
name = self._module_name(path)
|
||||
if name in whitelist or (not whitelist and not name in blacklist):
|
||||
try:
|
||||
self.load_module(bot, name)
|
||||
except ModuleWarning:
|
||||
pass
|
||||
fail.append(name)
|
||||
continue
|
||||
except Exception as e:
|
||||
if safe:
|
||||
fail.append(name)
|
||||
continue
|
||||
else:
|
||||
raise
|
||||
success.append(name)
|
||||
return success, fail
|
||||
|
||||
def unload_module(self, name: str):
|
||||
if not name in self.modules:
|
||||
|
|
5
start.py
5
start.py
|
@ -71,12 +71,11 @@ if args.module:
|
|||
module.module.command_line(args.module_args)
|
||||
sys.exit(0)
|
||||
|
||||
whitelist = bot.get_setting("module-whitelist", [])
|
||||
blacklist = bot.get_setting("module-blacklist", [])
|
||||
|
||||
server_configs = bot.database.servers.get_all()
|
||||
|
||||
if len(server_configs):
|
||||
modules.load_modules(bot, whitelist=whitelist, blacklist=blacklist)
|
||||
bot.load_modules()
|
||||
|
||||
servers = []
|
||||
for server_id, alias in server_configs:
|
||||
|
|
Loading…
Reference in a new issue