score-reply

This commit is contained in:
Untone 2024-09-26 15:50:50 +03:00
parent f51548dc07
commit 23c7b54136

View File

@ -15,6 +15,7 @@ async def messages_routing(msg, state):
cid = msg["chat"]["id"]
uid = msg["from"]["id"]
text = msg.get("text")
reply_msg = msg.get("reply_to_message")
if cid == uid:
# сообщения в личке с ботом
@ -25,11 +26,10 @@ async def messages_routing(msg, state):
# сообщения из группы обратной связи
logger.info("feedback chat message")
logger.debug(msg)
reply_msg = msg.get("reply_to_message")
if reply_msg:
reply_chat_id = reply_msg.get("chat", {}).get("id")
if reply_chat_id != FEEDBACK_CHAT_ID:
await telegram_api("sendMessage", chat_id=reply_chat_id, text=text, reply_to=reply_msg.get("message_id"))
await telegram_api("sendMessage", chat_id=reply_chat_id, text=text, reply_to_message_id=reply_msg.get("message_id"))
elif bool(text):
mid = msg.get("message_id")
@ -37,13 +37,21 @@ async def messages_routing(msg, state):
await telegram_api(
"sendMessage",
chat_id=cid,
reply_to=mid,
text=f"{latest_toxic.get(cid, 0)}%"
reply_to_message_id=mid,
text=f"{latest_toxic.get(cid, 0)}% токсичности"
)
elif text == '/score' and reply_to:
await telegram_api(
"re",
chat_id=cid,
reply_to_message_id=mid,
text=f"{latest_toxic.get(f"{cid}:{reply_msg.get("message_id")}", 0)}% токсичности"
)
else:
toxic_score = detector(text)
toxic_perc = math.floor(toxic_score*100)
latest_toxic[cid] = toxic_perc
latest_toxic[f"{cid}:{mid}"] = toxic_perc
logger.info(f'\ntext: {text}\ntoxic: {toxic_perc}%')
if toxic_score > 0.81:
if toxic_score > 0.90: