score-reply
This commit is contained in:
parent
f51548dc07
commit
23c7b54136
|
@ -15,6 +15,7 @@ async def messages_routing(msg, state):
|
||||||
cid = msg["chat"]["id"]
|
cid = msg["chat"]["id"]
|
||||||
uid = msg["from"]["id"]
|
uid = msg["from"]["id"]
|
||||||
text = msg.get("text")
|
text = msg.get("text")
|
||||||
|
reply_msg = msg.get("reply_to_message")
|
||||||
|
|
||||||
if cid == uid:
|
if cid == uid:
|
||||||
# сообщения в личке с ботом
|
# сообщения в личке с ботом
|
||||||
|
@ -25,11 +26,10 @@ async def messages_routing(msg, state):
|
||||||
# сообщения из группы обратной связи
|
# сообщения из группы обратной связи
|
||||||
logger.info("feedback chat message")
|
logger.info("feedback chat message")
|
||||||
logger.debug(msg)
|
logger.debug(msg)
|
||||||
reply_msg = msg.get("reply_to_message")
|
|
||||||
if reply_msg:
|
if reply_msg:
|
||||||
reply_chat_id = reply_msg.get("chat", {}).get("id")
|
reply_chat_id = reply_msg.get("chat", {}).get("id")
|
||||||
if reply_chat_id != FEEDBACK_CHAT_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):
|
elif bool(text):
|
||||||
mid = msg.get("message_id")
|
mid = msg.get("message_id")
|
||||||
|
@ -37,13 +37,21 @@ async def messages_routing(msg, state):
|
||||||
await telegram_api(
|
await telegram_api(
|
||||||
"sendMessage",
|
"sendMessage",
|
||||||
chat_id=cid,
|
chat_id=cid,
|
||||||
reply_to=mid,
|
reply_to_message_id=mid,
|
||||||
text=f"{latest_toxic.get(cid, 0)}%"
|
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:
|
else:
|
||||||
toxic_score = detector(text)
|
toxic_score = detector(text)
|
||||||
toxic_perc = math.floor(toxic_score*100)
|
toxic_perc = math.floor(toxic_score*100)
|
||||||
latest_toxic[cid] = toxic_perc
|
latest_toxic[cid] = toxic_perc
|
||||||
|
latest_toxic[f"{cid}:{mid}"] = toxic_perc
|
||||||
logger.info(f'\ntext: {text}\ntoxic: {toxic_perc}%')
|
logger.info(f'\ntext: {text}\ntoxic: {toxic_perc}%')
|
||||||
if toxic_score > 0.81:
|
if toxic_score > 0.81:
|
||||||
if toxic_score > 0.90:
|
if toxic_score > 0.90:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user