Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AM-ROBOTS authored Oct 12, 2022
1 parent 17d5ffe commit 064f0fb
Show file tree
Hide file tree
Showing 6 changed files with 493 additions and 0 deletions.
103 changes: 103 additions & 0 deletions main/plugins/batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#Tg:sources_cods/Am_RoBots
#Github.com/8769Anurag

"""
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 check, 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 = []

async def get_pvt_content(event, chat, id):
msg = await userbot.get_messages(chat, ids=id)
await event.client.send_message(event.chat_id, msg)

@Drone.on(events.NewMessage(incoming=True, from_users=AUTH, pattern='/batch'))
async def _batch(event):
if not event.is_private:
return
# wtf is the use of fsub here if the command is meant for the owner?
# well am too lazy to clean
s, r = await force_sub(event.client, fs, event.sender_id, ft)
if s == True:
await event.reply(r)
return
if f'{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.")
except Exception as e:
print(e)
return await conv.send_message("Cannot wait more longer for your response!")
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)
return await conv.send_message("Cannot wait more longer for your response!")
try:
value = int(_range.text)
if value > 100:
return await conv.send_message("You can only get upto 100 files in a single batch.")
except ValueError:
return await conv.send_message("Range must be an integer!")
s, r = await check(userbot, Bot, _link)
if s != True:
await conv.send_message(r)
return
batch.append(f'{event.sender_id}')
await run_batch(userbot, Bot, event.sender_id, _link, value)
conv.cancel()
batch.pop(0)


async def run_batch(userbot, client, sender, link, _range):
for i in range(_range):
timer = 60
if i < 25:
timer = 5
if i < 50 and i > 25:
timer = 10
if i < 100 and i > 50:
timer = 15
if not 't.me/c/' in link:
if i < 25:
timer = 2
else:
timer = 3
try:
await get_bulk_msg(userbot, client, sender, link, i)
except FloodWait as fw:
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!")
time.sleep(timer)
await protection.delete()



46 changes: 46 additions & 0 deletions main/plugins/frontend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#Github.com/8769Anurag

import time, os

from .. import bot as Drone
from .. import userbot, Bot
from .. import FORCESUB as fs
from main.plugins.pyroplug import get_msg
from main.plugins.helpers import get_link, join, screenshot

from telethon import events

from ethon.telefunc import force_sub

ft = f"To use this bot you've to join @{fs}."

message = "Send me the message link you want to start saving from, as a reply to this message."

# To-Do:
# Make these codes shorter and clean
# ofc will never do it.

@Drone.on(events.NewMessage(incoming=True, func=lambda e: e.is_private))
async def clone(event):
if event.is_reply:
reply = await event.get_reply_message()
if reply.text == message:
return
try:
link = get_link(event.text)
if not link:
return
except TypeError:
return
s, r = await force_sub(event.client, fs, event.sender_id, ft)
if s == True:
await event.reply(r)
return
edit = await event.reply("Processing!")
if 't.me/+' in link:
q = await join(userbot, link)
await edit.edit(q)
return
if 't.me/' in link:
await get_msg(userbot, Bot, event.sender_id, edit.id, link, 0)

73 changes: 73 additions & 0 deletions main/plugins/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#Github.com/8769Anurag

from pyrogram.errors import FloodWait, InviteHashInvalid, InviteHashExpired, UserAlreadyParticipant
from telethon import errors, events

import asyncio, subprocess, re, os, time
from pathlib import Path
from datetime import datetime as dt

#Join private chat-------------------------------------------------------------------------------------------------------------

async def join(client, invite_link):
try:
await client.join_chat(invite_link)
return "Successfully joined the Channel"
except UserAlreadyParticipant:
return "User is already a participant."
except (InviteHashInvalid, InviteHashExpired):
return "Could not join. Maybe your link is expired or Invalid."
except FloodWait:
return "Too many requests, try again later."
except Exception as e:
print(e)
return "Could not join, try joining manually."

#Regex---------------------------------------------------------------------------------------------------------------
#to get the url from event

def get_link(string):
regex = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"
url = re.findall(regex,string)
try:
link = [x[0] for x in url][0]
if link:
return link
else:
return False
except Exception:
return False

#Screenshot---------------------------------------------------------------------------------------------------------------

def hhmmss(seconds):
x = time.strftime('%H:%M:%S',time.gmtime(seconds))
return x

async def screenshot(video, duration, sender):
if os.path.exists(f'{sender}.jpg'):
return f'{sender}.jpg'
time_stamp = hhmmss(int(duration)/2)
out = dt.now().isoformat("_", "seconds") + ".jpg"
cmd = ["ffmpeg",
"-ss",
f"{time_stamp}",
"-i",
f"{video}",
"-frames:v",
"1",
f"{out}",
"-y"
]
process = await asyncio.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
x = stderr.decode().strip()
y = stdout.decode().strip()
if os.path.isfile(out):
return out
else:
None
88 changes: 88 additions & 0 deletions main/plugins/progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import math
import os
import time
import json

FINISHED_PROGRESS_STR = "█"
UN_FINISHED_PROGRESS_STR = ""
DOWNLOAD_LOCATION = "/app"


async def progress_for_pyrogram(
current,
total,
bot,
ud_type,
message,
start
):
now = time.time()
diff = now - start
if round(diff % 10.00) == 0 or current == total:
percentage = current * 100 / total
status = DOWNLOAD_LOCATION + "/status.json"
if os.path.exists(status):
with open(status, 'r+') as f:
statusMsg = json.load(f)
if not statusMsg["running"]:
bot.stop_transmission()
speed = current / diff
elapsed_time = round(diff) * 1000
time_to_completion = round((total - current) / speed) * 1000
estimated_total_time = elapsed_time + time_to_completion

elapsed_time = TimeFormatter(milliseconds=elapsed_time)
estimated_total_time = TimeFormatter(milliseconds=estimated_total_time)

progress = "**[{0}{1}]** `| {2}%`\n\n".format(
''.join([FINISHED_PROGRESS_STR for i in range(math.floor(percentage / 10))]),
''.join([UN_FINISHED_PROGRESS_STR for i in range(10 - math.floor(percentage / 10))]),
round(percentage, 2))

tmp = progress + "GROSSS: {0} of {1}\n\nSpeed: {2}/s\n\nETA: {3}\n".format(
humanbytes(current),
humanbytes(total),
humanbytes(speed),
estimated_total_time if estimated_total_time != '' else "0 s"
)
try:
if not message.photo:
await message.edit_text(
text="{}\n {}".format(
ud_type,
tmp
)
)
else:
await message.edit_caption(
caption="{}\n {}".format(
ud_type,
tmp
)
)
except:
pass


def humanbytes(size):
if not size:
return ""
power = 2**10
n = 0
Dic_powerN = {0: ' ', 1: 'Ki', 2: 'Mi', 3: 'Gi', 4: 'Ti'}
while size > power:
size /= power
n += 1
return str(round(size, 2)) + " " + Dic_powerN[n] + 'B'


def TimeFormatter(milliseconds: int) -> str:
seconds, milliseconds = divmod(int(milliseconds), 1000)
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
tmp = ((str(days) + "d, ") if days else "") + \
((str(hours) + "h, ") if hours else "") + \
((str(minutes) + "m, ") if minutes else "") + \
((str(seconds) + "s, ") if seconds else "")
return tmp[:-2]
Loading

0 comments on commit 064f0fb

Please sign in to comment.