bot commited on
Commit
449b123
·
1 Parent(s): 6b0200f
Files changed (1) hide show
  1. main.py +35 -30
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']}",
251
  ),
252
  InlineKeyboardButton(
253
  f"删除",
254
- callback_data=f"delete_file:{file['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']}",
264
  ),
265
  InlineKeyboardButton(
266
  f"删除",
267
- callback_data=f"delete_file:{file['id']}",
268
  ),
269
  ]
270
  )
@@ -278,7 +278,11 @@ async def handle_file_confirmation(update: Update, context: CallbackContext):
278
  await query.answer()
279
 
280
  # 获取确认操作的类型和文件 ID
281
- action, file_id = query.data.split(":")[0], query.data.split(":")[1]
 
 
 
 
282
 
283
  if action == "confirm_file_delete_file":
284
  await THUNDERX_CLIENT.delete_forever([file_id])
@@ -289,7 +293,11 @@ async def handle_file_cancel(update: Update, context: CallbackContext):
289
  query = update.callback_query
290
  await query.answer()
291
  # 获取取消操作的类型和文件 ID
292
- action, file_id = query.data.split(":")[0], query.data.split(":")[1]
 
 
 
 
293
  # 返回文件夹列表
294
  await query.edit_message_text(f"操作已取消")
295
 
@@ -300,7 +308,11 @@ async def handle_file_operation(update: Update, context: CallbackContext):
300
  await query.answer()
301
 
302
  # 获取操作类型和文件 ID
303
- action, file_id = query.data.split(":")
 
 
 
 
304
 
305
  # 需要确认的操作
306
  if action in ["delete_file"]:
@@ -308,12 +320,12 @@ async def handle_file_operation(update: Update, context: CallbackContext):
308
  keyboard = [
309
  [
310
  InlineKeyboardButton(
311
- "确认", callback_data=f"confirm_file_{action}:{file_id}"
312
  )
313
  ],
314
  [
315
  InlineKeyboardButton(
316
- "取消", callback_data=f"cancel_file_{action}:{file_id}"
317
  )
318
  ],
319
  ]
@@ -323,35 +335,28 @@ async def handle_file_operation(update: Update, context: CallbackContext):
323
  )
324
  else:
325
  # 不需要确认的操作,直接处理
326
- await perform_file_action(update, context, action, file_id)
327
 
328
 
329
  async def perform_file_action(
330
- update: Update, context: CallbackContext, action: str, file_id: str
331
  ):
332
  if action == "list_file":
333
 
334
- print(f"actions is {action} file id is {file_id}")
335
-
336
- if file_id is None:
337
- file_id = ""
338
-
339
  files = await THUNDERX_CLIENT.file_list(100, file_id, "", {})
340
  keyboard = []
341
 
342
  if files["files"] is None:
343
  await update.message.reply_text("❌未找到文件!!")
344
  else:
345
- parent_id = files["files"][0]["parent_id"]
346
- if parent_id is not None:
347
- keyboard.append(
348
- [
349
- InlineKeyboardButton(
350
- f"返回上级",
351
- callback_data=f"list_file:{parent_id}",
352
- ),
353
- ]
354
- )
355
  # 为每个文件创��按钮和操作选项
356
  for file in files["files"]:
357
  if file["kind"].lower() == "drive#folder":
@@ -359,11 +364,11 @@ async def perform_file_action(
359
  [
360
  InlineKeyboardButton(
361
  f"查看📁: {file['name']}",
362
- callback_data=f"list_file:{file['id']}",
363
  ),
364
  InlineKeyboardButton(
365
  f"删除",
366
- callback_data=f"delete_file:{file['id']}",
367
  ),
368
  ]
369
  )
@@ -372,11 +377,11 @@ async def perform_file_action(
372
  [
373
  InlineKeyboardButton(
374
  f"下载📄: {file['name']}",
375
- callback_data=f"download_file:{file['id']}",
376
  ),
377
  InlineKeyboardButton(
378
  f"删除",
379
- callback_data=f"delete_file:{file['id']}",
380
  ),
381
  ]
382
  )
 
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
  [
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
  )
 
278
  await query.answer()
279
 
280
  # 获取确认操作的类型和文件 ID
281
+ action, file_id, parent_id = (
282
+ query.data.split(":")[0],
283
+ query.data.split(":")[1],
284
+ query.data.split(":")[2],
285
+ )
286
 
287
  if action == "confirm_file_delete_file":
288
  await THUNDERX_CLIENT.delete_forever([file_id])
 
293
  query = update.callback_query
294
  await query.answer()
295
  # 获取取消操作的类型和文件 ID
296
+ action, file_id, parent_id = (
297
+ query.data.split(":")[0],
298
+ query.data.split(":")[1],
299
+ query.data.split(":")[2],
300
+ )
301
  # 返回文件夹列表
302
  await query.edit_message_text(f"操作已取消")
303
 
 
308
  await query.answer()
309
 
310
  # 获取操作类型和文件 ID
311
+ action, file_id, parent_id = (
312
+ query.data.split(":")[0],
313
+ query.data.split(":")[1],
314
+ query.data.split(":")[2],
315
+ )
316
 
317
  # 需要确认的操作
318
  if action in ["delete_file"]:
 
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
  ]
 
335
  )
336
  else:
337
  # 不需要确认的操作,直接处理
338
+ await perform_file_action(update, context, action, file_id, parent_id)
339
 
340
 
341
  async def perform_file_action(
342
+ update: Update, context: CallbackContext, action: str, file_id: str, parent_id: str
343
  ):
344
  if action == "list_file":
345
 
 
 
 
 
 
346
  files = await THUNDERX_CLIENT.file_list(100, file_id, "", {})
347
  keyboard = []
348
 
349
  if files["files"] is None:
350
  await update.message.reply_text("❌未找到文件!!")
351
  else:
352
+ keyboard.append(
353
+ [
354
+ InlineKeyboardButton(
355
+ f"返回上级",
356
+ callback_data=f"list_file:{file_id}:{parent_id}",
357
+ ),
358
+ ]
359
+ )
 
 
360
  # 为每个文件创��按钮和操作选项
361
  for file in files["files"]:
362
  if file["kind"].lower() == "drive#folder":
 
364
  [
365
  InlineKeyboardButton(
366
  f"查看📁: {file['name']}",
367
+ callback_data=f"list_file:{file['id']}:{file['parent_id']}",
368
  ),
369
  InlineKeyboardButton(
370
  f"删除",
371
+ callback_data=f"delete_file:{file['id']}:{file['parent_id']}",
372
  ),
373
  ]
374
  )
 
377
  [
378
  InlineKeyboardButton(
379
  f"下载📄: {file['name']}",
380
+ callback_data=f"download_file:{file['id']}:{file['parent_id']}",
381
  ),
382
  InlineKeyboardButton(
383
  f"删除",
384
+ callback_data=f"delete_file:{file['id']}:{file['parent_id']}",
385
  ),
386
  ]
387
  )