From 5dc89cd4a7df48389113f7e10b7efc414c2e5832 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Mon, 8 Jan 2024 02:38:46 +0530 Subject: [PATCH 01/18] Update batch.py --- main/plugins/batch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index 2bb76d965..efa2d10eb 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -66,7 +66,7 @@ async def _batch(event): return conv.cancel() try: value = int(_range.text) - if value > 100: + if value > 10000: await conv.send_message("You can only get upto 100 files in a single batch.") return conv.cancel() except ValueError: @@ -84,7 +84,7 @@ async def run_batch(userbot, client, sender, link, _range): timer = 5 if i < 50 and i > 25: timer = 10 - if i < 100 and i > 50: + if i < 10000 and i > 50: timer = 15 if not 't.me/c/' in link: if i < 25: From 8b43b254606fd7013ab1fd20e22ee4d20042f9b6 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Mon, 8 Jan 2024 19:53:46 +0530 Subject: [PATCH 02/18] Update batch.py --- main/plugins/batch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index efa2d10eb..62d2ab46b 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -80,11 +80,11 @@ async def _batch(event): async def run_batch(userbot, client, sender, link, _range): for i in range(_range): timer = 60 - if i < 25: + if i < 250: timer = 5 - if i < 50 and i > 25: + if i < 1000 and i > 250: timer = 10 - if i < 10000 and i > 50: + if i < 10000 and i > 1000: timer = 15 if not 't.me/c/' in link: if i < 25: @@ -102,7 +102,7 @@ async def run_batch(userbot, client, sender, link, _range): try: await get_bulk_msg(userbot, client, sender, link, i) except FloodWait as fw: - if int(fw.x) > 299: + if int(fw.x) > 100000: await client.send_message(sender, "Cancelling batch since you have floodwait more than 5 minutes.") break await asyncio.sleep(fw.x + 5) From 752a23795dcbc5e51604c5b84f2eb9f96437e6e6 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Mon, 8 Jan 2024 20:05:10 +0530 Subject: [PATCH 03/18] Update batch.py --- main/plugins/batch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index 62d2ab46b..c55056c71 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -80,9 +80,9 @@ async def _batch(event): async def run_batch(userbot, client, sender, link, _range): for i in range(_range): timer = 60 - if i < 250: + if i < 25: timer = 5 - if i < 1000 and i > 250: + if i < 1000 and i > 25: timer = 10 if i < 10000 and i > 1000: timer = 15 From 1fc7a34c72a46c1095ec4af9134e0c70620bd877 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Tue, 9 Jan 2024 18:59:55 +0530 Subject: [PATCH 04/18] Update batch.py --- main/plugins/batch.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index c55056c71..549b35c68 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -102,12 +102,11 @@ async def run_batch(userbot, client, sender, link, _range): try: await get_bulk_msg(userbot, client, sender, link, i) except FloodWait as fw: - if int(fw.x) > 100000: - await client.send_message(sender, "Cancelling batch since you have floodwait more than 5 minutes.") - break - await asyncio.sleep(fw.x + 5) + await asyncio.sleep(fw.seconds + 5) await get_bulk_msg(userbot, client, sender, link, i) protection = await client.send_message(sender, f"Sleeping for `{timer}` seconds to avoid Floodwaits and Protect account!") - await asyncio.sleep(timer) + time.sleep(timer) await protection.delete() + + From 49dc40fa2d162e0bf0bb853385e3396561b66995 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Tue, 9 Jan 2024 19:47:07 +0530 Subject: [PATCH 05/18] Update batch.py --- main/plugins/batch.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index 549b35c68..7f18559cf 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -102,10 +102,13 @@ async def run_batch(userbot, client, sender, link, _range): try: await get_bulk_msg(userbot, client, sender, link, i) except FloodWait as fw: - await asyncio.sleep(fw.seconds + 5) + if int(fw.value) > 299999: + await client.send_message(sender, "Cancelling batch since you have floodwait more than 5 minutes.") + break + await asyncio.sleep(fw.value + 5) await get_bulk_msg(userbot, client, sender, link, i) protection = await client.send_message(sender, f"Sleeping for `{timer}` seconds to avoid Floodwaits and Protect account!") - time.sleep(timer) + await asyncio.sleep(timer) await protection.delete() From 23febeebf4397cf33d318d5442de8abcddd760b9 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Fri, 12 Jan 2024 01:52:13 +0530 Subject: [PATCH 06/18] Update batch.py --- main/plugins/batch.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index 7f18559cf..e8c1da3d0 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -6,6 +6,7 @@ """ import time, os, asyncio +import random # Import the random module from .. import bot as Drone from .. import userbot, Bot, AUTH @@ -81,11 +82,11 @@ async def run_batch(userbot, client, sender, link, _range): for i in range(_range): timer = 60 if i < 25: - timer = 5 + timer = random.uniform(2, 15) # Random delay between 2 and 15 seconds if i < 1000 and i > 25: - timer = 10 + timer = random.uniform(10, 30) # Random delay between 10 and 30 seconds if i < 10000 and i > 1000: - timer = 15 + timer = random.uniform(30, 60) # Random delay between 30 and 60 seconds if not 't.me/c/' in link: if i < 25: timer = 2 @@ -105,11 +106,10 @@ async def run_batch(userbot, client, sender, link, _range): if int(fw.value) > 299999: await client.send_message(sender, "Cancelling batch since you have floodwait more than 5 minutes.") break - await asyncio.sleep(fw.value + 5) + await asyncio.sleep(fw.value + random.uniform(5, 10)) # Random delay after FloodWait await get_bulk_msg(userbot, client, sender, link, i) - protection = await client.send_message(sender, f"Sleeping for `{timer}` seconds to avoid Floodwaits and Protect account!") + protection = await client.send_message(sender, f"Sleeping for `{timer:.2f}` seconds to avoid Floodwaits and Protect account!") await asyncio.sleep(timer) await protection.delete() - - + From ebd9c3537a6ad3a9dd280d3c3793ec97b0c9b74c Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Fri, 12 Jan 2024 02:03:15 +0530 Subject: [PATCH 07/18] Update batch.py --- main/plugins/batch.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index e8c1da3d0..aed543559 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -82,11 +82,11 @@ async def run_batch(userbot, client, sender, link, _range): for i in range(_range): timer = 60 if i < 25: - timer = random.uniform(2, 15) # Random delay between 2 and 15 seconds + timer = random.uniform(2, 10) # Random delay between 2 and 15 seconds if i < 1000 and i > 25: - timer = random.uniform(10, 30) # Random delay between 10 and 30 seconds + timer = random.uniform(5, 30) # Random delay between 10 and 30 seconds if i < 10000 and i > 1000: - timer = random.uniform(30, 60) # Random delay between 30 and 60 seconds + timer = random.uniform(20, 60) # Random delay between 30 and 60 seconds if not 't.me/c/' in link: if i < 25: timer = 2 @@ -103,10 +103,10 @@ async def run_batch(userbot, client, sender, link, _range): try: await get_bulk_msg(userbot, client, sender, link, i) except FloodWait as fw: - if int(fw.value) > 299999: + if int(fw.value) > 14400: await client.send_message(sender, "Cancelling batch since you have floodwait more than 5 minutes.") break - await asyncio.sleep(fw.value + random.uniform(5, 10)) # Random delay after FloodWait + await asyncio.sleep(fw.value + random.uniform(5, 60)) # Random delay after FloodWait await get_bulk_msg(userbot, client, sender, link, i) protection = await client.send_message(sender, f"Sleeping for `{timer:.2f}` seconds to avoid Floodwaits and Protect account!") await asyncio.sleep(timer) From 757f6ec26cd59093d3e6fe6b779faa91d77dcef7 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Sat, 13 Jan 2024 03:08:45 +0530 Subject: [PATCH 08/18] Update batch.py --- main/plugins/batch.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index aed543559..94e096a7b 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -83,10 +83,28 @@ async def run_batch(userbot, client, sender, link, _range): timer = 60 if i < 25: timer = random.uniform(2, 10) # Random delay between 2 and 15 seconds - if i < 1000 and i > 25: - timer = random.uniform(5, 30) # Random delay between 10 and 30 seconds - if i < 10000 and i > 1000: - timer = random.uniform(20, 60) # Random delay between 30 and 60 seconds + if i < 100 and i > 25: + timer = random.uniform(5, 15) # Random delay between 10 and 30 seconds + if i < 200 and i > 100: + timer = random.uniform(25, 35) # Random delay between 30 and 60 seconds + if i < 300 and i > 200: + timer = random.uniform(10, 20) + if i < 400 and i > 300: + timer = random.uniform(30, 45) + if i < 500 and i > 400: + timer = random.uniform(22, 28) + if i < 600 and i > 500: + timer = random.uniform(2, 10) + if i < 700 and i > 600: + timer = random.uniform(25, 40) + if i < 800 and i > 700: + timer = random.uniform(15, 20) + if i < 900 and i > 800: + timer = random.uniform(45, 60) + if i < 1000 and i > 900: + timer = random.uniform(5, 12) + if i > 1000: + timer = random.uniform(2, 60) if not 't.me/c/' in link: if i < 25: timer = 2 From f9eb6fef90494e01abb1f992cb78247df27284a3 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Wed, 26 Jun 2024 20:11:54 +0530 Subject: [PATCH 09/18] Update batch.py --- main/plugins/batch.py | 153 ++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 87 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index 94e096a7b..a10660a46 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -1,133 +1,112 @@ -#Tg:MaheshChauhan/DroneBots -#Github.com/Vasusen-code - -""" -Plugin for both public & private channels! -""" - -import time, os, asyncio +import time +import asyncio import random # Import the random module -from .. import bot as Drone -from .. import userbot, Bot, AUTH -from .. import FORCESUB as fs +from .. import bot as Drone, userbot, Bot, AUTH, FORCESUB as fs from main.plugins.pyroplug import get_bulk_msg -from main.plugins.helpers import get_link, screenshot - -from telethon import events, Button, errors -from telethon.tl.types import DocumentAttributeVideo - -from pyrogram import Client +from main.plugins.helpers import get_link +from telethon import events, Button from pyrogram.errors import FloodWait - -from ethon.pyfunc import video_metadata from ethon.telefunc import force_sub ft = f"To use this bot you've to join @{fs}." - batch = [] @Drone.on(events.NewMessage(incoming=True, from_users=AUTH, pattern='/cancel')) async def cancel(event): - if not event.sender_id in batch: + if event.sender_id not in batch: return await event.reply("No batch active.") batch.clear() await event.reply("Done.") - + @Drone.on(events.NewMessage(incoming=True, from_users=AUTH, pattern='/batch')) async def _batch(event): if not event.is_private: return - s, r = await force_sub(event.client, fs, event.sender_id, ft) - if s == True: + s, r = await force_sub(event.client, fs, event.sender_id, ft) + if s: await event.reply(r) - return + return if event.sender_id in batch: - return await event.reply("You've already started one batch, wait for it to complete you dumbfuck owner!") - async with Drone.conversation(event.chat_id) as conv: - if s != True: - await conv.send_message("Send me the message link you want to start saving from, as a reply to this message.", buttons=Button.force_reply()) - try: - link = await conv.get_reply() - try: - _link = get_link(link.text) - except Exception: - await conv.send_message("No link found.") - return conv.cancel() - except Exception as e: - print(e) - await conv.send_message("Cannot wait more longer for your response!") - return conv.cancel() - await conv.send_message("Send me the number of files/range you want to save from the given message, as a reply to this message.", buttons=Button.force_reply()) - try: - _range = await conv.get_reply() - except Exception as e: - print(e) - await conv.send_message("Cannot wait more longer for your response!") - return conv.cancel() - try: - value = int(_range.text) - if value > 10000: - await conv.send_message("You can only get upto 100 files in a single batch.") - return conv.cancel() - except ValueError: - await conv.send_message("Range must be an integer!") - return conv.cancel() - batch.append(event.sender_id) - await run_batch(userbot, Bot, event.sender_id, _link, value) - conv.cancel() - batch.clear() + return await event.reply("You've already started one batch, wait for it to complete!") + + async with Drone.conversation(event.chat_id) as conv: + await conv.send_message("Send me the message link you want to start saving from, as a reply to this message.", buttons=Button.force_reply()) + try: + link = await conv.get_reply() + _link = get_link(link.text) + except Exception as e: + await conv.send_message(f"Error: {e}") + return await conv.cancel() + + await conv.send_message("Send me the number of files/range you want to save from the given message, as a reply to this message.", buttons=Button.force_reply()) + try: + _range = await conv.get_reply() + value = int(_range.text) + if value > 10000: + await conv.send_message("You can only get up to 10000 files in a single batch.") + return await conv.cancel() + except ValueError: + await conv.send_message("Range must be an integer!") + return await conv.cancel() + except Exception as e: + await conv.send_message(f"Error: {e}") + return await conv.cancel() + + batch.append(event.sender_id) + await run_batch(userbot, Bot, event.sender_id, _link, value) + await conv.cancel() + batch.clear() async def run_batch(userbot, client, sender, link, _range): for i in range(_range): timer = 60 if i < 25: - timer = random.uniform(2, 10) # Random delay between 2 and 15 seconds - if i < 100 and i > 25: - timer = random.uniform(5, 15) # Random delay between 10 and 30 seconds - if i < 200 and i > 100: - timer = random.uniform(25, 35) # Random delay between 30 and 60 seconds - if i < 300 and i > 200: + timer = random.uniform(2, 10) + elif i < 100: + timer = random.uniform(5, 15) + elif i < 200: + timer = random.uniform(25, 35) + elif i < 300: timer = random.uniform(10, 20) - if i < 400 and i > 300: + elif i < 400: timer = random.uniform(30, 45) - if i < 500 and i > 400: + elif i < 500: timer = random.uniform(22, 28) - if i < 600 and i > 500: + elif i < 600: timer = random.uniform(2, 10) - if i < 700 and i > 600: + elif i < 700: timer = random.uniform(25, 40) - if i < 800 and i > 700: + elif i < 800: timer = random.uniform(15, 20) - if i < 900 and i > 800: + elif i < 900: timer = random.uniform(45, 60) - if i < 1000 and i > 900: + elif i < 1000: timer = random.uniform(5, 12) - if i > 1000: + else: timer = random.uniform(2, 60) - if not 't.me/c/' in link: - if i < 25: - timer = 2 - else: - timer = 3 - try: - if not sender in batch: + + if 't.me/c/' not in link: + timer = 2 if i < 25 else 3 + + try: + if sender not in batch: await client.send_message(sender, "Batch completed.") break except Exception as e: print(e) await client.send_message(sender, "Batch completed.") break + try: - await get_bulk_msg(userbot, client, sender, link, i) + await get_bulk_msg(userbot, client, sender, link, i) except FloodWait as fw: - if int(fw.value) > 14400: - await client.send_message(sender, "Cancelling batch since you have floodwait more than 5 minutes.") + if int(fw.value) > 300: # 300 seconds = 5 minutes + await client.send_message(sender, "Cancelling batch since you have a floodwait more than 5 minutes.") break - await asyncio.sleep(fw.value + random.uniform(5, 60)) # Random delay after FloodWait + await asyncio.sleep(fw.value + random.uniform(5, 60)) await get_bulk_msg(userbot, client, sender, link, i) - protection = await client.send_message(sender, f"Sleeping for `{timer:.2f}` seconds to avoid Floodwaits and Protect account!") + + protection = await client.send_message(sender, f"Sleeping for `{timer:.2f}` seconds to avoid Floodwaits and protect account!") await asyncio.sleep(timer) await protection.delete() - - From e72d90ce7c7beaadd9e51d9dd02e8153db067db0 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Wed, 26 Jun 2024 20:59:23 +0530 Subject: [PATCH 10/18] Update batch.py --- main/plugins/batch.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index a10660a46..851db2ae3 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -58,6 +58,19 @@ async def _batch(event): await conv.cancel() batch.clear() +def parse_chat_id_from_link(link): + try: + # Attempt to parse the chat ID from the link + parts = link.split("/") + if 't.me/c/' in link: + chat_id = int('-100' + parts[-2]) + else: + chat_id = parts[-2] # or any other logic to extract chat_id + return chat_id + except ValueError: + # Handle cases where the link does not contain a valid integer part + raise ValueError("Invalid chat ID in link") + async def run_batch(userbot, client, sender, link, _range): for i in range(_range): timer = 60 @@ -99,13 +112,17 @@ async def run_batch(userbot, client, sender, link, _range): break try: - await get_bulk_msg(userbot, client, sender, link, i) + chat_id = parse_chat_id_from_link(link) + await get_bulk_msg(userbot, client, sender, link, chat_id, i) + except ValueError as e: + await client.send_message(sender, f"Error: {e}") + break except FloodWait as fw: if int(fw.value) > 300: # 300 seconds = 5 minutes await client.send_message(sender, "Cancelling batch since you have a floodwait more than 5 minutes.") break await asyncio.sleep(fw.value + random.uniform(5, 60)) - await get_bulk_msg(userbot, client, sender, link, i) + await get_bulk_msg(userbot, client, sender, link, chat_id, i) protection = await client.send_message(sender, f"Sleeping for `{timer:.2f}` seconds to avoid Floodwaits and protect account!") await asyncio.sleep(timer) From 019f6318267bb531a70b374a878c704d346c121b Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Wed, 26 Jun 2024 21:06:36 +0530 Subject: [PATCH 11/18] Update batch.py --- main/plugins/batch.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index 851db2ae3..b881e7a10 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -112,17 +112,13 @@ async def run_batch(userbot, client, sender, link, _range): break try: - chat_id = parse_chat_id_from_link(link) - await get_bulk_msg(userbot, client, sender, link, chat_id, i) - except ValueError as e: - await client.send_message(sender, f"Error: {e}") - break + await get_bulk_msg(userbot, client, sender, link, i) except FloodWait as fw: if int(fw.value) > 300: # 300 seconds = 5 minutes await client.send_message(sender, "Cancelling batch since you have a floodwait more than 5 minutes.") break await asyncio.sleep(fw.value + random.uniform(5, 60)) - await get_bulk_msg(userbot, client, sender, link, chat_id, i) + await get_bulk_msg(userbot, client, sender, link, i) protection = await client.send_message(sender, f"Sleeping for `{timer:.2f}` seconds to avoid Floodwaits and protect account!") await asyncio.sleep(timer) From 0f9f94a82a0dd8918bee79fac029065de22e4af5 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Wed, 26 Jun 2024 21:12:16 +0530 Subject: [PATCH 12/18] Update batch.py --- main/plugins/batch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index b881e7a10..d77189d69 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -65,7 +65,8 @@ def parse_chat_id_from_link(link): if 't.me/c/' in link: chat_id = int('-100' + parts[-2]) else: - chat_id = parts[-2] # or any other logic to extract chat_id + # Handle other formats or raise an error if the format is unexpected + raise ValueError("Invalid link format for extracting chat ID") return chat_id except ValueError: # Handle cases where the link does not contain a valid integer part From 795778ee033b1a77ede605e499c702260170d091 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Thu, 27 Jun 2024 02:42:30 +0530 Subject: [PATCH 13/18] Update batch.py --- main/plugins/batch.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index d77189d69..2064ccc4b 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -1,6 +1,7 @@ import time import asyncio import random # Import the random module +import logging from .. import bot as Drone, userbot, Bot, AUTH, FORCESUB as fs from main.plugins.pyroplug import get_bulk_msg @@ -12,6 +13,9 @@ ft = f"To use this bot you've to join @{fs}." batch = [] +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + @Drone.on(events.NewMessage(incoming=True, from_users=AUTH, pattern='/cancel')) async def cancel(event): if event.sender_id not in batch: @@ -63,13 +67,13 @@ def parse_chat_id_from_link(link): # Attempt to parse the chat ID from the link parts = link.split("/") if 't.me/c/' in link: - chat_id = int('-100' + parts[-2]) + chat_id_str = parts[-2] + chat_id = int('-100' + ''.join(filter(str.isdigit, chat_id_str))) else: - # Handle other formats or raise an error if the format is unexpected raise ValueError("Invalid link format for extracting chat ID") return chat_id - except ValueError: - # Handle cases where the link does not contain a valid integer part + except ValueError as e: + logger.error(f"Error parsing chat ID from link '{link}': {e}") raise ValueError("Invalid chat ID in link") async def run_batch(userbot, client, sender, link, _range): @@ -108,7 +112,7 @@ async def run_batch(userbot, client, sender, link, _range): await client.send_message(sender, "Batch completed.") break except Exception as e: - print(e) + logger.error(f"Error during batch completion check: {e}") await client.send_message(sender, "Batch completed.") break From 7a67171ae30081174bad08898f7fe5085fe58c10 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Thu, 27 Jun 2024 02:49:32 +0530 Subject: [PATCH 14/18] Update batch.py --- main/plugins/batch.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index 2064ccc4b..769a21a38 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -64,11 +64,13 @@ async def _batch(event): def parse_chat_id_from_link(link): try: - # Attempt to parse the chat ID from the link parts = link.split("/") if 't.me/c/' in link: chat_id_str = parts[-2] - chat_id = int('-100' + ''.join(filter(str.isdigit, chat_id_str))) + chat_id = int('-100' + chat_id_str) + elif 't.me/' in link and not 't.me/c/' in link: + # Handling user link + chat_id = parts[-2] else: raise ValueError("Invalid link format for extracting chat ID") return chat_id From 277f521fd29fd9dfc2a0e2c35722832adb3b4cfb Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Thu, 27 Jun 2024 03:09:47 +0530 Subject: [PATCH 15/18] Update batch.py --- main/plugins/batch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index 769a21a38..a324a9406 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -67,7 +67,7 @@ def parse_chat_id_from_link(link): parts = link.split("/") if 't.me/c/' in link: chat_id_str = parts[-2] - chat_id = int('-100' + chat_id_str) + chat_id = (chat_id_str) elif 't.me/' in link and not 't.me/c/' in link: # Handling user link chat_id = parts[-2] From 1b7b2afb3b5ed27ccbf714f00e3193c4dab60372 Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Thu, 27 Jun 2024 03:16:17 +0530 Subject: [PATCH 16/18] Update batch.py --- main/plugins/batch.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index a324a9406..96a1ede68 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -65,10 +65,7 @@ async def _batch(event): def parse_chat_id_from_link(link): try: parts = link.split("/") - if 't.me/c/' in link: - chat_id_str = parts[-2] - chat_id = (chat_id_str) - elif 't.me/' in link and not 't.me/c/' in link: + if 't.me/' in link: # Handling user link chat_id = parts[-2] else: From 08fe59b2e4ffcabca67ec383070f7ab275a37f6a Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Thu, 27 Jun 2024 03:24:47 +0530 Subject: [PATCH 17/18] Update batch.py --- main/plugins/batch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index 96a1ede68..463055b2d 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -65,7 +65,9 @@ async def _batch(event): def parse_chat_id_from_link(link): try: parts = link.split("/") - if 't.me/' in link: + if 't.me/c/' in link: + chat_id = parts[-2] # Take the chat ID as it is + elif 't.me/' in link and not 't.me/c/' in link: # Handling user link chat_id = parts[-2] else: From db67613e40f26261b1e25f9443d19970ede45adb Mon Sep 17 00:00:00 2001 From: SamKingotw <155861386+SamKingotw@users.noreply.github.com> Date: Thu, 27 Jun 2024 03:48:41 +0530 Subject: [PATCH 18/18] Update batch.py --- main/plugins/batch.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/main/plugins/batch.py b/main/plugins/batch.py index 463055b2d..ddff2671b 100644 --- a/main/plugins/batch.py +++ b/main/plugins/batch.py @@ -62,20 +62,16 @@ async def _batch(event): await conv.cancel() batch.clear() -def parse_chat_id_from_link(link): +def parse_message_id_from_link(link): try: - parts = link.split("/") - if 't.me/c/' in link: - chat_id = parts[-2] # Take the chat ID as it is - elif 't.me/' in link and not 't.me/c/' in link: - # Handling user link - chat_id = parts[-2] - else: - raise ValueError("Invalid link format for extracting chat ID") - return chat_id - except ValueError as e: - logger.error(f"Error parsing chat ID from link '{link}': {e}") - raise ValueError("Invalid chat ID in link") + # Assuming the link format is https://t.me/c/1635107642/6 + parts = link.split('/') + message_id = int(parts[-1]) + chat_id = -1001635107642 + return chat_id, message_id + except (ValueError, IndexError) as e: + logger.error(f"Error parsing message ID from link '{link}': {e}") + raise ValueError("Invalid message link") async def run_batch(userbot, client, sender, link, _range): for i in range(_range): @@ -118,14 +114,16 @@ async def run_batch(userbot, client, sender, link, _range): break try: - await get_bulk_msg(userbot, client, sender, link, i) + chat_id, message_id = parse_message_id_from_link(link) + await get_bulk_msg(userbot, client, sender, chat_id, message_id + i) except FloodWait as fw: if int(fw.value) > 300: # 300 seconds = 5 minutes await client.send_message(sender, "Cancelling batch since you have a floodwait more than 5 minutes.") break await asyncio.sleep(fw.value + random.uniform(5, 60)) - await get_bulk_msg(userbot, client, sender, link, i) + await get_bulk_msg(userbot, client, sender, chat_id, message_id + i) protection = await client.send_message(sender, f"Sleeping for `{timer:.2f}` seconds to avoid Floodwaits and protect account!") await asyncio.sleep(timer) await protection.delete() +