From 55685dfd6e18c74dddbcc15767d0b9e90d7c037c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 9 Dec 2018 15:17:21 +0200 Subject: [PATCH] Add full example plugin Also switch to yaml plugin metadata in example file (ref #33) --- example-plugin/LICENSE | 21 +++++++++++ example-plugin/build.sh | 2 ++ example-plugin/helloworld.py | 14 ++++++++ .../maubot.yaml | 36 ++++++++++++++----- 4 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 example-plugin/LICENSE create mode 100644 example-plugin/build.sh create mode 100644 example-plugin/helloworld.py rename example-maubot.ini => example-plugin/maubot.yaml (51%) diff --git a/example-plugin/LICENSE b/example-plugin/LICENSE new file mode 100644 index 0000000..bfdfe68 --- /dev/null +++ b/example-plugin/LICENSE @@ -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. diff --git a/example-plugin/build.sh b/example-plugin/build.sh new file mode 100644 index 0000000..1e83037 --- /dev/null +++ b/example-plugin/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +zip -9r helloworld.mbp maubot.yaml helloworld.py diff --git a/example-plugin/helloworld.py b/example-plugin/helloworld.py new file mode 100644 index 0000000..f91e168 --- /dev/null +++ b/example-plugin/helloworld.py @@ -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!") diff --git a/example-maubot.ini b/example-plugin/maubot.yaml similarity index 51% rename from example-maubot.ini rename to example-plugin/maubot.yaml index efa04f3..c173d37 100644 --- a/example-maubot.ini +++ b/example-plugin/maubot.yaml @@ -1,19 +1,37 @@ # This is an example maubot plugin definition file. -# All plugins must include a file like this named "maubot.ini" in their root directory. -[maubot] -# The unique ID for the plugin. Java package naming style. -ID = xyz.maubot.plugin +# All plugins must include a file like this named "maubot.yaml" in their root directory. + +# The unique ID for the plugin. Java package naming style. (i.e. use your own domain, not xyz.maubot) +id: xyz.maubot.example + # 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/ # Optional, assumes all rights reserved if omitted. -License = AGPL-3.0-or-later -# The comma-separated list of modules to load from the plugin archive. +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 = plugin +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 -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