toxic-average-fix

This commit is contained in:
Untone 2024-09-26 22:42:21 +03:00
parent e6db7f1a1b
commit 1945baf1d0
2 changed files with 16 additions and 8 deletions

View File

@ -27,7 +27,7 @@ async def handle_private(msg, state):
await edit_announce(msg) await edit_announce(msg)
return return
elif text.startswith('/toxic'): elif text.startswith('/toxic'):
toxic_score = get_average_toxic(msg) toxic_score = await get_average_toxic(msg)
text = f"Средняя токсичность сообщений: {toxic_score}%" text = f"Средняя токсичность сообщений: {toxic_score}%"
await telegram_api("sendMessage", chat_id=uid, reply_to_message_id=msg.get("message_id"), text=text) await telegram_api("sendMessage", chat_id=uid, reply_to_message_id=msg.get("message_id"), text=text)
return return

View File

@ -33,14 +33,22 @@ 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':
# latest in chat
latest_toxic_message_id = await redis.get(f"toxic:{cid}") latest_toxic_message_id = await redis.get(f"toxic:{cid}")
toxic_score = await get_average_toxic(msg)
# reply_to message_id
reply_to_msg_id = mid
if reply_msg: if reply_msg:
scoring_msg_id = reply_msg.get("message_id") reply_to_msg_id = reply_msg.get("message_id")
if not scoring_msg_id and latest_toxic_message_id: if not reply_to_msg_id and latest_toxic_message_id:
scoring_msg_id = int(latest_toxic_message_id) reply_to_msg_id = int(latest_toxic_message_id)
if scoring_msg_id:
one_score = await redis.get(f"toxic:{cid}:{uid}:{scoring_msg_id}") # count average between all of messages
toxic_score = await get_average_toxic(msg)
#
if reply_to_msg_id:
one_score = await redis.get(f"toxic:{cid}:{uid}:{reply_to_msg_id}")
if one_score: if one_score:
logger.debug(one_score) logger.debug(one_score)
emoji = '😳' if toxic_score > 90 else '😟' if toxic_score > 80 else '😏' if toxic_score > 60 else '🙂' if toxic_score > 20 else '😇' emoji = '😳' if toxic_score > 90 else '😟' if toxic_score > 80 else '😏' if toxic_score > 60 else '🙂' if toxic_score > 20 else '😇'
@ -48,7 +56,7 @@ async def messages_routing(msg, state):
await telegram_api( await telegram_api(
"sendMessage", "sendMessage",
chat_id=cid, chat_id=cid,
reply_to_message_id=scoring_msg_id, reply_to_message_id=reply_to_msg_id,
text=text text=text
) )
await telegram_api( await telegram_api(