ruffed
This commit is contained in:
@@ -9,10 +9,30 @@ logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
positive_reactions = ["👍", "❤", "🔥", "🥰", "👏", "🎉", "🙏", "👌", "🕊", "😍", "❤🔥", "🍓", "🍾", "💋", "😇", "🤝", "🤗", "💘", "😘"]
|
||||
positive_reactions = [
|
||||
"👍",
|
||||
"❤",
|
||||
"🔥",
|
||||
"🥰",
|
||||
"👏",
|
||||
"🎉",
|
||||
"🙏",
|
||||
"👌",
|
||||
"🕊",
|
||||
"😍",
|
||||
"❤🔥",
|
||||
"🍓",
|
||||
"🍾",
|
||||
"💋",
|
||||
"😇",
|
||||
"🤝",
|
||||
"🤗",
|
||||
"💘",
|
||||
"😘",
|
||||
]
|
||||
announced_message = {
|
||||
"ru": "Запрос на вступление опубликован в чате, как только вас узнают и отреагируют - она будет принята",
|
||||
"en": "The join request is posted in the chat, once you are recognized and someone reacted to - it will be accepted"
|
||||
"en": "The join request is posted in the chat, once you are recognized and someone reacted to - it will be accepted",
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +42,14 @@ async def handle_join_request(join_request):
|
||||
|
||||
lang = user.get("language_code", "ru")
|
||||
# показываем для FEEDBACK_CHAT
|
||||
await telegram_api("sendMessage", chat_id=FEEDBACK_CHAT_ID, text="новая заявка от " + mention(user))
|
||||
await telegram_api(
|
||||
"sendMessage", chat_id=FEEDBACK_CHAT_ID, text="новая заявка от " + mention(user)
|
||||
)
|
||||
# показываем анонс с заявкой
|
||||
await show_announce(join_request)
|
||||
|
||||
# сообщаем пользователю, что опубликовали анонс его заявки
|
||||
await telegram_api("sendMessage", chat_id=user['id'], text=announced_message[lang])
|
||||
await telegram_api("sendMessage", chat_id=user["id"], text=announced_message[lang])
|
||||
|
||||
|
||||
async def handle_reaction_on_request(update):
|
||||
@@ -39,5 +61,7 @@ async def handle_reaction_on_request(update):
|
||||
new_reaction = reaction.get("new_reaction")
|
||||
if new_reaction.get("emoji") in positive_reactions:
|
||||
# за пользователя поручились
|
||||
r = await telegram_api("approveChatJoinRequest", chat_id=chat_id, user_id=from_id)
|
||||
r = await telegram_api(
|
||||
"approveChatJoinRequest", chat_id=chat_id, user_id=from_id
|
||||
)
|
||||
logger.debug(r)
|
||||
|
@@ -2,14 +2,14 @@ from bot.config import FEEDBACK_CHAT_ID
|
||||
from bot.announce import edit_announce
|
||||
from bot.api import telegram_api
|
||||
import logging
|
||||
from utils.store import get_all_pattern, get_average_pattern
|
||||
from state.scan import get_all_pattern, get_average_pattern
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
start_message = {
|
||||
'en': "Welcome home! You can type any message here to be passed to chat",
|
||||
'ru': "Доброе утро! Можешь напечатать здесь любое сообщение для передачи в чат"
|
||||
"en": "Welcome home! You can type any message here to be passed to chat",
|
||||
"ru": "Доброе утро! Можешь напечатать здесь любое сообщение для передачи в чат",
|
||||
}
|
||||
|
||||
|
||||
@@ -21,25 +21,35 @@ async def handle_private(msg, state):
|
||||
if lang != "ru" and lang != "en":
|
||||
lang = "en"
|
||||
if text and text.startswith("/"):
|
||||
if text == '/start':
|
||||
if text == "/start":
|
||||
await telegram_api("sendMessage", chat_id=uid, text=start_message[lang])
|
||||
state['welcome'] = True
|
||||
elif state.get('welcome'):
|
||||
state["welcome"] = True
|
||||
elif state.get("welcome"):
|
||||
await edit_announce(msg)
|
||||
state['welcome'] = False
|
||||
state["welcome"] = False
|
||||
return
|
||||
elif text.startswith('/toxic'):
|
||||
elif text.startswith("/toxic"):
|
||||
cid = msg.get("chat", {}).get("id")
|
||||
toxic_pattern = f"toxic:{uid}:{cid}:*"
|
||||
toxic_score = await get_average_toxic(toxic_pattern)
|
||||
toxic_score = await get_average_pattern(toxic_pattern)
|
||||
text = f"Средняя токсичность сообщений: {toxic_score}%"
|
||||
mid = msg.get("message_id")
|
||||
await telegram_api("sendMessage", chat_id=uid, reply_to_message_id=mid, text=text)
|
||||
await telegram_api(
|
||||
"sendMessage", chat_id=uid, reply_to_message_id=mid, text=text
|
||||
)
|
||||
return
|
||||
elif text == '/removed':
|
||||
elif text == "/removed":
|
||||
removed_pattern = f"removed:{uid}:*"
|
||||
removed_messages = await get_all_pattern(removed_pattern)
|
||||
if removed_messages:
|
||||
await telegram_api("sendMessage", chat_id=uid, text="\n\n".join(removed_messages))
|
||||
await telegram_api(
|
||||
"sendMessage", chat_id=uid, text="\n\n".join(removed_messages)
|
||||
)
|
||||
return
|
||||
|
||||
await telegram_api("forwardMessage", from_chat_id=sender.get("id"), message_id=msg.get("message_id"), chat_id=FEEDBACK_CHAT_ID)
|
||||
await telegram_api(
|
||||
"forwardMessage",
|
||||
from_chat_id=sender.get("id"),
|
||||
message_id=msg.get("message_id"),
|
||||
chat_id=FEEDBACK_CHAT_ID,
|
||||
)
|
||||
|
@@ -1,15 +1,17 @@
|
||||
import logging
|
||||
import math
|
||||
from utils.store import redis, get_average_pattern
|
||||
from state.redis import redis
|
||||
from state.scan import get_average_pattern
|
||||
from bot.api import telegram_api
|
||||
from bot.config import FEEDBACK_CHAT_ID
|
||||
from nlp.toxicity_detector import detector
|
||||
from handlers.handle_private import handle_private
|
||||
from utils.normalize import normalize
|
||||
from nlp.toxicity_detector import detector
|
||||
from nlp.normalize import normalize
|
||||
|
||||
logger = logging.getLogger('handlers.messages_routing')
|
||||
logger = logging.getLogger("handlers.messages_routing")
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
async def messages_routing(msg, state):
|
||||
cid = msg["chat"]["id"]
|
||||
uid = msg["from"]["id"]
|
||||
@@ -28,11 +30,16 @@ async def messages_routing(msg, state):
|
||||
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_message_id=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")
|
||||
if text == '/toxic@welcomecenter_bot':
|
||||
if text == "/toxic@welcomecenter_bot":
|
||||
# latest in chat
|
||||
latest_toxic_message_id = await redis.get(f"toxic:{cid}")
|
||||
|
||||
@@ -52,46 +59,44 @@ async def messages_routing(msg, state):
|
||||
one_score = await redis.get(f"toxic:{cid}:{uid}:{reply_to_msg_id}")
|
||||
if 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 "😇"
|
||||
)
|
||||
text = f"{int(one_score)}% токсичности\nСредняя токсичность сообщений: {toxic_score}% {emoji}"
|
||||
await telegram_api(
|
||||
"sendMessage",
|
||||
chat_id=cid,
|
||||
reply_to_message_id=reply_to_msg_id,
|
||||
text=text
|
||||
text=text,
|
||||
)
|
||||
await telegram_api(
|
||||
"deleteMessage",
|
||||
chat_id=cid,
|
||||
message_id=mid
|
||||
)
|
||||
elif text == '/removed@welcomecenter_bot':
|
||||
await telegram_api(
|
||||
"deleteMessage",
|
||||
chat_id=cid,
|
||||
message_id=mid
|
||||
)
|
||||
await telegram_api("deleteMessage", chat_id=cid, message_id=mid)
|
||||
elif text == "/removed@welcomecenter_bot":
|
||||
await telegram_api("deleteMessage", chat_id=cid, message_id=mid)
|
||||
else:
|
||||
toxic_score = detector(normalize(text))
|
||||
toxic_perc = math.floor(toxic_score*100)
|
||||
toxic_perc = math.floor(toxic_score * 100)
|
||||
await redis.set(f"toxic:{cid}", mid)
|
||||
await redis.set(f"toxic:{cid}:{uid}:{mid}", toxic_perc, ex=60*60*24*3)
|
||||
logger.info(f'\ntext: {text}\ntoxic: {toxic_perc}%')
|
||||
await redis.set(f"toxic:{cid}:{uid}:{mid}", toxic_perc, ex=60 * 60 * 24 * 3)
|
||||
logger.info(f"\ntext: {text}\ntoxic: {toxic_perc}%")
|
||||
if toxic_score > 0.81:
|
||||
if toxic_score > 0.90:
|
||||
await redis.set(f"removed:{uid}:{cid}:{mid}", text)
|
||||
await telegram_api(
|
||||
"deleteMessage",
|
||||
chat_id=cid,
|
||||
message_id=mid
|
||||
)
|
||||
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":"🙉"}}]'
|
||||
reaction='[{"type":"emoji", "emoji":"🙉"}]',
|
||||
)
|
||||
|
||||
else:
|
||||
|
Reference in New Issue
Block a user