Load whitelist in start.py, pass to ModuleManager.load_modules
This commit is contained in:
parent
568d714fb2
commit
01a5032e87
2 changed files with 8 additions and 6 deletions
|
@ -15,9 +15,6 @@ class ModuleManager(object):
|
||||||
def _load_module(self, filename):
|
def _load_module(self, filename):
|
||||||
name = self.module_name(filename)
|
name = self.module_name(filename)
|
||||||
|
|
||||||
whitelist = self.bot.config.get("module_whitelist", [])
|
|
||||||
if whitelist and name not in whitelist: return
|
|
||||||
|
|
||||||
with open(filename) as module_file:
|
with open(filename) as module_file:
|
||||||
while True:
|
while True:
|
||||||
line = module_file.readline().strip()
|
line = module_file.readline().strip()
|
||||||
|
@ -73,8 +70,9 @@ class ModuleManager(object):
|
||||||
else:
|
else:
|
||||||
sys.stderr.write("module '%s' not loaded.\n" % filename)
|
sys.stderr.write("module '%s' not loaded.\n" % filename)
|
||||||
|
|
||||||
def load_modules(self):
|
def load_modules(self, whitelist=None):
|
||||||
for filename in self.list_modules():
|
for filename in self.list_modules():
|
||||||
|
if whitelist == None or filename in whitelist:
|
||||||
self.load_module(filename)
|
self.load_module(filename)
|
||||||
|
|
||||||
def unload_module(self, module):
|
def unload_module(self, module):
|
||||||
|
|
6
start.py
6
start.py
|
@ -24,7 +24,11 @@ config = Config.Config(bot, args.config)
|
||||||
bot.database = database
|
bot.database = database
|
||||||
bot.config = config.load_config()
|
bot.config = config.load_config()
|
||||||
bot.args = args
|
bot.args = args
|
||||||
bot.modules.load_modules()
|
|
||||||
|
whitelist = bot.config.get("module_whitelist", None)
|
||||||
|
if not whitelist == None:
|
||||||
|
whitelist = whitelist.split(",")
|
||||||
|
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