sticker-captcha-bot/plugins/reverify.py

83 lines
3.0 KiB
Python
Raw Normal View History

2022-07-05 10:42:47 +00:00
import contextlib
from pyrogram import filters
from pyrogram.enums import ChatMemberStatus
from datetime import datetime, timedelta
2024-01-22 13:01:59 +00:00
from plugins.languages import RE_MSG, VERIFY_TIME
2022-07-05 10:42:47 +00:00
from pyromod.utils.errors import TimeoutConversationError
2022-07-05 10:50:39 +00:00
from sticker.scheduler import add_delete_message_job
2022-07-05 10:42:47 +00:00
from sticker.single_utils import Message, Client
from sticker import bot, log
@bot.on_message(filters=filters.group & filters.command("reverify"))
async def re_verify(client: Client, message: Message):
if not message.from_user or not message.reply_to_message:
2022-07-05 10:50:39 +00:00
msg: Message = await message.reply("请回复一条消息来使 Ta 重新验证。")
2022-07-05 10:52:18 +00:00
add_delete_message_job(message, 10)
2022-07-05 10:50:39 +00:00
add_delete_message_job(msg, 10)
2022-07-05 10:42:47 +00:00
return
if not message.reply_to_message.from_user:
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
user = message.reply_to_message.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)
2022-07-05 10:42:47 +00:00
with contextlib.suppress(Exception):
await message.delete()
try:
2024-01-22 13:01:59 +00:00
msg = await message.reply_to_message.reply(RE_MSG % user.mention)
2023-09-11 12:48:52 +00:00
except Exception as _:
2022-07-05 10:42:47 +00:00
return
try:
2024-01-22 13:01:59 +00:00
msg_ = await client.listen(chat.id, filters=filters.user(user.id), timeout=VERIFY_TIME)
2022-07-05 10:42:47 +00:00
with contextlib.suppress(Exception):
await msg.delete()
if not msg_.sticker:
with contextlib.suppress(Exception):
await message.reply_to_message.delete()
2023-09-11 13:05:50 +00:00
if member.status not in [
ChatMemberStatus.OWNER,
ChatMemberStatus.ADMINISTRATOR,
]:
2022-07-05 10:50:39 +00:00
with contextlib.suppress(Exception):
2023-09-11 13:05:50 +00:00
await bot.ban_chat_member(
chat.id, user.id, datetime.now() + timedelta(minutes=5)
)
2022-07-05 10:42:47 +00:00
with contextlib.suppress(Exception):
await log(chat, user, "FAIL_ERROR")
else:
with contextlib.suppress(Exception):
await log(chat, user, "ACCEPT")
with contextlib.suppress(Exception):
await msg_.delete()
except TimeoutConversationError:
with contextlib.suppress(Exception):
await msg.delete()
with contextlib.suppress(Exception):
await message.reply_to_message.delete()
2023-09-11 13:05:50 +00:00
if member.status not in [
ChatMemberStatus.OWNER,
ChatMemberStatus.ADMINISTRATOR,
]:
2022-07-05 10:50:39 +00:00
with contextlib.suppress(Exception):
2023-09-11 13:05:50 +00:00
await bot.ban_chat_member(
chat.id, user.id, datetime.now() + timedelta(minutes=5)
)
2022-07-05 10:42:47 +00:00
with contextlib.suppress(Exception):
await log(chat, user, "FAIL_TIMEOUT")