less-norm-2

This commit is contained in:
2024-09-27 14:14:51 +03:00
parent 5606c69035
commit 98b842ef18
2 changed files with 53 additions and 43 deletions

View File

@@ -49,7 +49,7 @@ async def messages_routing(msg, state):
if not reply_to_msg_id and latest_toxic_message_id:
reply_to_msg_id = int(latest_toxic_message_id)
# count toxicity
# count one msg toxicity
if reply_to_msg_id:
# count one message score
one_score = await redis.get(f"toxic:{cid}:{uid}:{reply_to_msg_id}")
@@ -57,36 +57,36 @@ async def messages_routing(msg, state):
if one_score:
logger.debug(one_score)
reply_text += f"{int(one_score)}% токсичности\n"
try:
# count average between all of messages
toxic_pattern = f"toxic:{cid}:{uid}:*"
toxic_score = await get_average_pattern(toxic_pattern)
if toxic_score:
emoji = (
"😳"
if toxic_score > 90
else "😟"
if toxic_score > 80
else "😏"
if toxic_score > 60
else "🙂"
if toxic_score > 20
else "😇"
)
reply_text += (
f"Средняя токсичность сообщений: {toxic_score}% {emoji}"
)
except Exception:
pass
finally:
if reply_text:
await telegram_api(
"sendMessage",
chat_id=cid,
reply_to_message_id=reply_to_msg_id,
text=reply_text,
)
# count overall toxycity
try:
toxic_pattern = f"toxic:{cid}:{uid}:*"
toxic_score = await get_average_pattern(toxic_pattern)
if toxic_score:
emoji = (
"😳"
if toxic_score > 90
else "😟"
if toxic_score > 80
else "😏"
if toxic_score > 60
else "🙂"
if toxic_score > 20
else "😇"
)
reply_text += (
f"Средняя токсичность сообщений: {toxic_score}% {emoji}"
)
except Exception:
pass
if reply_text:
await telegram_api(
"sendMessage",
chat_id=cid,
reply_to_message_id=reply_to_msg_id,
text=reply_text,
)
try:
await telegram_api("deleteMessage", chat_id=cid, message_id=mid)
except Exception: