welcomecenterbot/handlers/handle_join_request.py
2024-09-27 13:30:29 +03:00

67 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from bot.api import telegram_api
from bot.announce import show_announce
from bot.config import FEEDBACK_CHAT_ID
import logging
from utils.mention import mention
logger = logging.getLogger(__name__)
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",
}
async def handle_join_request(join_request):
logger.info(f"handle join request {join_request}")
user = join_request["from"]
lang = user.get("language_code", "ru")
# показываем для FEEDBACK_CHAT
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])
async def handle_reaction_on_request(update):
chat_id = str(update["chat"]["id"])
from_id = str(update["from"]["id"])
logger.debug(update)
reaction = update.get("message_reaction")
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
)
logger.debug(r)