Update hello world example and add config example
This commit is contained in:
parent
400c9aaebc
commit
ac69c50b80
8 changed files with 49 additions and 10 deletions
21
examples/LICENSE
Normal file
21
examples/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Tulir Asokan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
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
|
10
examples/helloworld/helloworld.py
Normal file
10
examples/helloworld/helloworld.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from mautrix.types import EventType
|
||||
from maubot import Plugin, MessageEvent
|
||||
from maubot.handlers import event
|
||||
|
||||
|
||||
class HelloWorldBot(Plugin):
|
||||
@event.on(EventType.ROOM_MESSAGE)
|
||||
async def handler(self, event: MessageEvent) -> None:
|
||||
if event.sender != self.client.mxid:
|
||||
await event.reply("Hello, World!")
|
43
examples/helloworld/maubot.yaml
Normal file
43
examples/helloworld/maubot.yaml
Normal file
|
@ -0,0 +1,43 @@
|
|||
# This is an example maubot plugin definition file.
|
||||
# All plugins must include a file like this named "maubot.yaml" in their root directory.
|
||||
|
||||
# Target maubot version
|
||||
maubot: 0.1.0
|
||||
|
||||
# The unique ID for the plugin. Java package naming style. (i.e. use your own domain, not xyz.maubot)
|
||||
id: xyz.maubot.helloworld
|
||||
|
||||
# A PEP 440 compliant version string.
|
||||
version: 1.0.0
|
||||
|
||||
# The SPDX license identifier for the plugin. https://spdx.org/licenses/
|
||||
# Optional, assumes all rights reserved if omitted.
|
||||
license: MIT
|
||||
|
||||
# The list of modules to load from the plugin archive.
|
||||
# Modules can be directories with an __init__.py file or simply python files.
|
||||
# Submodules that are imported by modules listed here don't need to be listed separately.
|
||||
# However, top-level modules must always be listed even if they're imported by other modules.
|
||||
modules:
|
||||
- helloworld
|
||||
|
||||
# The main class of the plugin. Format: module/Class
|
||||
# If `module` is omitted, will default to last module specified in the module list.
|
||||
# Even if `module` is not omitted here, it must be included in the modules list.
|
||||
# The main class must extend maubot.Plugin
|
||||
main_class: HelloWorldBot
|
||||
|
||||
# Whether or not instances need a database
|
||||
database: false
|
||||
|
||||
# Extra files that the upcoming build tool should include in the mbp file.
|
||||
#extra_files:
|
||||
#- base-config.yaml
|
||||
#- LICENSE
|
||||
|
||||
# List of dependencies
|
||||
#dependencies:
|
||||
#- foo
|
||||
|
||||
#soft_dependencies:
|
||||
#- bar>=0.1
|
Loading…
Add table
Add a link
Reference in a new issue