优化路径
This commit is contained in:
25
bot/app.py
25
bot/app.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user