forked from VJBots/VJ-Txt-Leech-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47504e3
commit 3c36932
Showing
1 changed file
with
55 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,55 @@ | ||
# Don't Remove Credit Tg - @VJ_Botz | ||
# Subscribe YouTube Channel For Amazing Bot https://youtube.com/@Tech_VJ | ||
# Ask Doubt on telegram @KingVJ01 | ||
|
||
import time | ||
import math | ||
import os | ||
from pyrogram.errors import FloodWait | ||
|
||
class Timer: | ||
def __init__(self, time_between=5): | ||
self.start_time = time.time() | ||
self.time_between = time_between | ||
|
||
def can_send(self): | ||
if time.time() > (self.start_time + self.time_between): | ||
self.start_time = time.time() | ||
return True | ||
return False | ||
|
||
|
||
from datetime import datetime,timedelta | ||
|
||
def hrb(value, digits= 2, delim= "", postfix=""): | ||
"""Return a human-readable file size. | ||
""" | ||
if value is None: | ||
return None | ||
chosen_unit = "B" | ||
for unit in ("KiB", "MiB", "GiB", "TiB"): | ||
if value > 1000: | ||
value /= 1024 | ||
chosen_unit = unit | ||
else: | ||
break | ||
return f"{value:.{digits}f}" + delim + chosen_unit + postfix | ||
|
||
def hrt(seconds, precision = 0): | ||
"""Return a human-readable time delta as a string. | ||
""" | ||
pieces = [] | ||
value = timedelta(seconds=seconds) | ||
|
||
|
||
if value.days: | ||
pieces.append(f"{value.days}d") | ||
|
||
seconds = value.seconds | ||
|
||
if seconds >= 3600: | ||
hours = int(seconds / 3600) | ||
pieces.append(f"{hours}h") | ||
seconds -= hours * 3600 | ||
|
||
if seconds >= 60: | ||
minutes = int(seconds / 60) | ||
pieces.append(f"{minutes}m") | ||
seconds -= minutes * 60 | ||
|
||
if seconds > 0 or not pieces: | ||
pieces.append(f"{seconds}s") | ||
|
||
if not precision: | ||
return "".join(pieces) | ||
|
||
return "".join(pieces[:precision]) | ||
|
||
|
||
|
||
timer = Timer() | ||
|
||
async def progress_bar(current, total, reply, start): | ||
if timer.can_send(): | ||
now = time.time() | ||
diff = now - start | ||
if diff < 1: | ||
return | ||
else: | ||
perc = f"{current * 100 / total:.1f}%" | ||
elapsed_time = round(diff) | ||
speed = current / elapsed_time | ||
remaining_bytes = total - current | ||
if speed > 0: | ||
eta_seconds = remaining_bytes / speed | ||
eta = hrt(eta_seconds, precision=1) | ||
else: | ||
eta = "-" | ||
sp = str(hrb(speed)) + "/s" | ||
tot = hrb(total) | ||
cur = hrb(current) | ||
bar_length = 11 | ||
completed_length = int(current * bar_length / total) | ||
remaining_length = bar_length - completed_length | ||
progress_bar = "▰" * completed_length + "▱" * remaining_length | ||
|
||
try: | ||
await reply.edit(f'<b>\n ╭──⌯════🆄︎ᴘʟᴏᴀᴅɪɴɢ⬆️⬆️═════⌯──╮ \n├⚡ {progress_bar}|﹝{perc}﹞ \n├🚀 Speed » {sp} \n├📟 Processed » {cur}\n├🧲 Size - ETA » {tot} - {eta} \n├🤖 𝔹ʏ » @zx_gkk01\n╰─═══ ✪ @zx_gkk01 ✪ ═══─╯\n</b>') | ||
except FloodWait as e: | ||
time.sleep(e.x) | ||
|
||
import pytz, random, string | ||
from datetime import date | ||
from info import API, URL | ||
from shortzy import Shortzy | ||
|
||
TOKENS = {} | ||
VERIFIED = {} | ||
|
||
async def get_verify_shorted_link(link): | ||
shortzy = Shortzy(api_key=API, base_site=URL) | ||
link = await shortzy.convert(link) | ||
return link | ||
|
||
async def check_token(bot, userid, token): | ||
user = await bot.get_users(userid) | ||
if user.id in TOKENS.keys(): | ||
TKN = TOKENS[user.id] | ||
if token in TKN.keys(): | ||
is_used = TKN[token] | ||
if is_used == True: | ||
return False | ||
else: | ||
return True | ||
else: | ||
return False | ||
|
||
async def get_token(bot, userid, link): | ||
user = await bot.get_users(userid) | ||
token = ''.join(random.choices(string.ascii_letters + string.digits, k=7)) | ||
TOKENS[user.id] = {token: False} | ||
link = f"{link}verify-{user.id}-{token}" | ||
shortened_verify_url = await get_verify_shorted_link(link) | ||
return str(shortened_verify_url) | ||
|
||
async def verify_user(bot, userid, token): | ||
user = await bot.get_users(userid) | ||
TOKENS[user.id] = {token: True} | ||
tz = pytz.timezone('Asia/Kolkata') | ||
today = date.today() | ||
VERIFIED[user.id] = str(today) | ||
|
||
async def check_verification(bot, userid): | ||
user = await bot.get_users(userid) | ||
tz = pytz.timezone('Asia/Kolkata') | ||
today = date.today() | ||
if user.id in VERIFIED.keys(): | ||
EXP = VERIFIED[user.id] | ||
years, month, day = EXP.split('-') | ||
comp = date(int(years), int(month), int(day)) | ||
if comp<today: | ||
return False | ||
else: | ||
return True | ||
else: | ||
return False |