Add full example plugin

Also switch to yaml plugin metadata in example file (ref #33)
This commit is contained in:
Tulir Asokan 2018-12-09 15:17:21 +02:00
parent 5704b3e53b
commit 55685dfd6e
4 changed files with 64 additions and 9 deletions

21
example-plugin/LICENSE Normal file
View 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.

2
example-plugin/build.sh Normal file
View File

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

View File

@ -0,0 +1,14 @@
from maubot import Plugin, MessageEvent
from mautrix.types import EventType
class HelloWorldBot(Plugin):
async def start(self) -> None:
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:
if event.sender != self.client.mxid:
await event.reply("Hello, World!")

View File

@ -1,19 +1,37 @@
# This is an example maubot plugin definition file. # This is an example maubot plugin definition file.
# All plugins must include a file like this named "maubot.ini" in their root directory. # All plugins must include a file like this named "maubot.yaml" in their root directory.
[maubot]
# The unique ID for the plugin. Java package naming style. # The unique ID for the plugin. Java package naming style. (i.e. use your own domain, not xyz.maubot)
ID = xyz.maubot.plugin id: xyz.maubot.example
# A PEP 440 compliant version string. # A PEP 440 compliant version string.
Version = 1.0.0 version: 1.0.0
# The SPDX license identifier for the plugin. https://spdx.org/licenses/ # The SPDX license identifier for the plugin. https://spdx.org/licenses/
# Optional, assumes all rights reserved if omitted. # Optional, assumes all rights reserved if omitted.
License = AGPL-3.0-or-later license: MIT
# The comma-separated list of modules to load from the plugin archive.
# 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. # 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. # However, top-level modules must always be listed even if they're imported by other modules.
Modules = plugin modules:
- helloworld
# The main class of the plugin. Format: module/Class # The main class of the plugin. Format: module/Class
# If `module` is omitted, will default to last module specified in the module list. # 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. # Even if `module` is not omitted here, it must be included in the modules list.
# The main class must extend maubot.Plugin # The main class must extend maubot.Plugin
MainClass = PluginClass main_class: HelloWorldBot
# 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