welcomecenterbot/handlers/handle_join_request.py

67 lines
1.9 KiB
Python
Raw Normal View History

2024-01-07 09:19:46 +00:00
from bot.api import telegram_api
from bot.announce import show_announce
2024-01-07 11:52:30 +00:00
from bot.config import FEEDBACK_CHAT_ID
2023-09-18 07:50:48 +00:00
import logging
2024-01-07 09:19:46 +00:00
2024-01-07 11:52:30 +00:00
from utils.mention import mention
2023-09-18 07:50:48 +00:00
logger = logging.getLogger(__name__)
2024-09-27 08:28:41 +00:00
2023-04-23 16:54:58 +00:00
2024-09-27 06:23:55 +00:00
positive_reactions = [
"👍",
"",
"🔥",
"🥰",
"👏",
"🎉",
"🙏",
"👌",
"🕊",
"😍",
"❤‍🔥",
"🍓",
"🍾",
"💋",
"😇",
"🤝",
"🤗",
"💘",
"😘",
]
2024-01-07 11:41:27 +00:00
announced_message = {
"ru": "Запрос на вступление опубликован в чате, как только вас узнают и отреагируют - она будет принята",
2024-09-27 06:23:55 +00:00
"en": "The join request is posted in the chat, once you are recognized and someone reacted to - it will be accepted",
2024-01-07 11:41:27 +00:00
}
2024-01-07 11:52:30 +00:00
2023-09-18 13:23:32 +00:00
async def handle_join_request(join_request):
logger.info(f"handle join request {join_request}")
2024-01-07 11:41:27 +00:00
user = join_request["from"]
2024-01-07 09:19:46 +00:00
2024-01-07 11:52:30 +00:00
lang = user.get("language_code", "ru")
# показываем для FEEDBACK_CHAT
2024-09-27 06:23:55 +00:00
await telegram_api(
"sendMessage", chat_id=FEEDBACK_CHAT_ID, text="новая заявка от " + mention(user)
)
2024-01-07 11:41:27 +00:00
# показываем анонс с заявкой
2024-01-07 09:19:46 +00:00
await show_announce(join_request)
2024-01-07 11:41:27 +00:00
# сообщаем пользователю, что опубликовали анонс его заявки
2024-09-27 06:23:55 +00:00
await telegram_api("sendMessage", chat_id=user["id"], text=announced_message[lang])
2024-01-07 11:41:27 +00:00
2024-01-07 09:19:46 +00:00
async def handle_reaction_on_request(update):
chat_id = str(update["chat"]["id"])
from_id = str(update["from"]["id"])
logger.debug(update)
2024-01-07 11:41:27 +00:00
reaction = update.get("message_reaction")
new_reaction = reaction.get("new_reaction")
if new_reaction.get("emoji") in positive_reactions:
2024-01-07 09:19:46 +00:00
# за пользователя поручились
2024-09-27 06:23:55 +00:00
r = await telegram_api(
"approveChatJoinRequest", chat_id=chat_id, user_id=from_id
)
2023-09-18 07:50:48 +00:00
logger.debug(r)