-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathbatch.py
More file actions
113 lines (101 loc) · 4.12 KB
/
batch.py
File metadata and controls
113 lines (101 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#Tg:MaheshChauhan/DroneBots
#Github.com/Vasusen-code
"""
Plugin for both public & private channels!
"""
import time, os, asyncio
from .. import bot as Drone
from .. import userbot, Bot, AUTH
from .. import 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 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:
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:
await event.reply(r)
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 > 2000:
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()
async def run_batch(userbot, client, sender, link, _range):
for i in range(_range):
timer = 10
if i < 25:
timer = 10
if i < 50 and i > 25:
timer = 10
if i < 100 and i > 50:
timer = 10
if not 't.me/c/' in link:
if i < 25:
timer = 10
else:
timer = 10
try:
if not sender 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)
except FloodWait as fw:
if int(fw.x) > 299:
await client.send_message(sender, "Cancelling batch since you have floodwait more than 5 minutes.")
break
await asyncio.sleep(fw.x + 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)
await protection.delete()