From 025d688fcd27d342fe21ba11fbacdca6585fd4e6 Mon Sep 17 00:00:00 2001 From: fernandodpr Date: Wed, 27 Nov 2024 23:57:44 +0100 Subject: [PATCH] feat: Extend plugin configuration loader to support dynamic levels Previously, the configuration loader in `BasePlugin` only supported loading plugin configurations from the `plugins` section of the `config.yaml` file. This approach limited flexibility and made it incompatible with new configuration structures. With this update, the configuration loader now supports additional sections, such as `community-plugins` and `custom-plugins`, while maintaining backward compatibility. Plugins can access their configurations regardless of where they are defined in the file. - Added dynamic search across multiple levels: `plugins`, `community-plugins`, and `custom-plugins`. - Ensured `plugins` is prioritized to avoid breaking existing setups. - Plugins retain access to their full configuration through `self.config`. How to access configuration in plugins: - Use `self.config` to retrieve plugin-specific options. - Example: `self.config.get('active', False)` checks if the plugin is active. - All configuration options from the corresponding section (e.g., `plugins`, `community-plugins`) are available dynamically. --- plugins/base_plugin.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/base_plugin.py b/plugins/base_plugin.py index 1952ddb..b9c13fd 100644 --- a/plugins/base_plugin.py +++ b/plugins/base_plugin.py @@ -28,8 +28,12 @@ def __init__(self) -> None: super().__init__() self.logger = get_logger(f"Plugin:{self.plugin_name}") self.config = {"active": False} - if "plugins" in relay_config and self.plugin_name in relay_config["plugins"]: - self.config = relay_config["plugins"][self.plugin_name] + plugin_levels = ["plugins", "community-plugins", "custom-plugins"] + + for level in plugin_levels: + if level in relay_config and self.plugin_name in relay_config[level]: + self.config = relay_config[level][self.plugin_name] + break def start(self): if "schedule" not in self.config or (