Support monolithic configs
This commit is contained in:
parent
cc4e3fee72
commit
ee71fe69d2
|
@ -45,7 +45,8 @@ Instance Configuration
|
||||||
"modules":[
|
"modules":[
|
||||||
"PingResponder",
|
"PingResponder",
|
||||||
"Services"
|
"Services"
|
||||||
]
|
],
|
||||||
|
"module_configs": {}
|
||||||
}
|
}
|
||||||
|
|
||||||
In the example directory, this is stored in `config.json`. This may be
|
In the example directory, this is stored in `config.json`. This may be
|
||||||
|
@ -102,3 +103,9 @@ options:
|
||||||
A list of modules to load. Modules are loaded in the order they are listed
|
A list of modules to load. Modules are loaded in the order they are listed
|
||||||
here. :doc:`PingResponder </api/modules/pingresponder>` and :doc:`Services </api/modules/services>` are the *bare minimum* needed to open and
|
here. :doc:`PingResponder </api/modules/pingresponder>` and :doc:`Services </api/modules/services>` are the *bare minimum* needed to open and
|
||||||
maintain and IRC connection.
|
maintain and IRC connection.
|
||||||
|
|
||||||
|
.. cmdoption:: module_configs
|
||||||
|
|
||||||
|
A dictionary mapping module names to module configs. If you prefer a monolithic config file instead of a json config
|
||||||
|
file per module, this can be populated with the same data as the separate config files. Entries here will be
|
||||||
|
preferred over separate config files.
|
||||||
|
|
|
@ -45,10 +45,15 @@ class ModuleBase:
|
||||||
self.log.info("Loaded module %s" % self.moduleName)
|
self.log.info("Loaded module %s" % self.moduleName)
|
||||||
|
|
||||||
def loadConfig(self):
|
def loadConfig(self):
|
||||||
"""Loads this module's config into self.config"""
|
"""
|
||||||
configPath = self.getConfigPath()
|
Loads this module's config into self.config. The bot's main config is checked for a section matching the module
|
||||||
if configPath is not None:
|
name, which will be preferred. If not found, an individual config file will be loaded from the data dir
|
||||||
self.config = PyIRCBot.load(configPath)
|
"""
|
||||||
|
self.config = self.bot.botconfig.get("module_configs", {}).get(self.__class__.__name__, {})
|
||||||
|
if not self.config:
|
||||||
|
configPath = self.getConfigPath()
|
||||||
|
if configPath is not None:
|
||||||
|
self.config = PyIRCBot.load(configPath)
|
||||||
|
|
||||||
def ondisable(self):
|
def ondisable(self):
|
||||||
"""Called when the module should be disabled. Your module should do any sort
|
"""Called when the module should be disabled. Your module should do any sort
|
||||||
|
|
Loading…
Reference in New Issue