.
This commit is contained in:
@@ -3,8 +3,7 @@ import math
|
||||
|
||||
from bot.api import telegram_api
|
||||
from bot.config import FEEDBACK_CHAT_ID
|
||||
from nlp.toxicity import text2toxicity
|
||||
from nlp.replying import get_toxic_reply
|
||||
from nlp.toxicity_detector import detector
|
||||
from handlers.handle_private import handle_private
|
||||
|
||||
logger = logging.getLogger('handlers.messages_routing')
|
||||
@@ -31,18 +30,26 @@ async def messages_routing(msg, state):
|
||||
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"))
|
||||
|
||||
# TODO: implement text2toxicity with https://huggingface.co/s-nlp/russian_toxicity_classifier
|
||||
elif bool(text):
|
||||
toxic_score = text2toxicity(text)
|
||||
mid = msg.get("message_id")
|
||||
non_toxic_score, toxic_score = detector(text)
|
||||
logger.info(f'\ntext: {text}\ntoxic: {math.floor(toxic_score*100)}%')
|
||||
if toxic_score > 0.71:
|
||||
toxic_reply = get_toxic_reply(toxic_score)
|
||||
await telegram_api(
|
||||
"setMessageReaction",
|
||||
chat_id=cid,
|
||||
is_big=True,
|
||||
message_id=msg.get("message_id"),
|
||||
reaction=f'[{{"type":"emoji", "emoji":"{toxic_reply}"}}]'
|
||||
)
|
||||
if toxic_score > 0.85:
|
||||
await telegram_api(
|
||||
"deletemessage",
|
||||
chat_id=cid,
|
||||
message_id=mid
|
||||
)
|
||||
else:
|
||||
await telegram_api(
|
||||
"setMessageReaction",
|
||||
chat_id=cid,
|
||||
is_big=True,
|
||||
message_id=mid,
|
||||
reaction=f'[{{"type":"emoji", "emoji":"🙉"}}]'
|
||||
)
|
||||
|
||||
else:
|
||||
pass
|
||||
|
Reference in New Issue
Block a user