removed-fix2

This commit is contained in:
2024-09-26 18:48:41 +03:00
parent ca5f22ec0f
commit 08024e81fc

View File

@@ -32,25 +32,17 @@ async def messages_routing(msg, state):
elif bool(text): elif bool(text):
mid = msg.get("message_id") mid = msg.get("message_id")
if text == '/toxic@welcomecenter_bot': if text == '/toxic@welcomecenter_bot':
text = '' latest_toxic_message_id = await redis.get(f"toxic:{cid}")
toxic_score = 0
if not reply_msg:
logger.debug(f'scoring average for {uid}')
scoring_msg_id = mid
pattern = f"toxic:{cid}:{uid}:*" pattern = f"toxic:{cid}:{uid}:*"
scores = [] scores = []
async for key in redis.scan_iter(pattern): async for key in redis.scan_iter(pattern):
scr = int(await redis.get(key)) scr = int(await redis.get(key))
scores.append(scr) scores.append(scr)
toxic_score = math.floor(sum(scores)/len(scores)) if scores else 0 toxic_score = math.floor(sum(scores)/len(scores)) if scores else 0
emoji = '😳' if toxic_score > 90 else '😟' if toxic_score > 80 else '😏' if toxic_score > 60 else '🙂' if toxic_score > 20 else '😇'
text = f"Доброе утро! Средняя токсичность твоих сообщений: {toxic_score}% {emoji}"
else:
latest_toxic_message_id = await redis.get(f"toxic:{cid}")
scoring_msg_id = reply_msg.get("message_id") or int(latest_toxic_message_id) scoring_msg_id = reply_msg.get("message_id") or int(latest_toxic_message_id)
toxic_score = await redis.get(f"toxic:{cid}:{uid}:{scoring_msg_id}") one_score = await redis.get(f"toxic:{cid}:{uid}:{scoring_msg_id}")
x = int(toxic_score) if toxic_score else 0 emoji = '😳' if toxic_score > 90 else '😟' if toxic_score > 80 else '😏' if toxic_score > 60 else '🙂' if toxic_score > 20 else '😇'
text = f"{x}% токсичности" text = f"{int(one_score)}% токсичности\nСредняя токсичность сообщений: {toxic_score}% {emoji}"
await telegram_api( await telegram_api(
"deleteMessage", "deleteMessage",
chat_id=cid, chat_id=cid,