messages non lus
This commit is contained in:
8838
corpus/fra_wikipedia_2021_10K-sentences.txt
Normal file
8838
corpus/fra_wikipedia_2021_10K-sentences.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,14 @@ from callbacks import properly_fail
|
|||||||
from markov import parle
|
from markov import parle
|
||||||
|
|
||||||
|
|
||||||
|
async def non_lus(room_id):
|
||||||
|
room = tchap_bot.matrix_client.rooms[room_id]
|
||||||
|
if room.unread_notifications:
|
||||||
|
response = await tchap_bot.matrix_client.room_messages(room_id=room_id, limit=room.unread_notifications, direction="back", start="")
|
||||||
|
for message in response.chunk:
|
||||||
|
await repond(room, message, tchap_bot.matrix_client)
|
||||||
|
|
||||||
|
|
||||||
# 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
|
||||||
@@ -23,6 +31,11 @@ async def repond(room: MatrixRoom, message: Event, matrix_client: MatrixClient):
|
|||||||
# 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()
|
||||||
|
|
||||||
|
|
||||||
|
if not hasattr(message, "body") or not hasattr(message, "formatted_body"):
|
||||||
|
# message non textuel
|
||||||
|
raise EventNotConcerned
|
||||||
|
|
||||||
# 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
|
||||||
@@ -36,7 +49,7 @@ async def repond(room: MatrixRoom, message: Event, matrix_client: MatrixClient):
|
|||||||
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)
|
||||||
@@ -56,6 +69,7 @@ tchap_bot = MatrixBot(
|
|||||||
ssl=True
|
ssl=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
tchap_bot.callbacks.register_on_startup(non_lus)
|
||||||
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