plugin: handle resource files in configs
This commit is contained in:
parent
8b5721375f
commit
61703b484a
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
||||||
config.json
|
config.json
|
||||||
|
resources/*
|
||||||
|
!resources/.gitkeep
|
||||||
|
|
|
@ -24,3 +24,5 @@ Missing features
|
||||||
- [x] Wikipedia: find definition, get random page
|
- [x] Wikipedia: find definition, get random page
|
||||||
- [ ] Wolframalpha
|
- [ ] Wolframalpha
|
||||||
- [ ] Youtube: parsing for title, requests for channel or video
|
- [ ] Youtube: parsing for title, requests for channel or video
|
||||||
|
- [ ] Command aliases
|
||||||
|
- [ ] Question aliases
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"alternative_nicks": ["edmon", "edmond"],
|
"alternative_nicks": ["edmon", "edmond"],
|
||||||
"channels": ["#idi0crates"],
|
"channels": ["#idi0crates"],
|
||||||
"speak_delay": 0.5,
|
"speak_delay": 0.5,
|
||||||
|
"resources_dir": "resources",
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"common": {
|
"common": {
|
||||||
"command_suffix": "please"
|
"command_suffix": "please"
|
||||||
|
|
|
@ -5,5 +5,6 @@ def load_config(config_path, logger=None):
|
||||||
try:
|
try:
|
||||||
with open(config_path, "rt") as config_file:
|
with open(config_path, "rt") as config_file:
|
||||||
return json.load(config_file)
|
return json.load(config_file)
|
||||||
except OSError as exc:
|
except (OSError, json.decoder.JSONDecodeError) as exc:
|
||||||
logger.critical(f"Could not load config file: {exc}")
|
logger.critical(f"Could not load config file: {exc}")
|
||||||
|
exit()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class Plugin:
|
class Plugin:
|
||||||
|
@ -25,6 +26,12 @@ class Plugin:
|
||||||
plugins_configs = self.bot.config["plugins"]
|
plugins_configs = self.bot.config["plugins"]
|
||||||
config = plugins_configs["common"].copy()
|
config = plugins_configs["common"].copy()
|
||||||
config.update(plugins_configs.get(self.name, {}))
|
config.update(plugins_configs.get(self.name, {}))
|
||||||
|
# Load resources as config values.
|
||||||
|
resources_dir = self.bot.config["resources_dir"]
|
||||||
|
for key, resource_path in config.get("resources", {}).items():
|
||||||
|
resource_path = Path(resources_dir) / resource_path
|
||||||
|
with open(resource_path, "rt") as resource_file:
|
||||||
|
config[key] = [l.strip() for l in resource_file.readlines()]
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def check_config(self):
|
def check_config(self):
|
||||||
|
|
0
resources/.gitkeep
Normal file
0
resources/.gitkeep
Normal file
Loading…
Reference in a new issue