From 87af05d4b693cb7d98799b10b9e4fce33ad14a71 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 30 Mar 2016 19:31:23 +0100 Subject: added a "hashflag" to modules to stop modules being loaded that rely on a not-present config option. --- ModuleManager.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ModuleManager.py') diff --git a/ModuleManager.py b/ModuleManager.py index 3f6fa9fc..7103b7d3 100644 --- a/ModuleManager.py +++ b/ModuleManager.py @@ -1,4 +1,4 @@ -import glob, imp, inspect, os +import glob, imp, inspect, os, sys class ModuleManager(object): def __init__(self, bot, directory="modules"): @@ -12,11 +12,17 @@ class ModuleManager(object): with open(filename) as module_file: while True: line = module_file.readline().strip() + line_split = line.split(" ") if line and line.startswith("#--"): # this is a hashflag if line == "#--ignore": # nope, ignore this module. return None + elif line_split[0] == "#--require-config" and len( + line_split) > 1: + if not line_split[1].lower() in self.bot.config: + # nope, required config option not present. + return None else: break module = imp.load_source("bitbot_%s" % name, filename) @@ -35,3 +41,5 @@ class ModuleManager(object): assert not module._name in self.modules, ( "module name '%s' attempted to be used twice.") self.modules[module._name] = module + else: + sys.stderr.write("module '%s' not loaded.\n" % filename) -- cgit v1.3.1-10-gc9f91