welcomecenterbot/handlers/handle_join_request.py

38 lines
1.6 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
2023-04-23 16:54:58 +00:00
2023-09-18 07:50:48 +00:00
import logging
2024-01-07 09:19:46 +00:00
2023-09-18 07:50:48 +00:00
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
2023-04-23 16:54:58 +00:00
2024-01-07 09:19:46 +00:00
2024-01-07 11:41:27 +00:00
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"
}
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"]
lang = user.get("language_code", "ru")
2024-01-07 09:19:46 +00:00
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
# сообщаем пользователю, что опубликовали анонс его заявки
await telegram_api("sendMessage", chat_id=user['id'], text=announced_message[lang])
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-01-07 11:41:27 +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)