优化路径

This commit is contained in:
dela
2026-01-30 11:08:22 +08:00
parent 9b7ecb7b80
commit cd53c4892f
3 changed files with 60 additions and 1 deletions

View File

@@ -2,12 +2,30 @@
Telegram Bot Application 创建模块
"""
from telegram import BotCommand
from telegram.ext import Application, CommandHandler
from config import AppConfig
from bot.handlers import start, go, status, settings
# 定义命令菜单
BOT_COMMANDS = [
BotCommand("start", "开始使用 / 欢迎信息"),
BotCommand("go", "生成支付链接 [数量] [plus/pro]"),
BotCommand("status", "查看任务状态 [task_id]"),
BotCommand("set", "用户设置 (并发数等)"),
BotCommand("help", "查看详细帮助"),
]
async def post_init(application: Application) -> None:
"""
Bot 初始化后设置命令菜单
"""
await application.bot.set_my_commands(BOT_COMMANDS)
def create_application(config: AppConfig) -> Application:
"""
创建并配置 Telegram Bot Application
@@ -22,7 +40,12 @@ def create_application(config: AppConfig) -> Application:
raise ValueError("TELEGRAM_BOT_TOKEN is not configured")
# 创建 Application
application = Application.builder().token(config.telegram_bot_token).build()
application = (
Application.builder()
.token(config.telegram_bot_token)
.post_init(post_init)
.build()
)
# 存储配置到 bot_data 供 handlers 使用
application.bot_data["config"] = config