Compare commits
27 Commits
91129fc073
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
813a66288d | ||
| 484b5f7119 | |||
| 2d85f0b5de | |||
|
|
81dd3f6bfc | ||
|
|
9d4080b42f | ||
| c82364cdb5 | |||
|
|
09e1e0724a | ||
|
|
d3ab0e2844 | ||
|
|
50248feea7 | ||
| 2f063f7a52 | |||
| 8f9987fcd2 | |||
| 3c18739db0 | |||
| ff30f59787 | |||
|
|
16cd631d64 | ||
|
|
b209964631 | ||
|
|
3ed553b854 | ||
|
|
d1f3f8207b | ||
|
|
95c611ad36 | ||
|
|
162252b2de | ||
|
|
46347a2ea5 | ||
|
|
1dc16b9447 | ||
|
|
dab6faf9d0 | ||
|
|
29b185b1c5 | ||
|
|
e883545e61 | ||
|
|
a3e92ac244 | ||
|
|
7f688dc8aa | ||
|
|
129fb4eafb |
7
.env
7
.env
@@ -1,7 +0,0 @@
|
|||||||
VERBOSE=True
|
|
||||||
SYSTEMD_LOGGING=True
|
|
||||||
matrix_home_server="https://matrix.agent.dev-durable.tchap.gouv.fr"
|
|
||||||
matrix_bot_username="@chat.beta-developpement-durable.gouv.fr:agent.dev-durable.tchap.gouv.fr"
|
|
||||||
matrix_bot_password="C.5;oTYw+Mksn<,7jtgx/TbWHY2Ugf"
|
|
||||||
salt=b'I\x87>\xe5\x91\xbdw\x99\xb3\xea7\xc2\xa6\xbf\x8f#'
|
|
||||||
https_proxy=http://pfrie-std.proxy.e2.rie.gouv.fr:8080/
|
|
||||||
9
.env.exemple
Normal file
9
.env.exemple
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
## Matrix env variables
|
||||||
|
|
||||||
|
VERBOSE=True
|
||||||
|
SYSTEMD_LOGGING=False
|
||||||
|
matrix_home_server="https://matrix.agent.ministere_example.tchap.gouv.fr"
|
||||||
|
matrix_bot_username="jean.quidam@ministere_example.gouv.fr"
|
||||||
|
matrix_bot_password="test"
|
||||||
|
join_on_invite=True
|
||||||
|
#https_proxy=http://adresse.du.proxy:port/
|
||||||
@@ -20,7 +20,7 @@ pip install \
|
|||||||
tchap-bot --index-url https://code.peren.fr/api/v4/projects/83/packages/pypi/simple
|
tchap-bot --index-url https://code.peren.fr/api/v4/projects/83/packages/pypi/simple
|
||||||
|
|
||||||
# Renseignez les informations de connexion :
|
# Renseignez les informations de connexion :
|
||||||
editor .env
|
$EDITOR .env
|
||||||
python -c 'import secrets; print("salt=", secrets.token_bytes(16), sep="")' >> .env
|
python -c 'import secrets; print("salt=", secrets.token_bytes(16), sep="")' >> .env
|
||||||
|
|
||||||
# Lancer
|
# Lancer
|
||||||
|
|||||||
0
corpus/fra_wikipedia_2021_10K-sentences.txt
Executable file → Normal file
0
corpus/fra_wikipedia_2021_10K-sentences.txt
Executable file → Normal file
@@ -1,7 +1,6 @@
|
|||||||
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
|
||||||
@@ -12,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
|
||||||
@@ -24,17 +31,33 @@ 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
|
||||||
|
|
||||||
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)
|
||||||
|
reponse = parle()
|
||||||
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, "m.notice")
|
await matrix_client.send_html_message(room.room_id, reponse)
|
||||||
|
|
||||||
|
|
||||||
|
@properly_fail("Oups, j'ai buggué 😿")
|
||||||
|
@ignore_when_not_concerned
|
||||||
|
async def dune(room: MatrixRoom, message: Event, matrix_client: MatrixClient):
|
||||||
|
event_parser = MessageEventParser(room=room, event=message, matrix_client=matrix_client)
|
||||||
|
event_parser.do_not_accept_own_message()
|
||||||
|
|
||||||
|
if ("Adrien" in message.body or "adrien" in message.body):
|
||||||
|
await matrix_client.room_typing(room.room_id)
|
||||||
|
await matrix_client.send_html_message(room.room_id, "<em>Lisan al-Gaib !</em>", "m.notice")
|
||||||
|
|
||||||
|
|
||||||
tchap_bot = MatrixBot(
|
tchap_bot = MatrixBot(
|
||||||
@@ -46,10 +69,7 @@ tchap_bot = MatrixBot(
|
|||||||
ssl=True
|
ssl=True
|
||||||
)
|
)
|
||||||
|
|
||||||
tchap_bot.matrix_client.matrix_config.encryption_enabled = True
|
tchap_bot.callbacks.register_on_startup(non_lus)
|
||||||
tchap_bot.matrix_client.matrix_config.ignore_unverified_devices = True
|
tchap_bot.callbacks.register_on_message_event(dune)
|
||||||
tchap_bot.matrix_client.matrix_config.join_on_invite = True
|
|
||||||
|
|
||||||
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