generated from Nemesis/Exemple
test mendhandler
This commit is contained in:
parent
22a5bc60b6
commit
c81a03326f
2 changed files with 27 additions and 0 deletions
|
@ -9,6 +9,7 @@ import sys
|
|||
import pickle
|
||||
import time
|
||||
import threading
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from matrix_bot_api.matrix_bot_api import MatrixBotAPI
|
||||
|
@ -17,6 +18,7 @@ from matrix_bot_api.mcommand_handler import MCommandHandler
|
|||
from matrix_client.client import MatrixClient
|
||||
|
||||
from mall_handler import MAllHandler
|
||||
from mend_handler import MEndHandler
|
||||
|
||||
# Version initiale par Philippe Depriester et Clement Gauche
|
||||
|
||||
|
@ -1240,6 +1242,9 @@ def quote(room,event): # Gestion des citations
|
|||
else:
|
||||
msg(room,"Je n'ai pas de citations pour ce salon")
|
||||
|
||||
def addquote(room,event):
|
||||
room.send_text(json.dumps(event['content']))
|
||||
|
||||
def biere(room,event): # Gestion des boissons
|
||||
global modules
|
||||
try:
|
||||
|
@ -1651,6 +1656,7 @@ def main():
|
|||
quotes_read()
|
||||
quote_handler = MCommandHandler("quote", quote)
|
||||
bot.add_handler(quote_handler)
|
||||
addquote_handler = MEndHandler("addquote", addquote)
|
||||
|
||||
# bieres
|
||||
if ('biere' in liste_mod):
|
||||
|
|
21
mend_handler.py
Normal file
21
mend_handler.py
Normal file
|
@ -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 a new issue