Update configurable bot example to match the one in docs

This commit is contained in:
Tulir Asokan 2021-12-15 20:11:08 +02:00
parent e8862ed1a3
commit 7e06eadfd0
3 changed files with 18 additions and 12 deletions

View File

@ -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

View File

@ -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"])

View File

@ -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: