Fyaz Mohammed commited on
Commit
7c1069f
·
unverified ·
1 Parent(s): 1a1e2eb

Fixed Batch Link

Browse files
Thunder/bot/plugins/admin.py CHANGED
@@ -93,7 +93,7 @@ async def get_total_users(client, message):
93
  try:
94
  total_users = await db.total_users_count()
95
  reply_markup = InlineKeyboardMarkup([
96
- [InlineKeyboardButton("🗙 Close", callback_data="close_panel")]
97
  ])
98
  await message.reply_text(
99
  MSG_DB_STATS.format(total_users=total_users),
@@ -289,7 +289,7 @@ async def show_status(client, message):
289
  version=__version__
290
  )
291
  reply_markup = InlineKeyboardMarkup([
292
- [InlineKeyboardButton("🗙 Close", callback_data="close_panel")]
293
  ])
294
  await message.reply_text(stats_text, parse_mode=ParseMode.MARKDOWN, reply_markup=reply_markup)
295
  except:
@@ -314,7 +314,7 @@ async def show_stats(client, message):
314
  disk_percent=psutil.disk_usage('.').percent
315
  )
316
  reply_markup = InlineKeyboardMarkup([
317
- [InlineKeyboardButton("🗙 Close", callback_data="close_panel")]
318
  ])
319
  await message.reply_text(stats_text, parse_mode=ParseMode.MARKDOWN, reply_markup=reply_markup)
320
  except:
@@ -399,7 +399,7 @@ async def list_authorized_command(client, message):
399
  auth_time=user['authorized_at']
400
  )
401
  reply_markup = InlineKeyboardMarkup([
402
- [InlineKeyboardButton("🗙 Close", callback_data="close_panel")]
403
  ])
404
  await message.reply_text(
405
  message_text,
@@ -550,7 +550,7 @@ async def close_panel(client, callback_query):
550
  async def restart_broadcast(client, callback_query):
551
  try:
552
  await callback_query.edit_message_text(
553
- "Please use `/broadcast` command with a reply to the message you want to broadcast.",
554
  parse_mode=ParseMode.MARKDOWN
555
  )
556
  except:
 
93
  try:
94
  total_users = await db.total_users_count()
95
  reply_markup = InlineKeyboardMarkup([
96
+ [InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")]
97
  ])
98
  await message.reply_text(
99
  MSG_DB_STATS.format(total_users=total_users),
 
289
  version=__version__
290
  )
291
  reply_markup = InlineKeyboardMarkup([
292
+ [InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")]
293
  ])
294
  await message.reply_text(stats_text, parse_mode=ParseMode.MARKDOWN, reply_markup=reply_markup)
295
  except:
 
314
  disk_percent=psutil.disk_usage('.').percent
315
  )
316
  reply_markup = InlineKeyboardMarkup([
317
+ [InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")]
318
  ])
319
  await message.reply_text(stats_text, parse_mode=ParseMode.MARKDOWN, reply_markup=reply_markup)
320
  except:
 
399
  auth_time=user['authorized_at']
400
  )
401
  reply_markup = InlineKeyboardMarkup([
402
+ [InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")]
403
  ])
404
  await message.reply_text(
405
  message_text,
 
550
  async def restart_broadcast(client, callback_query):
551
  try:
552
  await callback_query.edit_message_text(
553
+ MSG_ERROR_BROADCAST_INSTRUCTION,
554
  parse_mode=ParseMode.MARKDOWN
555
  )
556
  except:
Thunder/bot/plugins/callbacks.py CHANGED
@@ -59,7 +59,7 @@ async def help_callback(client: Client, callback_query: CallbackQuery):
59
  buttons.append(force_button)
60
 
61
  # Add close button at the end
62
- buttons.append([InlineKeyboardButton("🗙 Close", callback_data="close_panel")])
63
 
64
  await callback_query.message.edit_text(
65
  text=MSG_HELP,
@@ -85,7 +85,7 @@ async def about_callback(client: Client, callback_query: CallbackQuery):
85
  buttons = [
86
  [InlineKeyboardButton(MSG_BUTTON_GET_HELP, callback_data="help_command")],
87
  [InlineKeyboardButton(MSG_BUTTON_GITHUB, url="https://github.com/fyaz05/FileToLink"),
88
- InlineKeyboardButton("🗙 Close", callback_data="close_panel")]
89
  ]
90
 
91
  await callback_query.message.edit_text(
@@ -113,7 +113,7 @@ async def restart_broadcast_callback(client: Client, callback_query: CallbackQue
113
  # Create back and close buttons
114
  buttons = [
115
  [InlineKeyboardButton(MSG_BUTTON_GET_HELP, callback_data="help_command"),
116
- InlineKeyboardButton("🗙 Close", callback_data="close_panel")]
117
  ]
118
 
119
  await callback_query.message.edit_text(
 
59
  buttons.append(force_button)
60
 
61
  # Add close button at the end
62
+ buttons.append([InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")])
63
 
64
  await callback_query.message.edit_text(
65
  text=MSG_HELP,
 
85
  buttons = [
86
  [InlineKeyboardButton(MSG_BUTTON_GET_HELP, callback_data="help_command")],
87
  [InlineKeyboardButton(MSG_BUTTON_GITHUB, url="https://github.com/fyaz05/FileToLink"),
88
+ InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")]
89
  ]
90
 
91
  await callback_query.message.edit_text(
 
113
  # Create back and close buttons
114
  buttons = [
115
  [InlineKeyboardButton(MSG_BUTTON_GET_HELP, callback_data="help_command"),
116
+ InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")]
117
  ]
118
 
119
  await callback_query.message.edit_text(
Thunder/bot/plugins/common.py CHANGED
@@ -135,7 +135,7 @@ async def start_command(bot: Client, message: Message):
135
  ],
136
  [
137
  InlineKeyboardButton(MSG_BUTTON_GITHUB, url="https://github.com/fyaz05/FileToLink/"),
138
- InlineKeyboardButton("🗙 Close", callback_data="close_panel")
139
  ]
140
  ])
141
 
@@ -248,7 +248,7 @@ async def help_command(bot: Client, message: Message):
248
  except Exception as e_help:
249
  logger.error(f"(ID: {error_id_context_help}) Error adding force channel button to /help command (User: {user_id_str}, FChannel: {Var.FORCE_CHANNEL_ID}): {e_help}")
250
 
251
- buttons.append([InlineKeyboardButton("🗙 Close", callback_data="close_panel")])
252
  reply_markup = InlineKeyboardMarkup(buttons)
253
 
254
  await message.reply_text(
@@ -273,7 +273,7 @@ async def about_command(bot: Client, message: Message):
273
  buttons = [
274
  [InlineKeyboardButton(MSG_BUTTON_GET_HELP, callback_data="help_command")],
275
  [InlineKeyboardButton(MSG_BUTTON_GITHUB, url="https://github.com/fyaz05/FileToLink"),
276
- InlineKeyboardButton("🗙 Close", callback_data="close_panel")]
277
  ]
278
 
279
  reply_markup = InlineKeyboardMarkup(buttons)
@@ -310,7 +310,7 @@ async def dc_command(bot: Client, message: Message):
310
  InlineKeyboardButton(MSG_BUTTON_VIEW_PROFILE, url=profile_url)
311
  ])
312
  buttons.append([
313
- InlineKeyboardButton("🗙 Close", callback_data="close_panel")
314
  ])
315
  dc_keyboard = InlineKeyboardMarkup(buttons)
316
 
@@ -411,7 +411,7 @@ async def ping_command(bot: Client, message: Message):
411
  time_taken_ms = (end_time - start_time) * 1000
412
  buttons = [
413
  [InlineKeyboardButton(MSG_BUTTON_GET_HELP, callback_data="help_command"),
414
- InlineKeyboardButton("🗙 Close", callback_data="close_panel")]
415
  ]
416
 
417
  await sent_msg.edit_text(
 
135
  ],
136
  [
137
  InlineKeyboardButton(MSG_BUTTON_GITHUB, url="https://github.com/fyaz05/FileToLink/"),
138
+ InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")
139
  ]
140
  ])
141
 
 
248
  except Exception as e_help:
249
  logger.error(f"(ID: {error_id_context_help}) Error adding force channel button to /help command (User: {user_id_str}, FChannel: {Var.FORCE_CHANNEL_ID}): {e_help}")
250
 
251
+ buttons.append([InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")])
252
  reply_markup = InlineKeyboardMarkup(buttons)
253
 
254
  await message.reply_text(
 
273
  buttons = [
274
  [InlineKeyboardButton(MSG_BUTTON_GET_HELP, callback_data="help_command")],
275
  [InlineKeyboardButton(MSG_BUTTON_GITHUB, url="https://github.com/fyaz05/FileToLink"),
276
+ InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")]
277
  ]
278
 
279
  reply_markup = InlineKeyboardMarkup(buttons)
 
310
  InlineKeyboardButton(MSG_BUTTON_VIEW_PROFILE, url=profile_url)
311
  ])
312
  buttons.append([
313
+ InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")
314
  ])
315
  dc_keyboard = InlineKeyboardMarkup(buttons)
316
 
 
411
  time_taken_ms = (end_time - start_time) * 1000
412
  buttons = [
413
  [InlineKeyboardButton(MSG_BUTTON_GET_HELP, callback_data="help_command"),
414
+ InlineKeyboardButton(MSG_BUTTON_CLOSE, callback_data="close_panel")]
415
  ]
416
 
417
  await sent_msg.edit_text(
Thunder/bot/plugins/stream.py CHANGED
@@ -252,10 +252,12 @@ async def forward_media(media_message):
252
  for retry in range(3):
253
  try:
254
  result = await media_message.copy(chat_id=Var.BIN_CHANNEL)
 
255
  return result
256
  except Exception:
257
  try:
258
  result = await media_message.forward(chat_id=Var.BIN_CHANNEL)
 
259
  return result
260
  except FloodWait as flood_error:
261
  if retry < 2:
@@ -284,6 +286,7 @@ async def log_request(log_msg, user, stream_link, online_link):
284
  link_preview_options=LinkPreviewOptions(is_disabled=True),
285
  quote=True
286
  )
 
287
  except Exception:
288
  pass
289
 
@@ -497,17 +500,40 @@ async def process_multiple_messages(client, command_message, reply_msg, num_file
497
 
498
  for chunk in chunk_list(download_links, 20):
499
  links_text = "\n".join(chunk)
500
- batch_links_message = MSG_BATCH_LINKS_READY.format(
501
- count=len(chunk),
502
- links=links_text
503
- )
504
 
505
- await command_message.reply_text(
506
- batch_links_message,
507
- quote=True,
508
- link_preview_options=LinkPreviewOptions(is_disabled=True),
509
- parse_mode=enums.ParseMode.MARKDOWN
510
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
 
512
  if len(chunk) > 10:
513
  await asyncio.sleep(0.5)
@@ -639,7 +665,7 @@ async def link_handler(client, message, shortener=True):
639
  )
640
  await client.send_message(
641
  chat_id=message.from_user.id,
642
- text=MSG_BATCH_LINKS_FROM.format(
643
  chat_title=message.chat.title,
644
  links_message=msg_text
645
  ),
@@ -652,7 +678,8 @@ async def link_handler(client, message, shortener=True):
652
  ]
653
  ]),
654
  )
655
- except Exception:
 
656
  await message.reply_text(
657
  MSG_ERROR_DM_FAILED,
658
  quote=True
 
252
  for retry in range(3):
253
  try:
254
  result = await media_message.copy(chat_id=Var.BIN_CHANNEL)
255
+ await asyncio.sleep(0.1)
256
  return result
257
  except Exception:
258
  try:
259
  result = await media_message.forward(chat_id=Var.BIN_CHANNEL)
260
+ await asyncio.sleep(0.1)
261
  return result
262
  except FloodWait as flood_error:
263
  if retry < 2:
 
286
  link_preview_options=LinkPreviewOptions(is_disabled=True),
287
  quote=True
288
  )
289
+ await asyncio.sleep(0.3)
290
  except Exception:
291
  pass
292
 
 
500
 
501
  for chunk in chunk_list(download_links, 20):
502
  links_text = "\n".join(chunk)
 
 
 
 
503
 
504
+ # Message for the group chat
505
+ group_message_content = MSG_BATCH_LINKS_READY.format(count=len(chunk)) + f"\n\n`{links_text}`"
506
+
507
+ # Message for the user's DM
508
+ dm_prefix = MSG_DM_BATCH_PREFIX.format(chat_title=command_message.chat.title)
509
+ dm_message_text = f"{dm_prefix}\n{group_message_content}"
510
+
511
+ # Send to original chat (group/supergroup)
512
+ try:
513
+ await command_message.reply_text(
514
+ group_message_content,
515
+ quote=True,
516
+ link_preview_options=LinkPreviewOptions(is_disabled=True),
517
+ parse_mode=enums.ParseMode.MARKDOWN
518
+ )
519
+ except Exception as e:
520
+ logger.error(f"Error sending batch links to original chat {command_message.chat.id}: {e}")
521
+
522
+ # Send to user's DM (if in a group/supergroup)
523
+ if command_message.chat.type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
524
+ try:
525
+ await client.send_message(
526
+ chat_id=command_message.from_user.id,
527
+ text=dm_message_text,
528
+ link_preview_options=LinkPreviewOptions(is_disabled=True),
529
+ parse_mode=enums.ParseMode.MARKDOWN
530
+ )
531
+ except Exception as e:
532
+ logger.error(f"Error sending batch links to user DM {command_message.from_user.id}: {e}")
533
+ await command_message.reply_text(
534
+ MSG_ERROR_DM_FAILED,
535
+ quote=True
536
+ )
537
 
538
  if len(chunk) > 10:
539
  await asyncio.sleep(0.5)
 
665
  )
666
  await client.send_message(
667
  chat_id=message.from_user.id,
668
+ text=MSG_LINK_FROM_GROUP.format(
669
  chat_title=message.chat.title,
670
  links_message=msg_text
671
  ),
 
678
  ]
679
  ]),
680
  )
681
+ except Exception as e:
682
+ logger.debug(f"Error sending DM to user {message.from_user.id} from group: {e}")
683
  await message.reply_text(
684
  MSG_ERROR_DM_FAILED,
685
  quote=True
Thunder/utils/messages.py CHANGED
@@ -159,6 +159,7 @@ MSG_BUTTON_JOIN_CHANNEL = "📢 Join {channel_title}"
159
  MSG_BUTTON_GITHUB = "🛠️ GitHub"
160
  MSG_BUTTON_START_CHAT = "📩 Start Chat"
161
  MSG_BUTTON_JOIN_CHAT = "📢 Join {chat_title}"
 
162
 
163
  # ------ Quick Start Guide ------
164
  MSG_QUICK_START_GUIDE = (
@@ -221,7 +222,7 @@ MSG_HELP = (
221
 
222
  MSG_ABOUT = (
223
  "🌟 **About Thunder File to Link Bot** ℹ️\n\n"
224
- "I'm your go-to bot for **instant direct download & streaming links!** ⚡\n\n"
225
  "**🚀 Key Features:**\n"
226
  "> **Instant Links:** Get your links within seconds.\n"
227
  "> **Online Streaming:** Watch videos or listen to audio directly (for supported formats).\n"
@@ -309,8 +310,9 @@ MSG_NEW_FILE_REQUEST = (
309
  MSG_PROCESSING_BATCH = "🔄 **Processing Batch {batch_number}/{total_batches}** ({file_count} files)"
310
  MSG_PROCESSING_STATUS = "📊 **Processing Files:** {processed}/{total} complete, {failed} failed"
311
  MSG_PROCESSING_WARNING = "⚠️ **Warning:** Too many files failed processing. Please try again with fewer files or contact support."
312
- MSG_BATCH_LINKS_READY = "🔗 **Batch Links ({count} files):**\n\n`{links}`"
313
- MSG_BATCH_LINKS_FROM = "📬 **Links from {chat_title}**\n\n`{links_message}`"
 
314
  MSG_PROCESSING_RESULT = "✅ **Process Complete:** {processed}/{total} files processed successfully, {failed} failed"
315
  MSG_PROCESSING_ERROR = "❌ **Error Processing Files:** {error}\n\n{processed}/{total} files were processed (ID: {error_id})"
316
  MSG_RETRYING_FILES = "🔄 **Retrying {count} Failed Files...**"
@@ -337,15 +339,12 @@ MSG_ERROR_BROADCAST_INSTRUCTION = "To start a new broadcast, use the /broadcast
337
  MSG_ERROR_CALLBACK_UNSUPPORTED = "This button is not active or no longer supported."
338
  MSG_ERROR_GENERIC_CALLBACK = "An error occurred. Please try again later. (ID: {error_id})"
339
  MSG_BROADCAST_COMPLETE = (
340
- "📢 **Broadcast Completed Successfully!** 📢\n"
341
- "──────────────────────────────\n"
342
  "⏱️ **Duration:** `{elapsed_time}`\n"
343
  "👥 **Total Users:** `{total_users}`\n"
344
  "✅ **Successful Deliveries:** `{successes}`\n"
345
- "❌ **Failed Deliveries:** `{failures}`\n"
346
- "──────────────────────────────\n"
347
- "🗑️ **Accounts Removed (Blocked/Deactivated):** `{deleted_accounts}`\n" # Clarified
348
- "──────────────────────────────"
349
  )
350
  MSG_BROADCAST_CANCEL = "🛑 **Cancelling Broadcast:** `{broadcast_id}`\n\n> ⏳ Stopping operations..."
351
  MSG_BROADCAST_FAILED = (
 
159
  MSG_BUTTON_GITHUB = "🛠️ GitHub"
160
  MSG_BUTTON_START_CHAT = "📩 Start Chat"
161
  MSG_BUTTON_JOIN_CHAT = "📢 Join {chat_title}"
162
+ MSG_BUTTON_CLOSE = "✖ Close"
163
 
164
  # ------ Quick Start Guide ------
165
  MSG_QUICK_START_GUIDE = (
 
222
 
223
  MSG_ABOUT = (
224
  "🌟 **About Thunder File to Link Bot** ℹ️\n\n"
225
+ "I'm your go-to bot for **instant download & streaming!** ⚡\n\n"
226
  "**🚀 Key Features:**\n"
227
  "> **Instant Links:** Get your links within seconds.\n"
228
  "> **Online Streaming:** Watch videos or listen to audio directly (for supported formats).\n"
 
310
  MSG_PROCESSING_BATCH = "🔄 **Processing Batch {batch_number}/{total_batches}** ({file_count} files)"
311
  MSG_PROCESSING_STATUS = "📊 **Processing Files:** {processed}/{total} complete, {failed} failed"
312
  MSG_PROCESSING_WARNING = "⚠️ **Warning:** Too many files failed processing. Please try again with fewer files or contact support."
313
+ MSG_BATCH_LINKS_READY = "🔗 Here are your {count} download links:"
314
+ MSG_DM_BATCH_PREFIX = "📬 **Batch Links from {chat_title}**\n"
315
+ MSG_LINK_FROM_GROUP = "📬 **Links from {chat_title}**\n\n{links_message}"
316
  MSG_PROCESSING_RESULT = "✅ **Process Complete:** {processed}/{total} files processed successfully, {failed} failed"
317
  MSG_PROCESSING_ERROR = "❌ **Error Processing Files:** {error}\n\n{processed}/{total} files were processed (ID: {error_id})"
318
  MSG_RETRYING_FILES = "🔄 **Retrying {count} Failed Files...**"
 
339
  MSG_ERROR_CALLBACK_UNSUPPORTED = "This button is not active or no longer supported."
340
  MSG_ERROR_GENERIC_CALLBACK = "An error occurred. Please try again later. (ID: {error_id})"
341
  MSG_BROADCAST_COMPLETE = (
342
+ "📢 **Broadcast Completed Successfully!** 📢\n\n"
 
343
  "⏱️ **Duration:** `{elapsed_time}`\n"
344
  "👥 **Total Users:** `{total_users}`\n"
345
  "✅ **Successful Deliveries:** `{successes}`\n"
346
+ "❌ **Failed Deliveries:** `{failures}`\n\n"
347
+ "🗑️ **Accounts Removed (Blocked/Deactivated):** `{deleted_accounts}`\n"
 
 
348
  )
349
  MSG_BROADCAST_CANCEL = "🛑 **Cancelling Broadcast:** `{broadcast_id}`\n\n> ⏳ Stopping operations..."
350
  MSG_BROADCAST_FAILED = (