plugable-matrix-bot/matrix_bot_api/mcommand_handler.py
Dennis 57499db3f5 Initial commit of software
This commit includes the matrix bot API
(https://github.com/shawnanastasio/python-matrix-bot-api/) and the first
proof of concept that the plugin API works. Furthermore, it includes the
first version of a plugin that acquires event from an Admidio setup
(https://admidio.org).
2018-12-16 16:38:47 +01:00

26 lines
883 B
Python

"""
Defines a matrix bot handler for commands
"""
import re
from matrix_bot_api.mhandler import MHandler
class MCommandHandler(MHandler):
# command - String of command to handle
# handle_callback - Function to call if message contains command
# cmd_char - Character that denotes a command. '!' by default
def __init__(self, command, handle_callback, cmd_char='!'):
MHandler.__init__(self, self.test_command, handle_callback)
self.command = command
self.cmd_char = cmd_char
# Function called by Matrix bot api to determine whether or not to handle this message
def test_command(self, room, event):
# Test the message to see if it has our command
if event['type'] == "m.room.message":
if re.match(self.cmd_char + self.command, event['content']['body']):
return True
return False