This commit is contained in:
root
2026-02-04 18:35:38 +01:00
parent 3712c4ddbd
commit 173bb371eb
9 changed files with 47 additions and 42 deletions

15
.env Normal file → Executable file
View File

@@ -1,8 +1,7 @@
## 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"
#https_proxy=http://adresse.du.proxy:port/
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/

1
.gitignore vendored Normal file → Executable file
View File

@@ -2,3 +2,4 @@
.venv/
session.txt
store/
__pycache__

0
README.md Normal file → Executable file
View File

26
callbacks.py Executable file
View File

@@ -0,0 +1,26 @@
from nio import MatrixRoom, Event
from matrix_bot.config import logger
from matrix_bot.client import MatrixClient
def properly_fail(function):
"""use this decorator so that your async callback never crash, log the error and return a message to the room"""
@wraps(function)
def decorated(room: MatrixRoom, message: Event, matrix_client: MatrixClient):
function_instance = function(room, message, matrix_client)
async def inner():
try:
return await function_instance
except Exception as unexpected_exception: # noqa
await matrix_client.send_text_message(room.room_id, "Oups, j'ai buggué 😿", "m.notice")
logger.warning(f"command failed with exception : {unexpected_exception}")
exit()
finally:
await matrix_client.room_typing(room.room_id, typing_state=False)
return inner()
return decorated

9
config.py Executable file
View File

@@ -0,0 +1,9 @@
from pydantic import Field
from tchap_bot.config import Config
class ConfigProxy(Config):
https_proxy: str = Field("", description="Proxy URL")
env_config = ConfigProxy()

0
fra_wikipedia_2021_10K-sentences.txt Normal file → Executable file
View File

0
markov.py Normal file → Executable file
View File

38
tchap-beta.py Normal file → Executable file
View File

@@ -4,44 +4,13 @@ from functools import wraps
from nio import MatrixRoom, Event
from nio.crypto import ENCRYPTION_ENABLED
from pydantic import Field
from matrix_bot.bot import MatrixBot
from matrix_bot.client import MatrixClient
from matrix_bot.eventparser import MessageEventParser, ignore_when_not_concerned, EventNotConcerned
from matrix_bot.config import logger
from tchap_bot.config import Config
from markov import parle
class ConfigProxy(Config):
https_proxy: str = Field("", description="Proxy URL")
env_config = ConfigProxy()
def properly_fail(function):
"""use this decorator so that your async callback never crash, log the error and return a message to the room"""
@wraps(function)
def decorated(room: MatrixRoom, message: Event, matrix_client: MatrixClient):
function_instance = function(room, message, matrix_client)
async def inner():
try:
return await function_instance
except Exception as unexpected_exception: # noqa
await matrix_client.send_text_message(room.room_id, "Oups, j'ai buggué 😿", "m.notice")
logger.warning(f"command failed with exception : {unexpected_exception}")
exit()
finally:
await matrix_client.room_typing(room.room_id, typing_state=False)
return inner()
return decorated
from .config import env_config
from .callbacks import properly_fail
from .markov import parle
# le décorateur @properly_fail va permettre à la commande de laisser un message d'erreur si la commande plante et
@@ -67,6 +36,7 @@ async def repond(room: MatrixRoom, message: Event, matrix_client: MatrixClient):
# il envoie le message
await matrix_client.send_text_message(room.room_id, reponse, "m.notice")
tchap_bot = MatrixBot(
env_config.matrix_home_server,
env_config.matrix_bot_username,

0
tchap-beta.service Normal file → Executable file
View File