bot
commited on
Commit
·
ff1e26a
1
Parent(s):
0c8f612
任务列表
Browse files
main.py
CHANGED
@@ -2,8 +2,14 @@ import os
|
|
2 |
import asyncio
|
3 |
import json
|
4 |
import logging
|
5 |
-
from telegram import
|
6 |
-
from telegram.ext import
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
import httpx
|
8 |
|
9 |
from pikpakapi import PikPakApi
|
@@ -208,6 +214,148 @@ async def tg_emptytrash(update: Update, context):
|
|
208 |
await update.message.reply_text(f"✅操作成功")
|
209 |
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
@app.on_event("startup")
|
212 |
async def init_client():
|
213 |
global THUNDERX_CLIENT
|
@@ -252,6 +400,15 @@ async def init_client():
|
|
252 |
TG_BOT_APPLICATION.add_handler(CommandHandler("help", help))
|
253 |
TG_BOT_APPLICATION.add_handler(CommandHandler("quota", quota))
|
254 |
TG_BOT_APPLICATION.add_handler(CommandHandler("emptytrash", tg_emptytrash))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
|
257 |
# FastAPI 路由:接收来自 Telegram 的 Webhook 回调
|
|
|
2 |
import asyncio
|
3 |
import json
|
4 |
import logging
|
5 |
+
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
6 |
+
from telegram.ext import (
|
7 |
+
Application,
|
8 |
+
CommandHandler,
|
9 |
+
MessageHandler,
|
10 |
+
CallbackQueryHandler,
|
11 |
+
CallbackContext,
|
12 |
+
)
|
13 |
import httpx
|
14 |
|
15 |
from pikpakapi import PikPakApi
|
|
|
214 |
await update.message.reply_text(f"✅操作成功")
|
215 |
|
216 |
|
217 |
+
# 确认操作的回调
|
218 |
+
async def handle_task_confirmation(update: Update, context: CallbackContext):
|
219 |
+
query = update.callback_query
|
220 |
+
query.answer()
|
221 |
+
|
222 |
+
# 获取确认操作的类型和文件 ID
|
223 |
+
action, task_id = query.data.split(":")[0], query.data.split(":")[1]
|
224 |
+
|
225 |
+
if action == "confirm_task_delete_task":
|
226 |
+
await THUNDERX_CLIENT.delete_tasks([task_id])
|
227 |
+
query.edit_message_text(f"✅任务 {task_id} 已删除。")
|
228 |
+
|
229 |
+
|
230 |
+
async def handle_task_cancel(update: Update, context: CallbackContext):
|
231 |
+
query = update.callback_query
|
232 |
+
query.answer()
|
233 |
+
# 获取取消操作的类型和文件 ID
|
234 |
+
action, file_id = query.data.split(":")[0], query.data.split(":")[1]
|
235 |
+
# 返回文件夹列表
|
236 |
+
query.edit_message_text(f"操作已取消。\n返回文件列表...")
|
237 |
+
|
238 |
+
|
239 |
+
async def tg_show_task(update: Update, context: CallbackContext):
|
240 |
+
"""
|
241 |
+
{
|
242 |
+
"tasks": [
|
243 |
+
{
|
244 |
+
"kind": "drive#task",
|
245 |
+
"id": "VONrJ4Skj4Qs7ALhxXlFudfJAA",
|
246 |
+
"name": "Billy Elliot (2000) 1080p (Deep61)[TGx]",
|
247 |
+
"type": "offline",
|
248 |
+
"user_id": "2000403406",
|
249 |
+
"statuses": [],
|
250 |
+
"status_size": 2,
|
251 |
+
"params": {
|
252 |
+
"folder_type": "",
|
253 |
+
"predict_type": "1",
|
254 |
+
"url": "magnet:?xt=urn:btih:96451E6F1ADBC8827B43621B74EDB30DF45012D6"
|
255 |
+
},
|
256 |
+
"file_id": "VONrJ4dZ8zf9KVWQuVEKmW8sTT",
|
257 |
+
"file_name": "Billy Elliot (2000) 1080p (Deep61)[TGx]",
|
258 |
+
"file_size": "3748030421",
|
259 |
+
"message": "Task timeout",
|
260 |
+
"created_time": "2025-04-15T10:38:54.320+08:00",
|
261 |
+
"updated_time": "2025-04-17T10:39:12.189+08:00",
|
262 |
+
"third_task_id": "",
|
263 |
+
"phase": "PHASE_TYPE_ERROR",
|
264 |
+
"progress": 0,
|
265 |
+
"icon_link": "https://backstage-img.xunleix.com/65d616355857aef8af40b89f187a8cf2770cb0ce",
|
266 |
+
"callback": "",
|
267 |
+
"reference_resource": {
|
268 |
+
"@type": "type.googleapis.com/drive.ReferenceFile",
|
269 |
+
"kind": "drive#folder",
|
270 |
+
"id": "VONrJ4dZ8zf9KVWQuVEKmW8sTT",
|
271 |
+
"parent_id": "VONS0fwXf3FNvt-g_IlMVKPxAA",
|
272 |
+
"name": "Billy Elliot (2000) 1080p (Deep61)[TGx]",
|
273 |
+
"size": "3748030421",
|
274 |
+
"mime_type": "",
|
275 |
+
"icon_link": "https://backstage-img.xunleix.com/65d616355857aef8af40b89f187a8cf2770cb0ce",
|
276 |
+
"hash": "",
|
277 |
+
"phase": "PHASE_TYPE_ERROR",
|
278 |
+
"audit": null,
|
279 |
+
"thumbnail_link": "",
|
280 |
+
"params": {},
|
281 |
+
"space": "",
|
282 |
+
"medias": [],
|
283 |
+
"starred": false,
|
284 |
+
"tags": []
|
285 |
+
},
|
286 |
+
"space": ""
|
287 |
+
}
|
288 |
+
],
|
289 |
+
"next_page_token": "",
|
290 |
+
"expires_in": 60,
|
291 |
+
"expires_in_ms": 60000
|
292 |
+
}
|
293 |
+
"""
|
294 |
+
tasks = await THUNDERX_CLIENT.offline_list(
|
295 |
+
size=100,
|
296 |
+
next_page_token=None,
|
297 |
+
phase=None,
|
298 |
+
)
|
299 |
+
keyboard = []
|
300 |
+
|
301 |
+
if tasks["tasks"] is None:
|
302 |
+
await update.message.reply_text("❌未找到任务!!")
|
303 |
+
else:
|
304 |
+
# 为每个文件创建按钮和操作选项
|
305 |
+
for task in tasks["tasks"]:
|
306 |
+
# 为每个文件添加操作按钮:删除
|
307 |
+
keyboard.append(
|
308 |
+
[
|
309 |
+
InlineKeyboardButton(
|
310 |
+
f"取消 {task['name']}",
|
311 |
+
callback_data=f"delete_task:{task['id']}",
|
312 |
+
),
|
313 |
+
]
|
314 |
+
)
|
315 |
+
|
316 |
+
reply_markup = InlineKeyboardMarkup(keyboard)
|
317 |
+
await update.message.reply_text(f"📋任务列表:", reply_markup=reply_markup)
|
318 |
+
|
319 |
+
|
320 |
+
# 处理任务操作的回调
|
321 |
+
async def handle_tasks_operation(update: Update, context: CallbackContext):
|
322 |
+
query = update.callback_query
|
323 |
+
query.answer()
|
324 |
+
|
325 |
+
# 获取操作类型和文件 ID
|
326 |
+
action, task_id = query.data.split(":")
|
327 |
+
|
328 |
+
# 需要确认的操作
|
329 |
+
if action in ["delete_task"]:
|
330 |
+
# 生成确认消息
|
331 |
+
keyboard = [
|
332 |
+
[
|
333 |
+
InlineKeyboardButton(
|
334 |
+
"确认", callback_data=f"confirm_task_{action}:{task_id}"
|
335 |
+
)
|
336 |
+
],
|
337 |
+
[
|
338 |
+
InlineKeyboardButton(
|
339 |
+
"取消", callback_data=f"cancel_task_{action}:{task_id}"
|
340 |
+
)
|
341 |
+
],
|
342 |
+
]
|
343 |
+
reply_markup = InlineKeyboardMarkup(keyboard)
|
344 |
+
query.edit_message_text(
|
345 |
+
f"你确定要{action}任务 {task_id} 吗?", reply_markup=reply_markup
|
346 |
+
)
|
347 |
+
else:
|
348 |
+
# 不需要确认的操作,直接处理
|
349 |
+
await perform_task_action(update, context, action, task_id)
|
350 |
+
|
351 |
+
|
352 |
+
async def perform_task_action(
|
353 |
+
update: Update, context: CallbackContext, action: str, file_id: str
|
354 |
+
):
|
355 |
+
if action == "cancel_task":
|
356 |
+
update.callback_query.edit_message_text(f"你选择了取消任务:{file_id}")
|
357 |
+
|
358 |
+
|
359 |
@app.on_event("startup")
|
360 |
async def init_client():
|
361 |
global THUNDERX_CLIENT
|
|
|
400 |
TG_BOT_APPLICATION.add_handler(CommandHandler("help", help))
|
401 |
TG_BOT_APPLICATION.add_handler(CommandHandler("quota", quota))
|
402 |
TG_BOT_APPLICATION.add_handler(CommandHandler("emptytrash", tg_emptytrash))
|
403 |
+
TG_BOT_APPLICATION.add_handler(CommandHandler("tasks", tg_show_task))
|
404 |
+
# 处理取消任务操作
|
405 |
+
TG_BOT_APPLICATION.add_handler(
|
406 |
+
CallbackQueryHandler(handle_task_cancel, pattern="^cancel_task")
|
407 |
+
)
|
408 |
+
# 处理确认操作(确认删除、复制等)
|
409 |
+
TG_BOT_APPLICATION.add_handler(
|
410 |
+
CallbackQueryHandler(handle_task_confirmation, pattern="^confirm_task")
|
411 |
+
)
|
412 |
|
413 |
|
414 |
# FastAPI 路由:接收来自 Telegram 的 Webhook 回调
|