welcomecenterbot/handlers/handle_join_request.py
2024-01-06 14:25:35 +03:00

23 lines
846 B
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 approve_chat_join_request, delete_message
from handlers.send_button import show_request_msg
from storage import Profile, storage
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
async def handle_join_request(join_request):
logger.info(f"handle join request {join_request}")
chat_id = str(join_request["chat"]["id"])
from_id = str(join_request["from"]["id"])
actor = Profile.get(from_id, join_request)
if len(actor["parents"]) == 0:
# показываем сообщение с кнопкой "поручиться"
await show_request_msg(join_request)
else:
# за пользователя поручились ранее
r = await approve_chat_join_request(chat_id, from_id)
logger.debug(r)
Profile.save(actor)