diff --git a/sopel_modules/SpiceBot/Config.py b/sopel_modules/SpiceBot/Config.py index 450ba59..954083e 100644 --- a/sopel_modules/SpiceBot/Config.py +++ b/sopel_modules/SpiceBot/Config.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi from sopel.cli.run import build_parser, get_configuration import sys +import configparser class BotConfig(): @@ -21,14 +22,29 @@ class BotConfig(): opts = parser.parse_args(argv) self.config = get_configuration(opts) + # Filename + self.filename = self.config.filename + + # load as dict + config = configparser.ConfigParser() + config.read(self.filename) + for each_section in config.sections(): + if each_section.lower() not in self.dict.keys(): + self.dict[each_section.lower()] = dict() + for (each_key, each_val) in config.items(each_section): + if each_key.lower() not in self.dict[each_section.lower()].keys(): + self.dict[each_section.lower()][each_key.lower()] = each_val + def define_section(self, name, cls_, validate=True): return self.config.define_section(name, cls_, validate) def __getattr__(self, name): ''' will only get called for undefined attributes ''' """We will try to find a core value, or return None""" - if hasattr(self.config, name): + if hasattr(self.config.core, name): return eval("self.config.core." + name) + elif name.lower() in self.dict["core"].keys(): + return self.dict["core"][str(name).lower()] else: return None