aboutsummaryrefslogtreecommitdiff
path: root/ModuleManager.py
diff options
context:
space:
mode:
authorGravatar jesopo2016-03-30 19:31:23 +0100
committerGravatar jesopo2016-03-30 19:31:23 +0100
commit87af05d4b693cb7d98799b10b9e4fce33ad14a71 (patch)
tree04b7a3d2b238a5753ec8729cc6bd2f59d2814e33 /ModuleManager.py
parentfixed a left over reference to event["channel"] that is now broken in to.py. (diff)
added a "hashflag" to modules to stop modules being loaded that rely on a not-present config option.
Diffstat (limited to 'ModuleManager.py')
-rw-r--r--ModuleManager.py10
1 files changed, 9 insertions, 1 deletions
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)