feat: auto delete bot start message
All checks were successful
Docker Build / docker build and publish (push) Successful in 1m12s

This commit is contained in:
xtaodada 2024-05-16 21:11:12 +08:00
parent d3246af110
commit aec2d3b546
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -1,8 +1,12 @@
import contextlib
from datetime import datetime, timedelta
from pyrogram import filters from pyrogram import filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton from pyrogram.enums import ChatType
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message
from src.bot import bot from src.bot import bot
from src.services.scheduler import scheduler
HELP_MSG = "此 BOT 将会自动回复可以转换成 Telegram 预览的 URL 链接,可以提供更直观、方便的浏览体验。" HELP_MSG = "此 BOT 将会自动回复可以转换成 Telegram 预览的 URL 链接,可以提供更直观、方便的浏览体验。"
TEST_URL = "https://m.miyoushe.com/ys?channel=xiaomi/#/article/51867765" TEST_URL = "https://m.miyoushe.com/ys?channel=xiaomi/#/article/51867765"
@ -21,10 +25,26 @@ def get_test_button() -> InlineKeyboardMarkup:
) )
async def delete_message(message: Message):
with contextlib.suppress(Exception):
await message.delete()
def add_delete_message_task(message: Message):
scheduler.add_job(
delete_message,
"date",
run_date=datetime.now() + timedelta(seconds=60),
args=(message,),
)
@bot.on_message(filters=filters.command("start")) @bot.on_message(filters=filters.command("start"))
async def start(_, message): async def start(_, message: "Message"):
await message.reply_text( reply = await message.reply_text(
HELP_MSG, HELP_MSG,
quote=True, quote=True,
reply_markup=get_test_button(), reply_markup=get_test_button(),
) )
if message.chat and message.chat.type in [ChatType.GROUP, ChatType.SUPERGROUP]:
add_delete_message_task(reply)