-
Notifications
You must be signed in to change notification settings - Fork 61
Unstable (Sourcery refactored) #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,12 +28,12 @@ async def download_file(message, url, file_name): | |
| async with aiohttp.ClientSession() as session: | ||
| async with session.get(url) as r: | ||
| total_length = r.headers.get('content-length') or r.headers.get("Content-Length") | ||
| dl = 0 | ||
| if total_length is None: | ||
| f.write(await r.read()) | ||
| else: | ||
| total_length = int(total_length) | ||
| async for chunk in r.content.iter_chunked(max(int(total_length/500), (1024*1024)*2)): | ||
| dl = 0 | ||
| async for chunk in r.content.iter_chunked(max(total_length // 500, (1024*1024)*2)): | ||
|
Comment on lines
-31
to
+36
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dl += len(chunk) | ||
| e_ = time.time() | ||
| diff = e_ - c_ | ||
|
|
@@ -44,9 +44,23 @@ async def download_file(message, url, file_name): | |
| estimated_total_time = elapsed_time + time_to_completion | ||
| f.write(chunk) | ||
| progress_str = "{0}{1} {2}%\n".format( | ||
| "".join(["▰" for i in range(math.floor(percentage / 10))]), | ||
| "".join(["▱" for i in range(10 - math.floor(percentage / 10))]), | ||
| round(percentage, 2)) | ||
| "".join( | ||
| [ | ||
| "▰" | ||
| for _ in range(math.floor(percentage / 10)) | ||
| ] | ||
| ), | ||
| "".join( | ||
| [ | ||
| "▱" | ||
| for _ in range( | ||
| 10 - math.floor(percentage / 10) | ||
| ) | ||
| ] | ||
| ), | ||
| round(percentage, 2), | ||
| ) | ||
|
|
||
| r_ = f"<b><u>Downloading This File</b></u> \n<b>File :</b> <code>{file_name}</code> \n<b>File Size :</b> <code>{humanbytes(total_length)}</code> \n<b>Downloaded :</b> <code>{humanbytes(dl)}</code> \n{progress_str} \n\n<b>Speed :</b> <code>{humanbytes(round(speed))}/ps</code> \n<b>ETA :</b> <code>{time_formatter(estimated_total_time)}</code>" | ||
| try: | ||
| await message.edit(r_) | ||
|
|
@@ -85,9 +99,7 @@ async def upload_file(client, reply_message, message, file_path, caption): | |
| async def send_file(client, r_msg, file, capt, e_msg): | ||
| c_time = time.time() | ||
| file_name = os.path.basename(file) | ||
| send_as_thumb = False | ||
| if os.path.exists("./main_startup/Cache/thumb.jpg"): | ||
| send_as_thumb = True | ||
| send_as_thumb = bool(os.path.exists("./main_startup/Cache/thumb.jpg")) | ||
|
Comment on lines
-88
to
+102
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if file.endswith(image_ext): | ||
| await r_msg.reply_video( | ||
| file, | ||
|
|
@@ -157,24 +169,23 @@ async def send_file(client, r_msg, file, capt, e_msg): | |
| progress=progress, | ||
| progress_args=(e_msg, c_time, f"`Uploading {file_name}!`", file_name), | ||
| ) | ||
| elif send_as_thumb: | ||
| await r_msg.reply_document( | ||
| file, | ||
| quote=True, | ||
| thumb="./main_startup/Cache/thumb.jpg", | ||
| caption=capt, | ||
| progress=progress, | ||
| progress_args=(e_msg, c_time, f"`Uploading {file_name}!`", file_name), | ||
| ) | ||
| else: | ||
| if send_as_thumb: | ||
| await r_msg.reply_document( | ||
| file, | ||
| quote=True, | ||
| thumb="./main_startup/Cache/thumb.jpg", | ||
| caption=capt, | ||
| progress=progress, | ||
| progress_args=(e_msg, c_time, f"`Uploading {file_name}!`", file_name), | ||
| ) | ||
| else: | ||
| await r_msg.reply_document( | ||
| file, | ||
| quote=True, | ||
| caption=capt, | ||
| progress=progress, | ||
| progress_args=(e_msg, c_time, f"`Uploading {file_name}!`", file_name), | ||
| ) | ||
| await r_msg.reply_document( | ||
| file, | ||
| quote=True, | ||
| caption=capt, | ||
| progress=progress, | ||
| progress_args=(e_msg, c_time, f"`Uploading {file_name}!`", file_name), | ||
| ) | ||
|
|
||
| def file_list(path, lisT): | ||
| pathlib.Path(path) | ||
|
|
@@ -203,8 +214,8 @@ async def download_(client, message): | |
| file_url, file_name = await dl_client.gdrive(url) | ||
| except BaseException as e: | ||
| return await s.edit(f"**Failed To GET Direct Link ::** `{e}`") | ||
| if file_url == None: | ||
| return await s.edit(f"**Failed To GET Direct Link**") | ||
| if file_url is None: | ||
| return await s.edit("**Failed To GET Direct Link**") | ||
|
Comment on lines
-206
to
+218
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| file = await download_file(s, file_url, file_name) | ||
| caption = f"<b><u>File Downloaded & Uploaded</b></u> \n<b>File Name :</b> <code>{file_name}</code>" | ||
| await upload_file(client, msg, s, file, caption) | ||
|
|
@@ -218,8 +229,8 @@ async def download_(client, message): | |
| file_url, file_name, file_size, file_upload_date, caption_, scan_result = await dl_client.media_fire_dl(url) | ||
| except BaseException as e: | ||
| return await s.edit(f"**Failed To GET Direct Link ::** `{e}`") | ||
| if file_url == None: | ||
| return await s.edit(f"**Failed To GET Direct Link**") | ||
| if file_url is None: | ||
| return await s.edit("**Failed To GET Direct Link**") | ||
| file = await download_file(s, file_url, file_name) | ||
| caption = f"<b><u>File Downloaded & Uploaded</b></u> \n<b>File Name :</b> <code>{file_name}</code> \n<b>File Size :</b> <code>{file_size}</code> \n<b>File Upload Date :</b> <code>{file_upload_date}</code> \n<b>File Scan Result :</b> <code>{scan_result}</code> \n<code>{caption_}</code>" | ||
| await upload_file(client, msg, s, file, caption) | ||
|
|
@@ -235,8 +246,8 @@ async def download_(client, message): | |
| file_url, file_name, file_size = await dl_client.mega_dl(link) | ||
| except BaseException as e: | ||
| return await s.edit(f"**Failed To GET Direct Link ::** `{e}`") | ||
| if file_url == None: | ||
| return await s.edit(f"**Failed To GET Direct Link**") | ||
| if file_url is None: | ||
| return await s.edit("**Failed To GET Direct Link**") | ||
| file = await download_file(s, file_url, file_name) | ||
| file_size = humanbytes(file_size) | ||
| caption = f"<b><u>File Downloaded & Uploaded</b></u> \n<b>File Name :</b> <code>{file_name}</code> \n<b>File Size :</b> <code>{file_size}</code>" | ||
|
|
@@ -251,12 +262,9 @@ async def download_(client, message): | |
| file_url, file_size, file_name = await dl_client.anon_files_dl(link) | ||
| except BaseException as e: | ||
| return await s.edit(f"**Failed To GET Direct Link ::** `{e}`") | ||
| if file_url == None: | ||
| return await s.edit(f"**Failed To GET Direct Link**") | ||
| if file_url is None: | ||
| return await s.edit("**Failed To GET Direct Link**") | ||
| file = await download_file(s, file_url, file_name) | ||
| caption = f"<b><u>File Downloaded & Uploaded</b></u> \n<b>File Name :</b> <code>{file_name}</code> \n<b>File Size :</b> <code>{file_size}</code>" | ||
| await upload_file(client, msg, s, file, caption) | ||
| return os.remove(file) | ||
| else: | ||
| url_ = url.split('|') | ||
| if len(url_) != 2: | ||
|
|
@@ -268,7 +276,8 @@ async def download_(client, message): | |
| except BaseException as e: | ||
| return await s.edit(f"**Failed To Download ::** `{e}`") | ||
| file_size = humanbytes(os.stat(file).st_size) | ||
| caption = f"<b><u>File Downloaded & Uploaded</b></u> \n<b>File Name :</b> <code>{file_name}</code> \n<b>File Size :</b> <code>{file_size}</code>" | ||
| await upload_file(client, msg, s, file, caption) | ||
| return os.remove(file) | ||
|
|
||
| caption = f"<b><u>File Downloaded & Uploaded</b></u> \n<b>File Name :</b> <code>{file_name}</code> \n<b>File Size :</b> <code>{file_size}</code>" | ||
| await upload_file(client, msg, s, file, caption) | ||
| return os.remove(file) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,10 +35,10 @@ def make_carbon(code, driver, lang="auto"): | |
| type_ = '//*[@id="__next"]/main/div[2]/div[2]/div[1]/div[1]/div/span[2]' | ||
| em = "export-menu" | ||
| png_xpath = '//*[@id="export-png"]' | ||
| four_x_path = '//*[@id="__next"]/main/div[2]/div[2]/div[1]/div[3]/div[4]/div[3]/div[2]/div[3]/div/button[3]' | ||
| four_x_path = '//*[@id="__next"]/main/div[2]/div[2]/div[1]/div[3]/div[4]/div[3]/div[2]/div[3]/div/button[3]' | ||
| color_used_xpath = '/html/body/div[1]/main/div[2]/div[2]/div[1]/div[1]/div/span[2]/input' | ||
| random_int = random.randint(1, 29) | ||
| value_ = "downshift-0-item-" + str(random_int) | ||
| value_ = f"downshift-0-item-{str(random_int)}" | ||
|
Comment on lines
-38
to
+41
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| wait = WebDriverWait(driver, 20) | ||
| wait.until(EC.visibility_of_element_located((By.XPATH, type_))).click() | ||
| wait.until(EC.visibility_of_element_located((By.ID, value_))).click() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ def namso_gen(bin, no_of_result=15): | |
| button_xpath = '/html/body/div/div/div/main/div/div/div[3]/div[1]/form/div[5]/button' | ||
| w.until(EC.visibility_of_element_located((By.XPATH, bin_xpath))).send_keys(bin) | ||
| elem3 = w.until(EC.visibility_of_element_located((By.XPATH, no_of_r_xpath))) | ||
| for i in range(2): | ||
| for _ in range(2): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| elem3.send_keys(Keys.BACKSPACE) | ||
| elem3 = w.until(EC.visibility_of_element_located((By.XPATH, no_of_r_xpath))) | ||
| elem3.send_keys(no_of_result) | ||
|
|
@@ -97,9 +97,13 @@ async def ns_gen(client, message): | |
| await msg.edit(t, parse_mode="md") | ||
|
|
||
| def stark_finder(to_find, from_find): | ||
| if re.search(r"( |^|[^\w])" + re.escape(to_find) + r"( |$|[^\w])", from_find, flags=re.IGNORECASE): | ||
| return True | ||
| return False | ||
| return bool( | ||
| re.search( | ||
| f"( |^|[^\\w]){re.escape(to_find)}( |$|[^\\w])", | ||
| from_find, | ||
| flags=re.IGNORECASE, | ||
| ) | ||
| ) | ||
|
Comment on lines
-100
to
+106
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| my_code = { | ||
| 400: "『! Invalid Key !』", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |
|
|
||
| async def create_s_collage(file_path, filename, width, stark_h): | ||
| """Create Image Collage""" | ||
| img_stark = [filepath for filepath in pathlib.Path(file_path).glob("**/*")] | ||
| img_stark = list(pathlib.Path(file_path).glob("**/*")) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| margin_size = 2 | ||
| while True: | ||
| img_stark_list = list(img_stark) | ||
|
|
@@ -45,10 +45,12 @@ async def create_s_collage(file_path, filename, width, stark_h): | |
| stark_h -= 10 | ||
| else: | ||
| break | ||
| out_lol_h = 0 | ||
| for meisnub, sedlife in ujwal_liness: | ||
| if sedlife: | ||
| out_lol_h += int(stark_h / meisnub) + margin_size | ||
| out_lol_h = sum( | ||
| int(stark_h / meisnub) + margin_size | ||
| for meisnub, sedlife in ujwal_liness | ||
| if sedlife | ||
| ) | ||
|
|
||
| if not out_lol_h: | ||
| return None | ||
| final_image = Image.new('RGB', (width, int(out_lol_h)), (35, 35, 35)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,32 +179,32 @@ async def fetch_all_fed(client, message): | |
| pass | ||
| await asyncio.sleep(7) | ||
| sed = (await client.get_history("@MissRose_bot", 1))[0] | ||
| if sed.media: | ||
| fed_file = await sed.download() | ||
| file = open(fed_file, "r") | ||
| lines = file.readlines() | ||
| for line in lines: | ||
| try: | ||
| fed_list.append(line[:36]) | ||
| except BaseException: | ||
| pass | ||
| os.remove(fed_file) | ||
| else: | ||
| if not sed.media: | ||
| return None | ||
| fed_file = await sed.download() | ||
| file = open(fed_file, "r") | ||
| lines = file.readlines() | ||
| for line in lines: | ||
| try: | ||
| fed_list.append(line[:36]) | ||
| except BaseException: | ||
| pass | ||
| os.remove(fed_file) | ||
| else: | ||
| X = ok.text | ||
| lol = X.splitlines() | ||
| if "you are the owner" in X.lower(): | ||
| for lo in lol: | ||
| if "you are the owner" not in lo.lower(): | ||
| if "you are admin" not in lo.lower(): | ||
| if lo[:36] != "": | ||
| if not lo.startswith("-"): | ||
| fed_list.append(lo[:36]) | ||
| else: | ||
| fed_list.append(lo[2:38]) | ||
| if ( | ||
| "you are the owner" not in lo.lower() | ||
| and "you are admin" not in lo.lower() | ||
| and lo[:36] != "" | ||
| ): | ||
| if not lo.startswith("-"): | ||
| fed_list.append(lo[:36]) | ||
| else: | ||
| fed_list.append(lo[2:38]) | ||
| else: | ||
| Y = X[44:].splitlines() | ||
| for lol in Y: | ||
| fed_list.append(lol[2:38]) | ||
| fed_list.extend(lol[2:38] for lol in Y) | ||
|
Comment on lines
-182
to
+209
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return fed_list | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,5 +54,5 @@ async def git(client, message): | |
| if qw.get("created_at"): | ||
| txt += f'<b>Created At :</b> <code>{qw.get("created_at")}</code>' | ||
| if qw.get("archived") == True: | ||
| txt += f"<b>This Project is Archived</b>" | ||
| txt += "<b>This Project is Archived</b>" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| await pablo.edit(txt, disable_web_page_preview=True) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,10 +87,7 @@ async def remove_nsfw(client, message): | |
| async def is_harem_enabled(f, client, message): | ||
| if Config.ENABLE_WAIFU_FOR_ALL_CHATS: | ||
| return bool(True) | ||
| if await is_chat_in_db(int(message.chat.id)): | ||
| return bool(True) | ||
| else: | ||
| return bool(False) | ||
| return bool(True) if await is_chat_in_db(int(message.chat.id)) else bool(False) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| async def harem_event(f, client, message): | ||
| if not message: | ||
|
|
@@ -117,11 +114,11 @@ def get_data(img): | |
| harem_event = filters.create(func=harem_event, name="harem_event") | ||
| is_harem_enabled = filters.create(func=is_harem_enabled, name="is_harem_enabled") | ||
|
|
||
| @listen(filters.user([int(792028928)]) & ~filters.edited & is_harem_enabled & harem_event & filters.group) | ||
| @listen(filters.user([792028928]) & ~filters.edited & is_harem_enabled & harem_event & filters.group) | ||
| async def harem_catcher(client, message): | ||
| img = await message.download() | ||
| fetchUrl = await get_data(img) | ||
| match = await ParseSauce(fetchUrl + "&preferences?hl=en&fg=1#languages") | ||
| match = await ParseSauce(f'{fetchUrl}&preferences?hl=en&fg=1#languages') | ||
|
Comment on lines
-120
to
+121
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| guessp = match["best_guess"] | ||
| if not guessp: | ||
| return logging.info("(Waifu Catch Failed.) \nERROR : 404: Waifu Not Found.") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,9 +33,7 @@ def gdrive(self, url): | |
| url = f'{drive}/uc?export=download&id={file_id}' | ||
| download = requests.get(url, stream=True, allow_redirects=False) | ||
| cookies = download.cookies | ||
| dl_url = None | ||
| if download.headers: | ||
| dl_url = download.headers.get("location") | ||
| dl_url = download.headers.get("location") if download.headers else None | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if not dl_url: | ||
| page = BeautifulSoup(download.content, 'lxml') | ||
| export = drive + page.find('a', {'id': 'uc-download-url'}).get('href') | ||
|
|
@@ -48,7 +46,7 @@ def gdrive(self, url): | |
|
|
||
| async def mega_dl(self, url): | ||
| path = parse_url(url).split('!') | ||
| if path == None: | ||
| if path is None: | ||
|
Comment on lines
-51
to
+49
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return None, None, None | ||
| file_handle = path[0] | ||
| file_key = path[1] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
_refactored with the following changes:use-join)