mirror of
https://github.com/Xtao-Labs/sticker-captcha-bot.git
synced 2024-11-22 07:07:51 +00:00
fix a block bug
This commit is contained in:
parent
ba8e6beb2e
commit
262a93dd6f
@ -4,6 +4,7 @@ from pyrogram.types import ChatJoinRequest
|
||||
from pyrogram import filters
|
||||
|
||||
from sticker.single_utils import Client
|
||||
from sticker.scheduler import add_decline_request_job, rem_decline_request_job
|
||||
from sticker import bot, log
|
||||
|
||||
from pyromod.utils.errors import TimeoutConversationError
|
||||
@ -20,13 +21,18 @@ MSG_FAILURE = """验证失败,请重试。"""
|
||||
async def new_member(client: Client, chat_join_request: ChatJoinRequest):
|
||||
chat = chat_join_request.chat
|
||||
user = chat_join_request.from_user
|
||||
add_decline_request_job(chat_join_request)
|
||||
try:
|
||||
with contextlib.suppress(Exception):
|
||||
await log(chat, user, "REQUEST")
|
||||
await client.ask(user.id, MSG % chat.title, filters=filters.sticker, timeout=30)
|
||||
with contextlib.suppress(Exception):
|
||||
await client.send_message(user.id, MSG_SUCCESS)
|
||||
await chat_join_request.approve()
|
||||
with contextlib.suppress(Exception):
|
||||
await log(chat, user, "ACCEPT")
|
||||
with contextlib.suppress(Exception):
|
||||
rem_decline_request_job(chat_join_request)
|
||||
except TimeoutConversationError:
|
||||
with contextlib.suppress(Exception):
|
||||
await client.send_message(user.id, MSG_FAILURE)
|
||||
|
@ -20,7 +20,6 @@ async def chat_members_handle(client: Client, message: Message):
|
||||
if message.service != MessageServiceType.NEW_CHAT_MEMBERS:
|
||||
return
|
||||
chat = message.chat
|
||||
user = message.from_user
|
||||
if message.new_chat_members:
|
||||
for i in message.new_chat_members:
|
||||
if i.is_self:
|
||||
@ -33,6 +32,8 @@ async def chat_members_handle(client: Client, message: Message):
|
||||
except Exception as e:
|
||||
return
|
||||
try:
|
||||
with contextlib.suppress(Exception):
|
||||
await log(chat, user, "REQUEST")
|
||||
msg_ = await client.listen(chat.id, filters=filters.user(user.id), timeout=30)
|
||||
with contextlib.suppress(Exception):
|
||||
await msg.delete()
|
||||
|
@ -52,7 +52,8 @@ async def log(chat, user, action):
|
||||
if not Config.LOG_CHANNEL:
|
||||
return
|
||||
me = await bot.get_me()
|
||||
event = {"FAIL_ERROR": "回答错误", "FAIL_TIMEOUT": "回答超时", "ACCEPT": "通过验证", "NEW_GROUP": "加入群组"}
|
||||
event = {"FAIL_ERROR": "回答错误", "FAIL_TIMEOUT": "回答超时", "ACCEPT": "通过验证", "NEW_GROUP": "加入群组",
|
||||
"REQUEST": "发起验证"}
|
||||
msg = """#%s
|
||||
群组: %s
|
||||
群组id: <code>%s</code>
|
||||
|
@ -3,6 +3,8 @@ import datetime
|
||||
|
||||
import pytz
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from pyrogram.types import ChatJoinRequest
|
||||
|
||||
from sticker.single_utils import Message
|
||||
|
||||
scheduler = AsyncIOScheduler(timezone="Asia/ShangHai")
|
||||
@ -15,6 +17,13 @@ async def delete_message(message: Message) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
async def decline_request(chat_join_request: ChatJoinRequest):
|
||||
with contextlib.suppress(Exception):
|
||||
await chat_join_request.decline()
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def add_delete_message_job(message: Message, delete_seconds: int = 60):
|
||||
scheduler.add_job(
|
||||
delete_message, "date",
|
||||
@ -23,3 +32,18 @@ def add_delete_message_job(message: Message, delete_seconds: int = 60):
|
||||
args=[message],
|
||||
run_date=datetime.datetime.now(pytz.timezone("Asia/Shanghai")) + datetime.timedelta(seconds=delete_seconds),
|
||||
replace_existing=True)
|
||||
|
||||
|
||||
def add_decline_request_job(chat_join_request: ChatJoinRequest):
|
||||
scheduler.add_job(
|
||||
decline_request, "date",
|
||||
id=f"{chat_join_request.chat.id}|{chat_join_request.from_user.id}|decline_request",
|
||||
name=f"{chat_join_request.chat.id}|{chat_join_request.from_user.id}|decline_request",
|
||||
args=[chat_join_request],
|
||||
run_date=datetime.datetime.now(pytz.timezone("Asia/Shanghai")) + datetime.timedelta(seconds=60),
|
||||
replace_existing=True)
|
||||
|
||||
|
||||
def rem_decline_request_job(chat_join_request: ChatJoinRequest):
|
||||
if job := scheduler.get_job(f"{chat_join_request.chat.id}|{chat_join_request.from_user.id}|decline_request"):
|
||||
job.remove()
|
||||
|
Loading…
Reference in New Issue
Block a user