From d71a6e00eca8d6a5f17de5ae5b7ee5c0c74cda6d Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 26 Sep 2024 15:33:10 +0300 Subject: [PATCH] separate-latest-toxic --- handlers/messages_routing.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/handlers/messages_routing.py b/handlers/messages_routing.py index 604f979..afd3e4f 100644 --- a/handlers/messages_routing.py +++ b/handlers/messages_routing.py @@ -9,7 +9,7 @@ from handlers.handle_private import handle_private logger = logging.getLogger('handlers.messages_routing') logging.basicConfig(level=logging.DEBUG) -latest_toxic = 0 +latest_toxic = {} async def messages_routing(msg, state): cid = msg["chat"]["id"] @@ -33,15 +33,17 @@ async def messages_routing(msg, state): elif bool(text): mid = msg.get("message_id") - if text == '/score': + if text.startswith('/score'): await telegram_api( "sendMessage", chat_id=cid, reply_to=mid, - text=f"{latest_toxic}%" + text=f"{latest_toxic.get(cid, 0)}%" ) toxic_score = detector(text) - logger.info(f'\ntext: {text}\ntoxic: {math.floor(toxic_score*100)}%') + toxic_perc = math.floor(toxic_score*100) + latest_toxic[cid] = toxic_perc + logger.info(f'\ntext: {text}\ntoxic: {toxic_perc}%') if toxic_score > 0.81: if toxic_score > 0.90: await redis.set(f"removed:{uid}:{cid}:{mid}", text)