2024-08-07 15:33:57 +00:00
|
|
|
from cashews import cache
|
2022-07-05 10:42:47 +00:00
|
|
|
from pyrogram import filters
|
|
|
|
from pyrogram.enums import ChatMemberStatus
|
|
|
|
|
|
|
|
from pyromod.utils.errors import TimeoutConversationError
|
2024-01-22 13:06:47 +00:00
|
|
|
from sticker.languages import RE_MSG, VERIFY_TIME
|
2024-08-07 15:33:57 +00:00
|
|
|
from sticker.scheduler import add_ban_chat_member_job
|
2022-07-05 10:42:47 +00:00
|
|
|
from sticker.single_utils import Message, Client
|
2024-08-07 15:33:57 +00:00
|
|
|
from sticker import bot, log, LogAction
|
2022-07-05 10:42:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bot.on_message(filters=filters.group & filters.command("reverify"))
|
|
|
|
async def re_verify(client: Client, message: Message):
|
2024-08-07 15:33:57 +00:00
|
|
|
reply_to: "Message" = message.reply_to_message
|
|
|
|
if not message.from_user or not reply_to:
|
2022-07-05 10:50:39 +00:00
|
|
|
msg: Message = await message.reply("请回复一条消息来使 Ta 重新验证。")
|
2024-08-07 15:33:57 +00:00
|
|
|
await message.delay_delete(10)
|
|
|
|
await msg.delay_delete(10)
|
2022-07-05 10:42:47 +00:00
|
|
|
return
|
2024-08-07 15:33:57 +00:00
|
|
|
if not reply_to.from_user:
|
2022-07-05 10:42:47 +00:00
|
|
|
return
|
|
|
|
chat = message.chat
|
|
|
|
user = message.from_user
|
|
|
|
member = await client.get_chat_member(chat.id, user.id)
|
|
|
|
if member.status not in [ChatMemberStatus.OWNER, ChatMemberStatus.ADMINISTRATOR]:
|
|
|
|
return
|
|
|
|
|
2024-08-07 15:33:57 +00:00
|
|
|
user = reply_to.from_user
|
2023-09-11 13:05:50 +00:00
|
|
|
if (
|
|
|
|
user.is_self
|
|
|
|
or user.is_verified
|
|
|
|
or user.is_bot
|
|
|
|
or user.is_deleted
|
|
|
|
or user.is_support
|
|
|
|
):
|
2022-07-05 10:44:14 +00:00
|
|
|
return
|
2022-07-05 10:50:39 +00:00
|
|
|
member = await client.get_chat_member(chat.id, user.id)
|
2024-08-07 15:33:57 +00:00
|
|
|
await message.delay_delete(1)
|
|
|
|
key = f"wait:{chat.id}:{user.id}"
|
|
|
|
await cache.set(key, "True", expire=VERIFY_TIME + 5)
|
2022-07-05 10:42:47 +00:00
|
|
|
try:
|
2024-08-07 15:33:57 +00:00
|
|
|
msg = await reply_to.reply(RE_MSG % (user.mention, user.mention))
|
2023-09-11 12:48:52 +00:00
|
|
|
except Exception as _:
|
2022-07-05 10:42:47 +00:00
|
|
|
return
|
|
|
|
try:
|
2024-08-07 15:33:57 +00:00
|
|
|
msg_ = await client.listen(
|
|
|
|
chat.id, filters=filters.user(user.id), timeout=VERIFY_TIME
|
|
|
|
)
|
|
|
|
await msg.delay_delete(1)
|
|
|
|
await msg_.delay_delete(1)
|
2022-07-05 10:42:47 +00:00
|
|
|
if not msg_.sticker:
|
2024-08-07 15:33:57 +00:00
|
|
|
await reply_to.delay_delete(1)
|
2023-09-11 13:05:50 +00:00
|
|
|
if member.status not in [
|
|
|
|
ChatMemberStatus.OWNER,
|
|
|
|
ChatMemberStatus.ADMINISTRATOR,
|
|
|
|
]:
|
2024-08-07 15:33:57 +00:00
|
|
|
add_ban_chat_member_job(chat.id, user.id)
|
|
|
|
await log(chat, user, LogAction.FAIL_ERROR)
|
2022-07-05 10:42:47 +00:00
|
|
|
else:
|
2024-08-07 15:33:57 +00:00
|
|
|
await cache.delete(key)
|
|
|
|
await log(chat, user, LogAction.ACCEPT)
|
2022-07-05 10:42:47 +00:00
|
|
|
except TimeoutConversationError:
|
2024-08-07 15:33:57 +00:00
|
|
|
await msg.delay_delete(1)
|
|
|
|
await reply_to.delay_delete(1)
|
2023-09-11 13:05:50 +00:00
|
|
|
if member.status not in [
|
|
|
|
ChatMemberStatus.OWNER,
|
|
|
|
ChatMemberStatus.ADMINISTRATOR,
|
|
|
|
]:
|
2024-08-07 15:33:57 +00:00
|
|
|
add_ban_chat_member_job(chat.id, user.id)
|
|
|
|
await log(chat, user, LogAction.FAIL_TIMEOUT)
|