From 2526ce330d9f77ea262dacbcf6ec9c48a55404fb Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sat, 16 Jan 2021 20:37:25 +0100 Subject: [PATCH] Allow to load plugins --- CHANGELOG.md | 1 + README.md | 10 ++++++++++ xbotlib.py | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6257e77..369975c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Allow to configure avatar from configuration file and environment - Load Redis details fron conf and CLI also ([#23](https://git.autonomic.zone/decentral1se/xbotlib/issues/23)) - Migrate Redis environment naming: `REDIS_URL` -> `XBOT_REDIS_URL` ([#23](https://git.autonomic.zone/decentral1se/xbotlib/issues/23)) +- Allow to load custom plugins ([#24](https://git.autonomic.zone/decentral1se/xbotlib/issues/24)) # xbotlib 0.10.0 (2021-01-16) diff --git a/README.md b/README.md index e342cc3..a9f9d0b 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,16 @@ You should see `INFO Successfully connected to storage` when your bot initialises. Please see the `GlossBot` example for more on how to work with this type of storage. +## Loading Plugins + +You can specify a `plugins = [...]` on your bot definition and they will be +automatically loaded. + +```python +class MyBot(Bot): + plugins = ["xep_0066"] +``` + ## Roadmap See the [issue tracker](https://git.autonomic.zone/decentral1se/xbotlib/issues). diff --git a/xbotlib.py b/xbotlib.py index 8f38cd1..9c631d1 100644 --- a/xbotlib.py +++ b/xbotlib.py @@ -361,6 +361,12 @@ class Bot(ClientXMPP): self.register_plugin("xep_0199") # XMPP Ping self.register_plugin("xep_0084") # User Avatar + try: + for plugin in self.plugins: + self.register_plugin(plugin) + except AttributeError: + self.log.info("No additional plugins loaded") + def init_db(self): """Initialise the Redis key/value store.""" if not self.redis_url: