sticker-captcha-bot/plugins/new_member.py

39 lines
1.5 KiB
Python
Raw Normal View History

2022-07-02 11:44:57 +00:00
import contextlib
2023-09-11 12:48:52 +00:00
from cashews import cache
2022-07-02 11:44:57 +00:00
from pyrogram.types import ChatJoinRequest
from pyrogram import filters
2024-01-22 13:01:59 +00:00
from plugins.languages import MSG, MSG_SUCCESS, MSG_FAILURE, VERIFY_TIME
2022-07-02 11:44:57 +00:00
from sticker.single_utils import Client
2022-07-06 15:20:06 +00:00
from sticker.scheduler import add_decline_request_job, rem_decline_request_job
2022-07-05 09:16:16 +00:00
from sticker import bot, log
2022-07-02 11:44:57 +00:00
from pyromod.utils.errors import TimeoutConversationError
@bot.on_chat_join_request()
async def new_member(client: Client, chat_join_request: ChatJoinRequest):
chat = chat_join_request.chat
2023-09-11 12:48:52 +00:00
await cache.set(f"cid:{chat.id}", "True", expire=3600, exist=True)
2022-07-02 11:44:57 +00:00
user = chat_join_request.from_user
2022-07-06 15:20:06 +00:00
add_decline_request_job(chat_join_request)
2022-07-02 11:44:57 +00:00
try:
2022-07-06 15:20:06 +00:00
with contextlib.suppress(Exception):
await log(chat, user, "REQUEST")
2024-01-22 13:01:59 +00:00
await client.ask(user.id, MSG % chat.title, filters=filters.sticker, timeout=VERIFY_TIME)
2022-07-02 11:44:57 +00:00
with contextlib.suppress(Exception):
await client.send_message(user.id, MSG_SUCCESS)
await chat_join_request.approve()
2022-07-05 09:16:16 +00:00
with contextlib.suppress(Exception):
await log(chat, user, "ACCEPT")
2022-07-06 15:20:06 +00:00
with contextlib.suppress(Exception):
rem_decline_request_job(chat_join_request)
2022-07-02 11:44:57 +00:00
except TimeoutConversationError:
with contextlib.suppress(Exception):
await client.send_message(user.id, MSG_FAILURE)
2023-05-12 14:09:43 +00:00
with contextlib.suppress(Exception):
await chat_join_request.decline()
2022-07-05 09:16:16 +00:00
with contextlib.suppress(Exception):
await log(chat, user, "FAIL_TIMEOUT")