Update configurable bot example to match the one in docs
This commit is contained in:
parent
e8862ed1a3
commit
7e06eadfd0
3 changed files with 18 additions and 12 deletions
|
@ -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"])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue