plugable-matrix-bot/plugins/hello/hello.py

29 lines
817 B
Python
Raw Normal View History

from matrix_bot_api.mregex_handler import MRegexHandler
import os
HELP_LOCATION = os.path.join(os.path.dirname(__file__), 'messages/help')
class Plugin:
""" This is an example plugin with only a single callback. When
a user says "Hello bot" in a room in which te bot is present,
the user replies with "Hello <username>!".
"""
def __init__(self, bot):
# Define sensitivity
self.handler = []
self.handler.append(MRegexHandler("Hello", self.hello_callback, bot))
# Save parent bot
self.bot = bot
def hello_callback(self, room, event):
room.send_text(f"Hello {event['sender']}!")
def help(self):
return open(HELP_LOCATION, mode="r").read()
def setup():
print("This function runs once, when the plugin is used the 1st time.")