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 # Who is allowed to use the bot?
message: Default configuration active 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 typing import Type
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
from maubot import Plugin, MessageEvent from maubot import Plugin, MessageEvent
from maubot.handlers import command from maubot.handlers import command
@ -7,19 +6,22 @@ from maubot.handlers import command
class Config(BaseProxyConfig): class Config(BaseProxyConfig):
def do_update(self, helper: ConfigUpdateHelper) -> None: 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: async def start(self) -> None:
await super().start()
self.config.load_and_update() 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 @classmethod
def get_config_class(cls) -> Type[BaseProxyConfig]: def get_config_class(cls) -> Type[BaseProxyConfig]:
return Config 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 maubot: 0.1.0
id: xyz.maubot.databasebot id: xyz.maubot.databasebot
version: 1.0.0 version: 2.0.0
license: MIT license: MIT
modules: modules:
- configurablebot - configurablebot
main_class: ConfigurableBot main_class: ConfigurableBot
database: false database: false
config: true
# Instruct the build tool to include the base config. # Instruct the build tool to include the base config.
extra_files: extra_files: