diff --git a/.gitignore b/.gitignore index d344ba6..0360844 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ config.json +resources/* +!resources/.gitkeep diff --git a/README.md b/README.md index 554d213..ffcf71c 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,5 @@ Missing features - [x] Wikipedia: find definition, get random page - [ ] Wolframalpha - [ ] Youtube: parsing for title, requests for channel or video +- [ ] Command aliases +- [ ] Question aliases diff --git a/config.json.example b/config.json.example index 958988f..a8bd9e7 100644 --- a/config.json.example +++ b/config.json.example @@ -5,6 +5,7 @@ "alternative_nicks": ["edmon", "edmond"], "channels": ["#idi0crates"], "speak_delay": 0.5, + "resources_dir": "resources", "plugins": { "common": { "command_suffix": "please" diff --git a/edmond/config.py b/edmond/config.py index a5aa93d..7ab002e 100644 --- a/edmond/config.py +++ b/edmond/config.py @@ -5,5 +5,6 @@ def load_config(config_path, logger=None): try: with open(config_path, "rt") as 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}") + exit() diff --git a/edmond/plugin.py b/edmond/plugin.py index 346c296..518d3cb 100644 --- a/edmond/plugin.py +++ b/edmond/plugin.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +from pathlib import Path class Plugin: @@ -25,6 +26,12 @@ class Plugin: plugins_configs = self.bot.config["plugins"] config = plugins_configs["common"].copy() 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 def check_config(self): diff --git a/resources/.gitkeep b/resources/.gitkeep new file mode 100644 index 0000000..e69de29