mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
Update hello world example and add config example
This commit is contained in:
parent
400c9aaebc
commit
ac69c50b80
@ -1,2 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
zip -9r helloworld.mbp maubot.yaml helloworld.py
|
|
6
examples/README.md
Normal file
6
examples/README.md
Normal 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
|
2
examples/config/base-config.yaml
Normal file
2
examples/config/base-config.yaml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Message to send when user sends !getmessage
|
||||||
|
message: Default configuration active
|
25
examples/config/configurablebot.py
Normal file
25
examples/config/configurablebot.py
Normal 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"])
|
12
examples/config/maubot.yaml
Normal file
12
examples/config/maubot.yaml
Normal 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
|
@ -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!")
|
@ -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
|
Loading…
Reference in New Issue
Block a user