Dennis Potter
ca86ade0fa
Before this commit, the name of the bot had to be hard coded into every plugin. Now, the name of the bot to which it should be sensitive can be set in the global config.hjson. Furthermore, the default sensitivity of a plugin is only recognized at the beginning of a sentence and is case insensitive. Finally, the possibility to add aliases for plugins is added.
29 lines
817 B
Python
29 lines
817 B
Python
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.")
|