Update hello world example and add config example

This commit is contained in:
Tulir Asokan 2019-01-07 08:14:29 +02:00
parent 400c9aaebc
commit ac69c50b80
8 changed files with 49 additions and 10 deletions

View File

@ -1,2 +0,0 @@
#!/bin/bash
zip -9r helloworld.mbp maubot.yaml helloworld.py

6
examples/README.md Normal file
View File

@ -0,0 +1,6 @@
# Maubot examples
All examples are published under the [MIT license](LICENSE).
* [Hello World](helloworld/) - Very basic event handling bot that responds "Hello, World!" to all messages.
* [Echo bot](https://github.com/maubot/echo) - Basic command handling bot with !echo and !ping commands
* [Config example](config/) - Simple example of using a config file

View File

@ -0,0 +1,2 @@
# Message to send when user sends !getmessage
message: Default configuration active

View File

@ -0,0 +1,25 @@
from typing import Type
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
from maubot import Plugin, MessageEvent
from maubot.handlers import command
class Config(BaseProxyConfig):
def do_update(self, helper: ConfigUpdateHelper) -> None:
helper.copy("message")
class DatabaseBot(Plugin):
async def start(self) -> None:
await super().start()
self.config.load_and_update()
@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

@ -0,0 +1,12 @@
maubot: 0.1.0
id: xyz.maubot.databasebot
version: 1.0.0
license: MIT
modules:
- configurablebot
main_class: ConfigurableBot
database: false
# Instruct the build tool to include the base config.
extra_files:
- base-config.yaml

View File

@ -1,14 +1,10 @@
from maubot import Plugin, MessageEvent
from mautrix.types import EventType from mautrix.types import EventType
from maubot import Plugin, MessageEvent
from maubot.handlers import event
class HelloWorldBot(Plugin): class HelloWorldBot(Plugin):
async def start(self) -> None: @event.on(EventType.ROOM_MESSAGE)
self.client.add_event_handler(self.handler, EventType.ROOM_MESSAGE)
async def stop(self) -> None:
self.client.remove_event_handler(self.handler, EventType.ROOM_MESSAGE)
async def handler(self, event: MessageEvent) -> None: async def handler(self, event: MessageEvent) -> None:
if event.sender != self.client.mxid: if event.sender != self.client.mxid:
await event.reply("Hello, World!") await event.reply("Hello, World!")

View File

@ -5,7 +5,7 @@
maubot: 0.1.0 maubot: 0.1.0
# The unique ID for the plugin. Java package naming style. (i.e. use your own domain, not xyz.maubot) # The unique ID for the plugin. Java package naming style. (i.e. use your own domain, not xyz.maubot)
id: xyz.maubot.example id: xyz.maubot.helloworld
# A PEP 440 compliant version string. # A PEP 440 compliant version string.
version: 1.0.0 version: 1.0.0