import inutile
This commit is contained in:
123
tchap-beta.py
123
tchap-beta.py
@@ -1,62 +1,61 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from nio import MatrixRoom, Event
|
from nio import MatrixRoom, Event
|
||||||
from nio.crypto import ENCRYPTION_ENABLED
|
|
||||||
|
from matrix_bot.bot import MatrixBot
|
||||||
from matrix_bot.bot import MatrixBot
|
from matrix_bot.client import MatrixClient
|
||||||
from matrix_bot.client import MatrixClient
|
from matrix_bot.eventparser import MessageEventParser, ignore_when_not_concerned, EventNotConcerned
|
||||||
from matrix_bot.eventparser import MessageEventParser, ignore_when_not_concerned, EventNotConcerned
|
|
||||||
|
from config import env_config
|
||||||
from config import env_config
|
from callbacks import properly_fail
|
||||||
from callbacks import properly_fail
|
from markov import parle
|
||||||
from markov import parle
|
|
||||||
|
|
||||||
|
# le décorateur @properly_fail va permettre à la commande de laisser un message d'erreur si la commande plante et
|
||||||
# le décorateur @properly_fail va permettre à la commande de laisser un message d'erreur si la commande plante et
|
# d'envoyer le message que le bot n'est plus en train d'écrire
|
||||||
# d'envoyer le message que le bot n'est plus en train d'écrire
|
# la fonction va être appelée dans tous les cas, le décorateur @ignore_when_not_concerned
|
||||||
# la fonction va être appelée dans tous les cas, le décorateur @ignore_when_not_concerned
|
# permet de laisser event_parser gérer le cas où la commande n'est pas concernée
|
||||||
# permet de laisser event_parser gérer le cas où la commande n'est pas concernée
|
@properly_fail("Oups, j'ai buggué 😿")
|
||||||
@properly_fail("Oups, j'ai buggué 😿")
|
@ignore_when_not_concerned
|
||||||
@ignore_when_not_concerned
|
async def repond(room: MatrixRoom, message: Event, matrix_client: MatrixClient):
|
||||||
async def repond(room: MatrixRoom, message: Event, matrix_client: MatrixClient):
|
# on initialise un event_parser pour décider à quel message cette commande va répondre
|
||||||
# on initialise un event_parser pour décider à quel message cette commande va répondre
|
event_parser = MessageEventParser(room=room, event=message, matrix_client=matrix_client)
|
||||||
event_parser = MessageEventParser(room=room, event=message, matrix_client=matrix_client)
|
# il ne va pas répondre à ses propres messages
|
||||||
# il ne va pas répondre à ses propres messages
|
event_parser.do_not_accept_own_message()
|
||||||
event_parser.do_not_accept_own_message()
|
|
||||||
|
# ne répond qu'en message direct ou dans un salon s'il est interpellé avec @identifiant.du.bot dans le corps du message
|
||||||
# ne répond qu'en message direct ou dans un salon s'il est interpellé avec @identifiant.du.bot dans le corps du message
|
if len(room.users) > 2 and not (message.formatted_body and matrix_client.user_id in message.formatted_body):
|
||||||
if len(room.users) > 2 and not (message.formatted_body and matrix_client.user_id in message.formatted_body):
|
raise EventNotConcerned
|
||||||
raise EventNotConcerned
|
|
||||||
|
reponse = parle()
|
||||||
reponse = parle()
|
# il envoie l'information qu'il est en train d'écrire
|
||||||
# il envoie l'information qu'il est en train d'écrire
|
await matrix_client.room_typing(room.room_id)
|
||||||
await matrix_client.room_typing(room.room_id)
|
await asyncio.sleep(len(reponse) / 50)
|
||||||
await asyncio.sleep(len(reponse) / 50)
|
# il envoie le message
|
||||||
# il envoie le message
|
await matrix_client.room_typing(room.room_id, typing_state=False)
|
||||||
await matrix_client.room_typing(room.room_id, typing_state=False)
|
await matrix_client.send_html_message(room.room_id, reponse)
|
||||||
await matrix_client.send_html_message(room.room_id, reponse)
|
|
||||||
|
|
||||||
|
@properly_fail("Oups, j'ai buggué 🐶")
|
||||||
@properly_fail("Oups, j'ai buggué 🐶")
|
@ignore_when_not_concerned
|
||||||
@ignore_when_not_concerned
|
async def dune(room: MatrixRoom, message: Event, matrix_client: MatrixClient):
|
||||||
async def dune(room: MatrixRoom, message: Event, matrix_client: MatrixClient):
|
event_parser = MessageEventParser(room=room, event=message, matrix_client=matrix_client)
|
||||||
event_parser = MessageEventParser(room=room, event=message, matrix_client=matrix_client)
|
event_parser.do_not_accept_own_message()
|
||||||
event_parser.do_not_accept_own_message()
|
|
||||||
|
if ("Adrien" in message.body or "adrien" in message.body):
|
||||||
if ("Adrien" in message.body or "adrien" in message.body):
|
await matrix_client.room_typing(room.room_id)
|
||||||
await matrix_client.room_typing(room.room_id)
|
await matrix_client.send_html_message(room.room_id, "<em>Lisan al-Gaib !</em>", "m.notice")
|
||||||
await matrix_client.send_html_message(room.room_id, "<em>Lisan al-Gaib !</em>", "m.notice")
|
|
||||||
|
|
||||||
|
tchap_bot = MatrixBot(
|
||||||
tchap_bot = MatrixBot(
|
env_config.matrix_home_server,
|
||||||
env_config.matrix_home_server,
|
env_config.matrix_bot_username,
|
||||||
env_config.matrix_bot_username,
|
env_config.matrix_bot_password,
|
||||||
env_config.matrix_bot_password,
|
proxy=env_config.https_proxy,
|
||||||
proxy=env_config.https_proxy,
|
use_functions=True,
|
||||||
use_functions=True,
|
ssl=True
|
||||||
ssl=True
|
)
|
||||||
)
|
|
||||||
|
tchap_bot.callbacks.register_on_message_event(dune)
|
||||||
tchap_bot.callbacks.register_on_message_event(dune)
|
tchap_bot.callbacks.register_on_message_event(repond)
|
||||||
tchap_bot.callbacks.register_on_message_event(repond)
|
tchap_bot.run()
|
||||||
tchap_bot.run()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user