bot
commited on
Commit
·
080894c
1
Parent(s):
c68ac88
Fix
Browse files
main.py
CHANGED
@@ -357,41 +357,10 @@ async def perform_task_action(
|
|
357 |
await update.callback_query.edit_message_text(f"你选择了取消任务:{file_id}")
|
358 |
|
359 |
|
360 |
-
# 在 FastAPI 中启动 Telegram Bot 的异步任务
|
361 |
-
async def run_telegram_bot():
|
362 |
-
# 创建 Application 对象
|
363 |
-
global TG_BOT_APPLICATION
|
364 |
-
TG_BOT_APPLICATION = (
|
365 |
-
Application.builder().base_url(TG_BASE_URL).token(TG_BOT_TOKEN).build()
|
366 |
-
)
|
367 |
-
# await TG_BOT_APPLICATION.bot.delete_webhook()
|
368 |
-
await TG_BOT_APPLICATION.bot.set_webhook(TG_WEBHOOK_URL)
|
369 |
-
await TG_BOT_APPLICATION.initialize()
|
370 |
-
# 将命令处理函数添加到 dispatcher
|
371 |
-
TG_BOT_APPLICATION.add_handler(CommandHandler("start", start))
|
372 |
-
TG_BOT_APPLICATION.add_handler(CommandHandler("help", help))
|
373 |
-
TG_BOT_APPLICATION.add_handler(CommandHandler("quota", quota))
|
374 |
-
TG_BOT_APPLICATION.add_handler(CommandHandler("emptytrash", tg_emptytrash))
|
375 |
-
TG_BOT_APPLICATION.add_handler(CommandHandler("tasks", tg_show_task))
|
376 |
-
TG_BOT_APPLICATION.add_handler(
|
377 |
-
CallbackQueryHandler(handle_tasks_operation, pattern="^delete_task:")
|
378 |
-
)
|
379 |
-
# 处理取消任务操作
|
380 |
-
TG_BOT_APPLICATION.add_handler(
|
381 |
-
CallbackQueryHandler(handle_task_cancel, pattern="^cancel_task")
|
382 |
-
)
|
383 |
-
# 处理确认操作(确认删除、复制等)
|
384 |
-
TG_BOT_APPLICATION.add_handler(
|
385 |
-
CallbackQueryHandler(handle_task_confirmation, pattern="^confirm_task")
|
386 |
-
)
|
387 |
-
|
388 |
-
# 启动机器人
|
389 |
-
await TG_BOT_APPLICATION.run_polling()
|
390 |
-
|
391 |
-
|
392 |
@app.on_event("startup")
|
393 |
async def init_client():
|
394 |
global THUNDERX_CLIENT
|
|
|
395 |
if not os.path.exists("thunderx.txt"):
|
396 |
THUNDERX_CLIENT = PikPakApi(
|
397 |
username=THUNDERX_USERNAME,
|
@@ -421,7 +390,29 @@ async def init_client():
|
|
421 |
if TG_BOT_TOKEN is None:
|
422 |
print("未设置TG_BOT_TOKEN无法实现TG机器人功能!")
|
423 |
else:
|
424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
|
426 |
|
427 |
# FastAPI 路由:接收来自 Telegram 的 Webhook 回调
|
|
|
357 |
await update.callback_query.edit_message_text(f"你选择了取消任务:{file_id}")
|
358 |
|
359 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
360 |
@app.on_event("startup")
|
361 |
async def init_client():
|
362 |
global THUNDERX_CLIENT
|
363 |
+
global TG_BOT_APPLICATION
|
364 |
if not os.path.exists("thunderx.txt"):
|
365 |
THUNDERX_CLIENT = PikPakApi(
|
366 |
username=THUNDERX_USERNAME,
|
|
|
390 |
if TG_BOT_TOKEN is None:
|
391 |
print("未设置TG_BOT_TOKEN无法实现TG机器人功能!")
|
392 |
else:
|
393 |
+
TG_BOT_APPLICATION = (
|
394 |
+
Application.builder().base_url(TG_BASE_URL).token(TG_BOT_TOKEN).build()
|
395 |
+
)
|
396 |
+
# await TG_BOT_APPLICATION.bot.delete_webhook()
|
397 |
+
await TG_BOT_APPLICATION.bot.set_webhook(TG_WEBHOOK_URL)
|
398 |
+
await TG_BOT_APPLICATION.initialize()
|
399 |
+
# 将命令处理函数添加到 dispatcher
|
400 |
+
TG_BOT_APPLICATION.add_handler(CommandHandler("start", start))
|
401 |
+
TG_BOT_APPLICATION.add_handler(CommandHandler("help", help))
|
402 |
+
TG_BOT_APPLICATION.add_handler(CommandHandler("quota", quota))
|
403 |
+
TG_BOT_APPLICATION.add_handler(CommandHandler("emptytrash", tg_emptytrash))
|
404 |
+
TG_BOT_APPLICATION.add_handler(CommandHandler("tasks", tg_show_task))
|
405 |
+
TG_BOT_APPLICATION.add_handler(
|
406 |
+
CallbackQueryHandler(handle_tasks_operation, pattern="^delete_task:")
|
407 |
+
)
|
408 |
+
# 处理取消任务操作
|
409 |
+
TG_BOT_APPLICATION.add_handler(
|
410 |
+
CallbackQueryHandler(handle_task_cancel, pattern="^cancel_task")
|
411 |
+
)
|
412 |
+
# 处理确认操作(确认删除、复制等)
|
413 |
+
TG_BOT_APPLICATION.add_handler(
|
414 |
+
CallbackQueryHandler(handle_task_confirmation, pattern="^confirm_task")
|
415 |
+
)
|
416 |
|
417 |
|
418 |
# FastAPI 路由:接收来自 Telegram 的 Webhook 回调
|