This commit is contained in:
Untone 2024-09-26 17:01:52 +03:00
parent 0604a4fd8f
commit 9537d8875b

View File

@ -37,18 +37,20 @@ async def messages_routing(msg, state):
pattern = f"toxic:{cid}:{uid}:*" pattern = f"toxic:{cid}:{uid}:*"
scores = [] scores = []
async for key in client.scan_iter(pattern): async for key in client.scan_iter(pattern):
scr = await redis.get(key) scr = int(await redis.get(key))
scores.append(scr) scores.append(scr)
toxic_score = sum(scores)/len(scores) toxic_score = math.floor(sum(scores)/len(scores))
text = f"Средняя токсичность сообщений: {toxic_score}%"
else: else:
latest_toxic_message_id = await redis.get(f"toxic:{cid}") latest_toxic_message_id = await redis.get(f"toxic:{cid}")
scoring_msg_id = reply_msg.get("message_id") or latest_toxic_message_id scoring_msg_id = reply_msg.get("message_id") or latest_toxic_message_id
toxic_score = await redis.get(f"toxic:{cid}:{uid}:{scoring_msg_id}") toxic_score = float(await redis.get(f"toxic:{cid}:{uid}:{scoring_msg_id}"))
text = f"{float(toxic_score)}% токсичности"
await telegram_api( await telegram_api(
"sendMessage", "sendMessage",
chat_id=cid, chat_id=cid,
reply_to_message_id=scoring_msg_id, reply_to_message_id=scoring_msg_id,
text=f"{toxic_score}% токсичности" text=text
) )
await telegram_api( await telegram_api(
"deleteMessage", "deleteMessage",