To create a plugin for mmpy_bot, subclass the Plugin class. Use the @listen_to decorator on methods within your class to define how the bot responds to specific messages. Each decorated method should accept a Message object. To run the bot, instantiate the Bot class, provide a Settings object (containing Mattermost connection details), and pass a list of your plugin instances to the plugins argument.
from mmpy_bot import Plugin, listen_to, Message, Bot, Settings
class MyPlugin(Plugin):
@listen_to("wake up")
async def wake_up(self, message: Message):
self.driver.reply_to(message, "I'm awake!")
bot = Bot(
settings=Settings(
MATTERMOST_URL = "http://127.0.0.1",
MATTERMOST_PORT = 8065,
BOT_TOKEN = "<your_bot_token>",
BOT_TEAM = "<team_name>",
SSL_VERIFY = False,
),
plugins=[MyPlugin()],
)
bot.run()