From 7e06eadfd05c1b30e8f544fa11e517c73b8d7aae Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 15 Dec 2021 20:11:08 +0200 Subject: [PATCH] Update configurable bot example to match the one in docs --- examples/config/base-config.yaml | 7 +++++-- examples/config/configurablebot.py | 20 +++++++++++--------- examples/config/maubot.yaml | 3 ++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/examples/config/base-config.yaml b/examples/config/base-config.yaml index c621847..0f7f8a3 100644 --- a/examples/config/base-config.yaml +++ b/examples/config/base-config.yaml @@ -1,2 +1,5 @@ -# Message to send when user sends !getmessage -message: Default configuration active +# Who is allowed to use the bot? +whitelist: + - "@user:example.com" +# The prefix for the main command without the ! +command_prefix: hello-world diff --git a/examples/config/configurablebot.py b/examples/config/configurablebot.py index 13624be..54b47b6 100644 --- a/examples/config/configurablebot.py +++ b/examples/config/configurablebot.py @@ -1,5 +1,4 @@ from typing import Type - from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper from maubot import Plugin, MessageEvent from maubot.handlers import command @@ -7,19 +6,22 @@ from maubot.handlers import command class Config(BaseProxyConfig): def do_update(self, helper: ConfigUpdateHelper) -> None: - helper.copy("message") + helper.copy("whitelist") + helper.copy("command_prefix") -class DatabaseBot(Plugin): +class ConfigurableBot(Plugin): async def start(self) -> None: - await super().start() self.config.load_and_update() + def get_command_name(self) -> str: + return self.config["command_prefix"] + + @command.new(name=get_command_name) + async def hmm(self, evt: MessageEvent) -> None: + if evt.sender in self.config["whitelist"]: + await evt.reply("You're whitelisted 🎉") + @classmethod def get_config_class(cls) -> Type[BaseProxyConfig]: return Config - - @command.new("getmessage") - async def handler(self, event: MessageEvent) -> None: - if event.sender != self.client.mxid: - await event.reply(self.config["message"]) diff --git a/examples/config/maubot.yaml b/examples/config/maubot.yaml index b049dba..89ae153 100644 --- a/examples/config/maubot.yaml +++ b/examples/config/maubot.yaml @@ -1,11 +1,12 @@ maubot: 0.1.0 id: xyz.maubot.databasebot -version: 1.0.0 +version: 2.0.0 license: MIT modules: - configurablebot main_class: ConfigurableBot database: false +config: true # Instruct the build tool to include the base config. extra_files: