feat: add /ping & /tips command

This commit is contained in:
草师傅 2025-08-02 21:07:15 +08:00
parent 3cfc94b321
commit 7d52e23522
2 changed files with 35 additions and 1 deletions

View file

@ -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 模块

View file

@ -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