bot commited on
Commit
900f8d5
·
1 Parent(s): 25671c8

添加分享功能

Browse files
Files changed (1) hide show
  1. main.py +26 -1
main.py CHANGED
@@ -150,6 +150,7 @@ TG_BASE_URL = "https://tg.alist.dpdns.org/bot"
150
 
151
 
152
  ###################TG机器人功能区###################
 
153
  # 定义命令处理函数
154
  async def start(update: Update, context):
155
  commands = (
@@ -253,6 +254,10 @@ async def tg_show_files(update: Update, context: CallbackContext):
253
  f"删除",
254
  callback_data=f"del_f:{file['id']}:{file['parent_id']}",
255
  ),
 
 
 
 
256
  ]
257
  )
258
  else:
@@ -266,6 +271,10 @@ async def tg_show_files(update: Update, context: CallbackContext):
266
  f"删除",
267
  callback_data=f"del_f:{file['id']}:{file['parent_id']}",
268
  ),
 
 
 
 
269
  ]
270
  )
271
 
@@ -358,6 +367,10 @@ async def perform_file_action(
358
  f"删除",
359
  callback_data=f"del_f:{file['id']}:{file['parent_id']}",
360
  ),
 
 
 
 
361
  ]
362
  )
363
  else:
@@ -371,6 +384,10 @@ async def perform_file_action(
371
  f"删除",
372
  callback_data=f"del_f:{file['id']}:{file['parent_id']}",
373
  ),
 
 
 
 
374
  ]
375
  )
376
 
@@ -392,6 +409,12 @@ async def perform_file_action(
392
  )
393
  else:
394
  await update.callback_query.edit_message_text(f"❌未找到文件下载地址!!")
 
 
 
 
 
 
395
 
396
 
397
  #################### 离线任务处理 ##########################
@@ -592,7 +615,9 @@ async def init_client():
592
  ########## 文件操作 ###############
593
 
594
  TG_BOT_APPLICATION.add_handler(
595
- CallbackQueryHandler(handle_file_operation, pattern="^(del_f|ls_f|dw_f):")
 
 
596
  )
597
  # 处理取消任务操作
598
  TG_BOT_APPLICATION.add_handler(
 
150
 
151
 
152
  ###################TG机器人功能区###################
153
+ # ❗❗❗❗❗❗❗❗❗注意TG机器人callbackdata不能超过64位,否则会报无效按钮的错误
154
  # 定义命令处理函数
155
  async def start(update: Update, context):
156
  commands = (
 
254
  f"删除",
255
  callback_data=f"del_f:{file['id']}:{file['parent_id']}",
256
  ),
257
+ InlineKeyboardButton(
258
+ f"分享",
259
+ callback_data=f"sh_f:{file['id']}:{file['parent_id']}",
260
+ ),
261
  ]
262
  )
263
  else:
 
271
  f"删除",
272
  callback_data=f"del_f:{file['id']}:{file['parent_id']}",
273
  ),
274
+ InlineKeyboardButton(
275
+ f"分享",
276
+ callback_data=f"sh_f:{file['id']}:{file['parent_id']}",
277
+ ),
278
  ]
279
  )
280
 
 
367
  f"删除",
368
  callback_data=f"del_f:{file['id']}:{file['parent_id']}",
369
  ),
370
+ InlineKeyboardButton(
371
+ f"分享",
372
+ callback_data=f"sh_f:{file['id']}:{file['parent_id']}",
373
+ ),
374
  ]
375
  )
376
  else:
 
384
  f"删除",
385
  callback_data=f"del_f:{file['id']}:{file['parent_id']}",
386
  ),
387
+ InlineKeyboardButton(
388
+ f"分享",
389
+ callback_data=f"sh_f:{file['id']}:{file['parent_id']}",
390
+ ),
391
  ]
392
  )
393
 
 
409
  )
410
  else:
411
  await update.callback_query.edit_message_text(f"❌未找到文件下载地址!!")
412
+ elif action == "sh_f":
413
+ result = await THUNDERX_CLIENT.file_batch_share([file_id], False, -1)
414
+ if result["share_id"] is not None:
415
+ await update.callback_query.edit_message_text(f"✅分享码为:{result["share_id"]}")
416
+ else:
417
+ await update.callback_query.edit_message_text(f"❌分享失败!!")
418
 
419
 
420
  #################### 离线任务处理 ##########################
 
615
  ########## 文件操作 ###############
616
 
617
  TG_BOT_APPLICATION.add_handler(
618
+ CallbackQueryHandler(
619
+ handle_file_operation, pattern="^(del_f|ls_f|dw_f|sh_f):"
620
+ )
621
  )
622
  # 处理取消任务操作
623
  TG_BOT_APPLICATION.add_handler(