2019-01-12 14:13:21 +00:00
|
|
|
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 = []
|
|
|
|
|
2019-01-12 17:02:34 +00:00
|
|
|
self.handler.append(MRegexHandler("Hello bot", self.hello_callback))
|
2019-01-12 14:13:21 +00:00
|
|
|
|
|
|
|
# Save parent bot
|
|
|
|
self.bot = bot
|
|
|
|
|
2019-01-12 17:02:34 +00:00
|
|
|
def hello_callback(self, room, event):
|
2019-01-12 14:13:21 +00:00
|
|
|
room.send_text(f"Hello {event['sender']}!")
|
|
|
|
|
|
|
|
def help(self):
|
|
|
|
return open(HELP_LOCATION, mode="r").read()
|
2019-01-12 17:02:34 +00:00
|
|
|
|
|
|
|
def setup():
|
|
|
|
print("This function runs once, when the plugin is used the 1st time.")
|