From dccbaa332a1eb07fe8c0388acab78818c7ffe061 Mon Sep 17 00:00:00 2001 From: MALINGREY Adrien Date: Wed, 4 Feb 2026 16:33:57 +0000 Subject: [PATCH] =?UTF-8?q?r=C3=A9pond=20en=20message=20direct=20ou=20dans?= =?UTF-8?q?=20les=20salons=20publics=20en=20cas=20d'interpellation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tchap-beta.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tchap-beta.py b/tchap-beta.py index 2e36407..8649fe0 100644 --- a/tchap-beta.py +++ b/tchap-beta.py @@ -14,13 +14,11 @@ from tchap_bot.config import Config from markov import parle -# Ajout du paramètre de configuration du proxy class ConfigProxy(Config): https_proxy: str = Field("", description="Proxy URL") env_config = ConfigProxy() - # 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 # la fonction va être appelée dans tous les cas, le décorateur @ignore_when_not_concerned @@ -33,15 +31,14 @@ async def repond(room: MatrixRoom, message: Event, matrix_client: MatrixClient): # il ne va pas répondre à ses propres messages event_parser.do_not_accept_own_message() - # ne répond que s'il est interpellé dans le message avec @identifiant.du.bot - if not (message.formatted_body and matrix_client.user_id in message.formatted_body): + # 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): raise EventNotConcerned + reponse = parle() # il envoie l'information qu'il est en train d'écrire await matrix_client.room_typing(room.room_id) - # génération d'une phrase aléatoire - reponse = parle() - await asyncio.sleep(len(reponse) / 20) + await asyncio.sleep(len(reponse) / 30) # il envoie le message await matrix_client.send_text_message(room.room_id, reponse, "m.notice") @@ -53,9 +50,11 @@ tchap_bot = MatrixBot( use_functions=True, ssl=True ) + tchap_bot.matrix_client.matrix_config.encryption_enabled = True tchap_bot.matrix_client.matrix_config.ignore_unverified_devices = True tchap_bot.matrix_client.matrix_config.join_on_invite = True tchap_bot.callbacks.register_on_message_event(repond) tchap_bot.run() +