bot commited on
Commit
007372a
·
1 Parent(s): de41578
Files changed (1) hide show
  1. main.py +18 -21
main.py CHANGED
@@ -247,11 +247,11 @@ async def tg_show_files(update: Update, context: CallbackContext):
247
  [
248
  InlineKeyboardButton(
249
  f"查看📁: {file['name']}",
250
- callback_data=f"list_file:{file['id']}:{file['parent_id']}",
251
  ),
252
  InlineKeyboardButton(
253
  f"删除",
254
- callback_data=f"delete_file:{file['id']}:{file['parent_id']}",
255
  ),
256
  ]
257
  )
@@ -260,11 +260,11 @@ async def tg_show_files(update: Update, context: CallbackContext):
260
  [
261
  InlineKeyboardButton(
262
  f"下载📄: {file['name']}",
263
- callback_data=f"download_file:{file['id']}:{file['parent_id']}",
264
  ),
265
  InlineKeyboardButton(
266
  f"删除",
267
- callback_data=f"delete_file:{file['id']}:{file['parent_id']}",
268
  ),
269
  ]
270
  )
@@ -284,7 +284,7 @@ async def handle_file_confirmation(update: Update, context: CallbackContext):
284
  query.data.split(":")[2],
285
  )
286
 
287
- if action == "confirm_file_delete_file":
288
  await THUNDERX_CLIENT.delete_forever([file_id])
289
  await query.edit_message_text(f"✅文件 {file_id} 已删除。")
290
 
@@ -315,17 +315,17 @@ async def handle_file_operation(update: Update, context: CallbackContext):
315
  )
316
 
317
  # 需要确认的操作
318
- if action in ["delete_file"]:
319
  # 生成确认消息
320
  keyboard = [
321
  [
322
  InlineKeyboardButton(
323
- "确认", callback_data=f"confirm_file_{action}:{file_id}:{parent_id}"
324
  )
325
  ],
326
  [
327
  InlineKeyboardButton(
328
- "取消", callback_data=f"cancel_file_{action}:{file_id}:{parent_id}"
329
  )
330
  ],
331
  ]
@@ -342,7 +342,7 @@ async def perform_file_action(
342
  update: Update, context: CallbackContext, action: str, file_id: str, parent_id: str
343
  ):
344
 
345
- if action == "list_file":
346
  files = await THUNDERX_CLIENT.file_list(100, file_id, "", {})
347
  keyboard = []
348
 
@@ -353,38 +353,35 @@ async def perform_file_action(
353
  [
354
  InlineKeyboardButton(
355
  f"↩️返回上级",
356
- callback_data=f"list_file:{parent_id}:{parent_id}",
357
  ),
358
  ]
359
  )
360
  # 为每个文件创建按钮和操作选项
361
  for file in files["files"]:
362
- print(file["kind"].lower())
363
  if file["kind"].lower() == "drive#folder":
364
- print(file["parent_id"])
365
  keyboard.append(
366
  [
367
  InlineKeyboardButton(
368
  f"查看📁: {file['name']}",
369
- callback_data=f"list_file:{file['id']}:{file['parent_id']}",
370
  ),
371
  InlineKeyboardButton(
372
  f"删除",
373
- callback_data=f"delete_file:{file['id']}:{file['parent_id']}",
374
  ),
375
  ]
376
  )
377
  else:
378
- print(file["parent_id"])
379
  keyboard.append(
380
  [
381
  InlineKeyboardButton(
382
  f"下载📄: {file['name']}",
383
- callback_data=f"download_file:{file['id']}:{file['parent_id']}",
384
  ),
385
  InlineKeyboardButton(
386
  f"删除",
387
- callback_data=f"delete_file:{file['id']}:{file['parent_id']}",
388
  ),
389
  ]
390
  )
@@ -394,7 +391,7 @@ async def perform_file_action(
394
  await update.callback_query.edit_message_text(
395
  f"📋文件列表:", reply_markup=reply_markup
396
  )
397
- elif action == "download_file":
398
  result = await THUNDERX_CLIENT.get_download_url(file_id)
399
  download_url = result["web_content_link"]
400
  for media in result["medias"]:
@@ -608,16 +605,16 @@ async def init_client():
608
 
609
  TG_BOT_APPLICATION.add_handler(
610
  CallbackQueryHandler(
611
- handle_file_operation, pattern="^(delete_file|list_file|download_file):"
612
  )
613
  )
614
  # 处理取消任务操作
615
  TG_BOT_APPLICATION.add_handler(
616
- CallbackQueryHandler(handle_file_cancel, pattern="^cancel_file")
617
  )
618
  # 处理确认操作(确认删除、复制等)
619
  TG_BOT_APPLICATION.add_handler(
620
- CallbackQueryHandler(handle_file_confirmation, pattern="^confirm_file")
621
  )
622
 
623
  TG_BOT_APPLICATION.add_handler(CommandHandler("start", start))
 
247
  [
248
  InlineKeyboardButton(
249
  f"查看📁: {file['name']}",
250
+ callback_data=f"ls_file:{file['id']}:{file['parent_id']}",
251
  ),
252
  InlineKeyboardButton(
253
  f"删除",
254
+ callback_data=f"del_file:{file['id']}:{file['parent_id']}",
255
  ),
256
  ]
257
  )
 
260
  [
261
  InlineKeyboardButton(
262
  f"下载📄: {file['name']}",
263
+ callback_data=f"dw_file:{file['id']}:{file['parent_id']}",
264
  ),
265
  InlineKeyboardButton(
266
  f"删除",
267
+ callback_data=f"del_file:{file['id']}:{file['parent_id']}",
268
  ),
269
  ]
270
  )
 
284
  query.data.split(":")[2],
285
  )
286
 
287
+ if action == "confirm_file_del_file":
288
  await THUNDERX_CLIENT.delete_forever([file_id])
289
  await query.edit_message_text(f"✅文件 {file_id} 已删除。")
290
 
 
315
  )
316
 
317
  # 需要确认的操作
318
+ if action in ["del_file"]:
319
  # 生成确认消息
320
  keyboard = [
321
  [
322
  InlineKeyboardButton(
323
+ "确认", callback_data=f"yes_f_{action}:{file_id}:{parent_id}"
324
  )
325
  ],
326
  [
327
  InlineKeyboardButton(
328
+ "取消", callback_data=f"no_file_{action}:{file_id}:{parent_id}"
329
  )
330
  ],
331
  ]
 
342
  update: Update, context: CallbackContext, action: str, file_id: str, parent_id: str
343
  ):
344
 
345
+ if action == "ls_file":
346
  files = await THUNDERX_CLIENT.file_list(100, file_id, "", {})
347
  keyboard = []
348
 
 
353
  [
354
  InlineKeyboardButton(
355
  f"↩️返回上级",
356
+ callback_data=f"ls_file:{parent_id}:{parent_id}",
357
  ),
358
  ]
359
  )
360
  # 为每个文件创建按钮和操作选项
361
  for file in files["files"]:
 
362
  if file["kind"].lower() == "drive#folder":
 
363
  keyboard.append(
364
  [
365
  InlineKeyboardButton(
366
  f"查看📁: {file['name']}",
367
+ callback_data=f"ls_file:{file['id']}:{file['parent_id']}",
368
  ),
369
  InlineKeyboardButton(
370
  f"删除",
371
+ callback_data=f"del_file:{file['id']}:{file['parent_id']}",
372
  ),
373
  ]
374
  )
375
  else:
 
376
  keyboard.append(
377
  [
378
  InlineKeyboardButton(
379
  f"下载📄: {file['name']}",
380
+ callback_data=f"dw_file:{file['id']}:{file['parent_id']}",
381
  ),
382
  InlineKeyboardButton(
383
  f"删除",
384
+ callback_data=f"del_file:{file['id']}:{file['parent_id']}",
385
  ),
386
  ]
387
  )
 
391
  await update.callback_query.edit_message_text(
392
  f"📋文件列表:", reply_markup=reply_markup
393
  )
394
+ elif action == "dw_file":
395
  result = await THUNDERX_CLIENT.get_download_url(file_id)
396
  download_url = result["web_content_link"]
397
  for media in result["medias"]:
 
605
 
606
  TG_BOT_APPLICATION.add_handler(
607
  CallbackQueryHandler(
608
+ handle_file_operation, pattern="^(del_file|ls_file|dw_file):"
609
  )
610
  )
611
  # 处理取消任务操作
612
  TG_BOT_APPLICATION.add_handler(
613
+ CallbackQueryHandler(handle_file_cancel, pattern="^no_f")
614
  )
615
  # 处理确认操作(确认删除、复制等)
616
  TG_BOT_APPLICATION.add_handler(
617
+ CallbackQueryHandler(handle_file_confirmation, pattern="^yes_f")
618
  )
619
 
620
  TG_BOT_APPLICATION.add_handler(CommandHandler("start", start))