Nemesis
6 years ago
2 changed files with 27 additions and 0 deletions
@ -0,0 +1,21 @@ |
|||
# coding: utf8 |
|||
from matrix_bot_api.mhandler import MHandler |
|||
|
|||
|
|||
class MEndHandler(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, regex_str, handle_callback): |
|||
MHandler.__init__(self, self.test, handle_callback) |
|||
self.regex_str = regex_str |
|||
|
|||
def test(self, room, event): |
|||
if event['type'] == "m.room.message": |
|||
motif = "^.+" + self.regex_str + "$" |
|||
if re.match(motif, event['content']['body']): |
|||
# The message matches the regex, return true |
|||
return True |
|||
|
|||
return False |
Loading…
Reference in new issue