Skip to content

Commit

Permalink
pylint: auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
prono69 committed Sep 8, 2020
1 parent 292d298 commit 5f40f43
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 92 deletions.
99 changes: 49 additions & 50 deletions stdplugins/chanel_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,32 @@
from uniborg.util import admin_cmd, humanbytes, time_formatter
import math
import time

SLEEP_TIME = 5



def getProgressBarString(percentage):
progress_bar_str = "[{0}{1}]\n".format(
''.join(["▰" for i in range(math.floor(percentage / 5))]),
''.join(["▱" for i in range(18 - math.floor(percentage / 5))]))
''.join(["▰" for i in range(math.floor(percentage / 5))]),
''.join(["▱" for i in range(18 - math.floor(percentage / 5))]))
return progress_bar_str



def getProgressString(tg_obj):
progressStr = f"**Name:** `{tg_obj.name()}`\n"
progressStr += f"**CurrentFile:** `{tg_obj.currentFileName()}`\n"
progressStr = f"**Name:** `{tg_obj.name()}`\n"
progressStr += f"**CurrentFile:** `{tg_obj.currentFileName()}`\n"
progressStr += f"**Transferred:** `{humanbytes(tg_obj.transferredBytes())}`\n"
progressStr += f"`{getProgressBarString(tg_obj.percent())}`"
progressStr += f"**Percent:** `{tg_obj.percent()}%\n`"
progressStr += f"**Speed:** `{humanbytes(tg_obj.speed())}ps`\n"
progressStr += f"**ETA:** `{time_formatter(tg_obj.eta())}`\n"
progressStr += f"**Total:** `{humanbytes(tg_obj.totalBytes())}`\n"
return progressStr

async def progressSpinner(tg_obj,banner,event):


async def progressSpinner(tg_obj, banner, event):
while not tg_obj.isComplete():
text = f"__{banner}__\n"
text = f"__{banner}__\n"
try:
text += getProgressString(tg_obj)
except Exception as e:
Expand All @@ -44,9 +47,10 @@ async def progressSpinner(tg_obj,banner,event):
except MessageNotModifiedError:
pass
await asyncio.sleep(SLEEP_TIME)



class TelegramDownloader:
def __init__(self,peer_id,event):
def __init__(self, peer_id, event):
self.peer_id = peer_id
self.event = event
self._name = None
Expand All @@ -62,87 +66,87 @@ def __init__(self,peer_id,event):
self._eta = 0
self.base_dir = None
self.count = 0

def speed(self):
return self.transfer_speed

def percent(self):
try:
return round(self.transferredBytes() * 100 / self.totalBytes(),2)
return round(self.transferredBytes() * 100 / self.totalBytes(), 2)
except ZeroDivisionError:
return 0.0

def eta(self):
return self._eta

def totalBytes(self):
return self.total_bytes

def transferredBytes(self):
return self.transferred_bytes

def name(self):
return self._name

def currentFileName(self):
return self.current_file_name

def isComplete(self):
return self.is_complete

def fileCount(self):
return self.count
async def getMessages(self,peer_id):

async def getMessages(self, peer_id):
messages = []
async for m in borg.iter_messages(peer_id,limit=None,wait_time=2):
async for m in borg.iter_messages(peer_id, limit=None, wait_time=2):
if m.media:
messages.append(m)
return messages


def getSizeByMessages(self,messages):

def getSizeByMessages(self, messages):
size = 0
for m in messages:
if m.media:
size += m.file.size
self.count += 1
return size
def onTransferProgress(self,current,total):
return size

def onTransferProgress(self, current, total):
chunksize = current - self.last_downloaded
self.transferred_bytes += chunksize
self.last_downloaded = current
diff = time.time() - self.start_time
self.transfer_speed = self.transferredBytes() / diff
try:
self._eta = round((self.totalBytes() - self.transferredBytes()) / self.speed()) * 1000
self._eta = round(
(self.totalBytes() - self.transferredBytes()) / self.speed()) * 1000
except ZeroDivisionError:
self._eta = 0

async def onTransferComplete(self):
self.is_complete = True
await self.event.edit(f"Downloaded {self.fileCount()} files in `{self.name()}`")
def onTransferStart(self,chat):

def onTransferStart(self, chat):
self.start_time = time.time()
self._name = chat.title
self.base_dir = chat.title + "/"
os.makedirs(self.base_dir,exist_ok=True)
async def downloadMessage(self,message):
os.makedirs(self.base_dir, exist_ok=True)

async def downloadMessage(self, message):
if message.file.name:
self.current_file_name = message.file.name
elif message.file.title:
self.current_file_name = message.file.title
else:
self.current_file_name = "file"
try:
await borg.download_media(message,self.base_dir,progress_callback=self.onTransferProgress)
await borg.download_media(message, self.base_dir, progress_callback=self.onTransferProgress)
except errors.FloodWaitError as e:
await asyncio.sleep(e.seconds)
self.last_downloaded = 0

async def startDownload(self):
chat = await borg.get_entity(self.peer_id)
self.onTransferStart(chat)
Expand All @@ -151,9 +155,8 @@ async def startDownload(self):
for message in messages:
await self.downloadMessage(message)
await self.onTransferComplete()





@borg.on(admin_cmd(pattern="geta ?(.*)", allow_sudo=True))
async def get_media(event):
if event.fwd_from:
Expand All @@ -164,11 +167,7 @@ async def get_media(event):
except ValueError:
pass
mone = await event.reply("Downloading All Media From this Channel.")
tgDownloader = TelegramDownloader(channel,mone)
tgDownloader = TelegramDownloader(channel, mone)
task1 = tgDownloader.startDownload()
task2 = progressSpinner(tgDownloader,"DOWNLOAD PROGRESS",mone)
await asyncio.gather(*[task1,task2])




task2 = progressSpinner(tgDownloader, "DOWNLOAD PROGRESS", mone)
await asyncio.gather(*[task1, task2])
10 changes: 5 additions & 5 deletions stdplugins/direct_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# you may not use this file except in compliance with the License.
#
""" Userbot module containing various sites direct links generators"""
from asyncio import create_subprocess_shell as asyncSubprocess
from asyncio.subprocess import PIPE as asyncPIPE
import asyncio
import json
import re
Expand All @@ -24,7 +22,8 @@
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.WARN)

USR_TOKEN = Config.USR_TOKEN
USR_TOKEN = Config.USR_TOKEN


@borg.on(events.NewMessage(pattern=r"^.direct(?: |$)([\s\S]*)", outgoing=True))
async def direct_link_generator(request):
Expand Down Expand Up @@ -66,7 +65,7 @@ async def direct_link_generator(request):
elif 'androidfilehost.com' in link:
reply += androidfilehost(link)
elif 'uptobox.com' in link:
reply += await uptobox(request, link)
reply += await uptobox(request, link)
else:
reply += '`' + re.findall(r"\bhttps?://(.*?[^/]+)",
link)[0] + 'is not supported`\n'
Expand Down Expand Up @@ -342,6 +341,7 @@ def androidfilehost(url: str) -> str:
reply += f'[{name}]({dl_url}) '
return reply


async def uptobox(request, url: str) -> str:
""" Uptobox direct links generator """
try:
Expand Down Expand Up @@ -421,7 +421,7 @@ async def uptobox(request, url: str) -> str:
f"`status`: **{status}**"
)
return


def useragent():
"""
Expand Down
3 changes: 1 addition & 2 deletions stdplugins/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def aexec(code, event):
)
return await locals()['__aexec'](event)


@borg.on(admin_cmd(pattern="exec ?(.*)"))
async def _(event):
if event.fwd_from or event.via_bot_id:
Expand Down Expand Up @@ -113,4 +113,3 @@ async def _(event):
)
await event.delete()
await event.edit(OUTPUT)

86 changes: 51 additions & 35 deletions stdplugins/proxyscrape.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
# Created By @StarkXD
# Fixed By @MrConfused
# Created By @StarkXD
# Fixed By @MrConfused
# UserBot Plugin To Send Fresh Proxies From Proxyscrape.com
# Banned For Sensible Userbot And Users.
""" Usage : For Http Proxy : .proxyhttp , For Socks4 : .proxysocks4 , For socks5 : .proxysocks5"""

from telethon import events
from uniborg.util import admin_cmd
from uniborg.util import admin_cmd
from pySmartDL import SmartDL
import os

STARK_HTTP = "https://api.proxyscrape.com/?request=getproxies&proxytype=http&timeout=10000&country=all&ssl=all&anonymity=all"
HTTP_TXT = ("**Proxy Info** \nType: __HTTPS__ \nTimeOut: __10000__ \nCountry: __All__ \nSsl: All \nAnonymity: __All__ \n[Click Here To View Or Download File Manually](https://api.proxyscrape.com/?request=getproxies&proxytype=http&timeout=10000&country=all&ssl=all&anonymity=all) \nUploaded By [Friday](https://github.com/starkgang/FridayUserBot) \n**Here Is Your Proxy** 👇")
STARK_HTTP = "https://api.proxyscrape.com/?request=getproxies&proxytype=http&timeout=10000&country=all&ssl=all&anonymity=all"
HTTP_TXT = (
"**Proxy Info** \nType: __HTTPS__ \nTimeOut: __10000__ \nCountry: __All__ \nSsl: All \nAnonymity: __All__ \n[Click Here To View Or Download File Manually](https://api.proxyscrape.com/?request=getproxies&proxytype=http&timeout=10000&country=all&ssl=all&anonymity=all) \nUploaded By [Friday](https://github.com/starkgang/FridayUserBot) \n**Here Is Your Proxy** 👇")
STARK_SOCKS4 = "https://api.proxyscrape.com/?request=getproxies&proxytype=socks4&timeout=10000&country=all"
SOCKS4_TXT = ("**Proxy Info** \nType: __SOCKS4__ \nTimeOut: __10000__ \nCountry: __All__ \nSsl: __Only For Http Proxy__ \nAnonymity: __Only For Http__ \n[Click Here To View Or Download File Manually](https://api.proxyscrape.com/?request=getproxies&proxytype=socks4&timeout=10000&country=all) \nUploaded By [Friday](https://github.com/starkgang/FridayUserBot) \n**Here Is Your Proxy** 👇")
SOCKS4_TXT = (
"**Proxy Info** \nType: __SOCKS4__ \nTimeOut: __10000__ \nCountry: __All__ \nSsl: __Only For Http Proxy__ \nAnonymity: __Only For Http__ \n[Click Here To View Or Download File Manually](https://api.proxyscrape.com/?request=getproxies&proxytype=socks4&timeout=10000&country=all) \nUploaded By [Friday](https://github.com/starkgang/FridayUserBot) \n**Here Is Your Proxy** 👇")
STARK_SOCKS5 = "https://api.proxyscrape.com/?request=getproxies&proxytype=socks5&timeout=10000&country=all"
SOCKS5_TXT = ("**Proxy Info** \nType: __SOCKS4__ \nTimeOut: __10000__ \nCountry: __All__ \nSsl: __Only For Http Proxy__ \nAnonymity: __Only For Http__ \n[Click Here To View Or Download File Manually](https://api.proxyscrape.com/?request=getproxies&proxytype=socks5&timeout=10000&country=all) \nUploaded By [Friday](https://github.com/starkgang/FridayUserBot) \n**Here Is Your Proxy** 👇")
SOCKS5_TXT = (
"**Proxy Info** \nType: __SOCKS4__ \nTimeOut: __10000__ \nCountry: __All__ \nSsl: __Only For Http Proxy__ \nAnonymity: __Only For Http__ \n[Click Here To View Or Download File Manually](https://api.proxyscrape.com/?request=getproxies&proxytype=socks5&timeout=10000&country=all) \nUploaded By [Friday](https://github.com/starkgang/FridayUserBot) \n**Here Is Your Proxy** 👇")

@borg.on(admin_cmd(pattern="proxyhttp"))
async def starkxD(event):
chat = await event.get_chat()

@borg.on(admin_cmd(pattern="proxyhttp"))
async def starkxD(event):
await event.get_chat()
file_name = "proxy_http.txt"
downloaded_file_name = os.path.join(Config.TMP_DOWNLOAD_DIRECTORY , file_name)
downloader = SmartDL( f"{STARK_HTTP}" , downloaded_file_name, progress_bar=False)
downloader.start(blocking=False)
await borg.send_message(event.chat_id , HTTP_TXT)
await event.client.send_file(event.chat_id , downloaded_file_name)

@borg.on(admin_cmd(pattern="proxysocks4"))
async def starkgang(event):
chat = await event.get_chat()
downloaded_file_name = os.path.join(
Config.TMP_DOWNLOAD_DIRECTORY, file_name)
downloader = SmartDL(
f"{STARK_HTTP}",
downloaded_file_name,
progress_bar=False)
downloader.start(blocking=False)
await borg.send_message(event.chat_id, HTTP_TXT)
await event.client.send_file(event.chat_id, downloaded_file_name)


@borg.on(admin_cmd(pattern="proxysocks4"))
async def starkgang(event):
await event.get_chat()
file_name = "proxy_socks4.txt"
downloaded_file_name = os.path.join(Config.TMP_DOWNLOAD_DIRECTORY , file_name)
downloader = SmartDL( f"{STARK_SOCKS4}" , downloaded_file_name, progress_bar=False)
downloader.start(blocking=False)
await borg.send_message(event.chat_id , SOCKS4_TXT)
await event.client.send_file(event.chat_id , downloaded_file_name)

@borg.on(admin_cmd(pattern="proxysocks5"))
async def friday(event):
chat = await event.get_chat()
downloaded_file_name = os.path.join(
Config.TMP_DOWNLOAD_DIRECTORY, file_name)
downloader = SmartDL(
f"{STARK_SOCKS4}",
downloaded_file_name,
progress_bar=False)
downloader.start(blocking=False)
await borg.send_message(event.chat_id, SOCKS4_TXT)
await event.client.send_file(event.chat_id, downloaded_file_name)


@borg.on(admin_cmd(pattern="proxysocks5"))
async def friday(event):
await event.get_chat()
file_name = "proxy_socks5.txt"
downloaded_file_name = os.path.join(Config.TMP_DOWNLOAD_DIRECTORY , file_name)
downloader = SmartDL( f"{STARK_SOCKS5}" , downloaded_file_name, progress_bar=False)
downloader.start(blocking=False)
await borg.send_message(event.chat_id , SOCKS5_TXT)
await event.client.send_file(event.chat_id , downloaded_file_name)

downloaded_file_name = os.path.join(
Config.TMP_DOWNLOAD_DIRECTORY, file_name)
downloader = SmartDL(
f"{STARK_SOCKS5}",
downloaded_file_name,
progress_bar=False)
downloader.start(blocking=False)
await borg.send_message(event.chat_id, SOCKS5_TXT)
await event.client.send_file(event.chat_id, downloaded_file_name)

0 comments on commit 5f40f43

Please sign in to comment.