bot
commited on
Commit
·
c68ac88
1
Parent(s):
7e09f49
test
Browse files
main.py
CHANGED
@@ -320,7 +320,6 @@ async def tg_show_task(update: Update, context: CallbackContext):
|
|
320 |
|
321 |
# 处理任务操作的回调
|
322 |
async def handle_tasks_operation(update: Update, context: CallbackContext):
|
323 |
-
logging.debug(f"Received callback: {update.callback_query.data}") # 打印回调数据
|
324 |
query = update.callback_query
|
325 |
await query.answer()
|
326 |
|
@@ -358,10 +357,41 @@ async def perform_task_action(
|
|
358 |
await update.callback_query.edit_message_text(f"你选择了取消任务:{file_id}")
|
359 |
|
360 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
@app.on_event("startup")
|
362 |
async def init_client():
|
363 |
global THUNDERX_CLIENT
|
364 |
-
global TG_BOT_APPLICATION
|
365 |
if not os.path.exists("thunderx.txt"):
|
366 |
THUNDERX_CLIENT = PikPakApi(
|
367 |
username=THUNDERX_USERNAME,
|
@@ -391,29 +421,7 @@ async def init_client():
|
|
391 |
if TG_BOT_TOKEN is None:
|
392 |
print("未设置TG_BOT_TOKEN无法实现TG机器人功能!")
|
393 |
else:
|
394 |
-
|
395 |
-
Application.builder().base_url(TG_BASE_URL).token(TG_BOT_TOKEN).build()
|
396 |
-
)
|
397 |
-
# await TG_BOT_APPLICATION.bot.delete_webhook()
|
398 |
-
await TG_BOT_APPLICATION.bot.set_webhook(TG_WEBHOOK_URL)
|
399 |
-
await TG_BOT_APPLICATION.initialize()
|
400 |
-
# 将命令处理函数添加到 dispatcher
|
401 |
-
TG_BOT_APPLICATION.add_handler(CommandHandler("start", start))
|
402 |
-
TG_BOT_APPLICATION.add_handler(CommandHandler("help", help))
|
403 |
-
TG_BOT_APPLICATION.add_handler(CommandHandler("quota", quota))
|
404 |
-
TG_BOT_APPLICATION.add_handler(CommandHandler("emptytrash", tg_emptytrash))
|
405 |
-
TG_BOT_APPLICATION.add_handler(CommandHandler("tasks", tg_show_task))
|
406 |
-
TG_BOT_APPLICATION.add_handler(
|
407 |
-
CallbackQueryHandler(handle_tasks_operation, pattern="^delete_task:")
|
408 |
-
)
|
409 |
-
# 处理取消任务操作
|
410 |
-
TG_BOT_APPLICATION.add_handler(
|
411 |
-
CallbackQueryHandler(handle_task_cancel, pattern="^cancel_task")
|
412 |
-
)
|
413 |
-
# 处理确认操作(确认删除、复制等)
|
414 |
-
TG_BOT_APPLICATION.add_handler(
|
415 |
-
CallbackQueryHandler(handle_task_confirmation, pattern="^confirm_task")
|
416 |
-
)
|
417 |
|
418 |
|
419 |
# FastAPI 路由:接收来自 Telegram 的 Webhook 回调
|
|
|
320 |
|
321 |
# 处理任务操作的回调
|
322 |
async def handle_tasks_operation(update: Update, context: CallbackContext):
|
|
|
323 |
query = update.callback_query
|
324 |
await query.answer()
|
325 |
|
|
|
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 |
if TG_BOT_TOKEN is None:
|
422 |
print("未设置TG_BOT_TOKEN无法实现TG机器人功能!")
|
423 |
else:
|
424 |
+
asyncio.create_task(run_telegram_bot())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
|
426 |
|
427 |
# FastAPI 路由:接收来自 Telegram 的 Webhook 回调
|