🎨 Delete NEW_CHAT_MEMBERS message during group captcha

This commit is contained in:
洛水居室 2023-09-13 12:18:22 +08:00
parent aef1cb4c02
commit c2bcd0bf19
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -379,18 +379,11 @@ class GroupCaptcha(Plugin):
), ),
] ]
) )
if new_chat_members_message: reply_message = (
reply_message = ( f"*欢迎 {user.mention_markdown_v2()} 来到「提瓦特」世界!* \n"
f"*欢迎来到「提瓦特」世界!* \n" f"问题: {escape_markdown(question.text, version=2)} \n"
f"问题: {escape_markdown(question.text, version=2)} \n" f"请在*{self.time_out}*秒内回答问题"
f"请在*{self.time_out}*秒内回答问题" )
)
else:
reply_message = (
f"*欢迎 {user.mention_markdown_v2()} 来到「提瓦特」世界!* \n"
f"问题: {escape_markdown(question.text, version=2)} \n"
f"请在*{self.time_out}*秒内回答问题"
)
logger.debug( logger.debug(
"发送入群验证问题 %s[%s] \n%s[%s] 在 %s[%s]", "发送入群验证问题 %s[%s] \n%s[%s] 在 %s[%s]",
question.text, question.text,
@ -401,16 +394,11 @@ class GroupCaptcha(Plugin):
chat.id, chat.id,
) )
try: try:
if new_chat_members_message: question_message = await chat.send_message(
question_message = await new_chat_members_message.reply_markdown_v2( reply_message,
reply_message, reply_markup=InlineKeyboardMarkup(buttons), allow_sending_without_reply=True reply_markup=InlineKeyboardMarkup(buttons),
) parse_mode=ParseMode.MARKDOWN_V2,
else: )
question_message = await chat.send_message(
reply_message,
reply_markup=InlineKeyboardMarkup(buttons),
parse_mode=ParseMode.MARKDOWN_V2,
)
except BadRequest as exc: except BadRequest as exc:
await chat.send_message("派蒙分心了一下,不小心忘记你了,你只能先退出群再重新进来吧。") await chat.send_message("派蒙分心了一下,不小心忘记你了,你只能先退出群再重新进来吧。")
raise exc raise exc
@ -422,16 +410,6 @@ class GroupCaptcha(Plugin):
user_id=user.id, user_id=user.id,
job_kwargs={"replace_existing": True, "id": f"{chat.id}|{user.id}|auth_kick"}, job_kwargs={"replace_existing": True, "id": f"{chat.id}|{user.id}|auth_kick"},
) )
if new_chat_members_message:
context.job_queue.run_once(
callback=self.clean_message_job,
when=self.time_out,
data=new_chat_members_message.message_id,
name=f"{chat.id}|{user.id}|auth_clean_join_message",
chat_id=chat.id,
user_id=user.id,
job_kwargs={"replace_existing": True, "id": f"{chat.id}|{user.id}|auth_clean_join_message"},
)
context.job_queue.run_once( context.job_queue.run_once(
callback=self.clean_message_job, callback=self.clean_message_job,
when=self.time_out, when=self.time_out,
@ -441,6 +419,11 @@ class GroupCaptcha(Plugin):
user_id=user.id, user_id=user.id,
job_kwargs={"replace_existing": True, "id": f"{chat.id}|{user.id}|auth_clean_question_message"}, job_kwargs={"replace_existing": True, "id": f"{chat.id}|{user.id}|auth_clean_question_message"},
) )
try:
if new_chat_members_message:
await new_chat_members_message.delete()
except BadRequest as exc:
logger.warning("无法删除 Chat Members Message [%s]", exc.message)
if PYROGRAM_AVAILABLE and self.mtp: if PYROGRAM_AVAILABLE and self.mtp:
try: try:
if new_chat_members_message: if new_chat_members_message: