From 7d52e23522a3a89bbe3e936899e6dab7ef9249ae Mon Sep 17 00:00:00 2001 From: grassblock Date: Sat, 2 Aug 2025 21:07:15 +0800 Subject: [PATCH] feat: add /ping & /tips command --- adapters/tg.py | 5 ++++- core/simple.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/adapters/tg.py b/adapters/tg.py index ff8f14c..01162c4 100644 --- a/adapters/tg.py +++ b/adapters/tg.py @@ -18,7 +18,8 @@ from core.post_to_fedi import handle_auth, handle_post_to_fedi from core.promote import handle_promote_command from core.repeater import MessageRepeater from core.report_links import report_broken_links -from core.simple import handle_start_command, handle_baka, dummy_handler, handle_info_command +from core.simple import handle_start_command, handle_baka, dummy_handler, handle_info_command, handle_ping_command, \ + handle_tips_command from core.actions import handle_actions, handle_reverse_actions from core.stats import handle_stats_command from core.middleware.stats import MessageStatsMiddleware @@ -45,6 +46,8 @@ class TelegramAdapter: # Register handlers on router router.message(CommandStart())(handle_start_command) router.message(Command('info'))(handle_info_command) + router.message(Command('ping'))(handle_ping_command) + router.message(Command('tips'))(handle_tips_command) # bitflip 模块 router.message(Command('bitflip'))(handle_bitflip_command) # promote 模块 diff --git a/core/simple.py b/core/simple.py index 2faf463..b388144 100644 --- a/core/simple.py +++ b/core/simple.py @@ -1,3 +1,5 @@ +import asyncio + from aiogram import html from aiogram.types import Message @@ -24,6 +26,35 @@ async def handle_info_command(message: Message) -> None: ) await message.reply(response) +async def handle_ping_command(message: Message) -> None: + """Handle /ping command""" + import time + user_sent_time = message.date.timestamp() + bot_time_now = time.time() + time_diff = bot_time_now - user_sent_time + response = f"Pong! Time taken: {round(time_diff * 1000, 2)} milliseconds" + await message.reply(response) + +async def handle_tips_command(message: Message) -> None: + """Handle /tips command""" + tips = [ + "你知道吗:其实 tips 都是废话(确信", + "如果 bot 没有回复链接,说明链接不需要被清理", + "不管如何,你今天都很棒!", + "这个 bot 暂时还跑在一台运行着 Arch Linux 的笔电上", + "/ping 命令其实显示的是 bot 到 Telegram 服务器的延迟,而不是用户到 bot 的延迟", + "bot 的链接清理功能其实大多归功于 ➗ Actually Legitimate URL Shortener Tool 规则集", + "bot 的功能可以被选择性的开启或者关闭,但是示例 bot 为了方便开发和测试,默认开启了所有功能", + "说真的,你应该去看看 @kmuav2bot", + "任何一条 tips 消息都会在一分钟后自动消失,再也不用担心消息堆积了", + ] + import random + response = random.choice(tips) + tips_message = await message.reply(response) + # Delete the message after 1 minute + await asyncio.sleep(60) + await tips_message.delete() + async def dummy_handler(message: Message) -> None: """A handler to catch all other messages""" pass \ No newline at end of file