Conversation
| Sed = "" | ||
| for match in result: | ||
| Sed += match.get_text() + "\n\n" | ||
| Sed = "".join(match.get_text() + "\n\n" for match in result) |
There was a problem hiding this comment.
Function _ refactored with the following changes:
- Use str.join() instead of for loop (
use-join)
| 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)): |
There was a problem hiding this comment.
Function download_file refactored with the following changes:
- Move assignments closer to their usage (
move-assign) - Simplify division expressions. (
simplify-division) - Replace unused for index with underscore (
for-index-underscore)
| 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")) |
There was a problem hiding this comment.
Function send_file refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity) - Replace if statement with if expression (
assign-if-exp) - Move setting of default value for variable into
elsebranch (introduce-default-else) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| 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**") |
There was a problem hiding this comment.
Function download_ refactored with the following changes:
- Use x is None rather than x == None (
none-compare) - Replace f-string with no interpolated values with string (
remove-redundant-fstring) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| 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)}" |
There was a problem hiding this comment.
Function make_carbon refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| return | ||
| return | ||
| if not group_call.is_connected: | ||
| await m_.edit("`Is Group Call Even Connected?`") | ||
| return | ||
| return |
There was a problem hiding this comment.
Function ski_p refactored with the following changes:
- Remove unnecessary casts to int, str and float (
remove-unnecessary-cast)
| input_str = get_text(message) | ||
| if not input_str: | ||
| if not message.reply_to_message: | ||
| return await u_s.edit_text("`Reply To A File To PLay It.`") | ||
| if message.reply_to_message.audio: | ||
| await u_s.edit_text("`Please Wait, Let Me Download This File!`") | ||
| audio = message.reply_to_message.audio | ||
| audio_original = await message.reply_to_message.download() | ||
| vid_title = audio.title or audio.file_name | ||
| uploade_r = message.reply_to_message.audio.performer or "Unknown Artist." | ||
| dura_ = message.reply_to_message.audio.duration | ||
| dur = datetime.timedelta(seconds=dura_) | ||
| raw_file_name = ''.join([random.choice(string.ascii_lowercase) for i in range(5)]) + ".raw" | ||
| url = message.reply_to_message.link | ||
| else: | ||
| return await u_s.edit("`Reply To A File To PLay It.`") | ||
| if input_str := get_text(message): | ||
| search = SearchVideos(str(input_str), offset=1, mode="dict", max_results=1) | ||
| rt = search.result() | ||
| result_s = rt.get("search_result") | ||
| if not result_s: | ||
| return await u_s.edit(f"`No Song Found Matching With Query - {input_str}, Please Try Giving Some Other Name.`") | ||
| url = result_s[0]["link"] | ||
| dur = result_s[0]["duration"] | ||
| vid_title = result_s[0]["title"] | ||
| yt_id = result_s[0]["id"] | ||
| uploade_r = result_s[0]["channel"] | ||
| start = time.time() | ||
| try: | ||
| audio_original = await yt_dl(url, client, message, start) | ||
| except BaseException as e: | ||
| return await u_s.edit(f"**Failed To Download** \n**Error :** `{str(e)}`") | ||
| raw_file_name = ( | ||
| ''.join([random.choice(string.ascii_lowercase) for _ in range(5)]) | ||
| + ".raw" | ||
| ) | ||
|
|
||
| else: | ||
| search = SearchVideos(str(input_str), offset=1, mode="dict", max_results=1) | ||
| rt = search.result() | ||
| result_s = rt.get("search_result") | ||
| if not result_s: | ||
| return await u_s.edit(f"`No Song Found Matching With Query - {input_str}, Please Try Giving Some Other Name.`") | ||
| url = result_s[0]["link"] | ||
| dur = result_s[0]["duration"] | ||
| vid_title = result_s[0]["title"] | ||
| yt_id = result_s[0]["id"] | ||
| uploade_r = result_s[0]["channel"] | ||
| start = time.time() | ||
| try: | ||
| audio_original = await yt_dl(url, client, message, start) | ||
| except BaseException as e: | ||
| return await u_s.edit(f"**Failed To Download** \n**Error :** `{str(e)}`") | ||
| raw_file_name = ''.join([random.choice(string.ascii_lowercase) for i in range(5)]) + ".raw" | ||
| if not message.reply_to_message: | ||
| return await u_s.edit_text("`Reply To A File To PLay It.`") | ||
| if not message.reply_to_message.audio: | ||
| return await u_s.edit("`Reply To A File To PLay It.`") | ||
| await u_s.edit_text("`Please Wait, Let Me Download This File!`") | ||
| audio = message.reply_to_message.audio | ||
| audio_original = await message.reply_to_message.download() | ||
| vid_title = audio.title or audio.file_name | ||
| uploade_r = message.reply_to_message.audio.performer or "Unknown Artist." | ||
| dura_ = message.reply_to_message.audio.duration | ||
| dur = datetime.timedelta(seconds=dura_) | ||
| raw_file_name = ( | ||
| ''.join([random.choice(string.ascii_lowercase) for _ in range(5)]) | ||
| + ".raw" | ||
| ) | ||
|
|
||
| url = message.reply_to_message.link |
There was a problem hiding this comment.
Function play_m refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Replace unused for index with underscore (
for-index-underscore)
| file_name = str(ytdl_data['id']) + ".mp3" | ||
| return file_name | ||
| return str(ytdl_data['id']) + ".mp3" |
There was a problem hiding this comment.
Function yt_dl refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| g_s_ = GPC.get((message.chat.id, client.me.id)) | ||
| if g_s_: | ||
| if g_s_ := GPC.get((message.chat.id, client.me.id)): | ||
| if g_s_.is_connected: | ||
| await g_s_.stop() | ||
| del GPC[(message.chat.id, client.me.id)] | ||
| s = await edit_or_reply(message, "`Please Wait.`") | ||
| s = await edit_or_reply(message, "`Please Wait.`") |
There was a problem hiding this comment.
Function radio_s refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| group_call = RD_.get((message.chat.id, client.me.id)) | ||
| if group_call: | ||
| if group_call.is_connected: | ||
| await group_call.stop() | ||
| else: | ||
| return await msg.edit("`Is Vc is Connected?`") | ||
| if not (group_call := RD_.get((message.chat.id, client.me.id))): | ||
| return await msg.edit("`Is Vc is Connected?`") | ||
| if group_call.is_connected: | ||
| await group_call.stop() |
There was a problem hiding this comment.
Function stop_radio refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Use named expression to simplify assignment and conditional (
use-named-expression)
| return | ||
| return | ||
| if not group_call.is_connected: | ||
| await edit_or_reply(message, "`Is Group Call Even Connected?`") | ||
| return | ||
| return | ||
| group_call.resume_playout() | ||
| await edit_or_reply(message, f"`▶️ Resumed.`") | ||
| await edit_or_reply(message, "`▶️ Resumed.`") |
There was a problem hiding this comment.
Function wow_dont_stop_songs refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| return | ||
| await group_call.reconnect() | ||
| await edit_or_reply(message, f"`Rejoined! - Vc`") | ||
| await edit_or_reply(message, "`Rejoined! - Vc`") |
There was a problem hiding this comment.
Function rejoinvcpls refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| return await e_.edit("`Please Give Me An Query.`") | ||
| href = await get_url(query) | ||
| if href == None: | ||
| if href is None: |
There was a problem hiding this comment.
Function m_ refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| return await e_.edit("`Please Give Me An Query.`") | ||
| file_url, r_date, size, system, device = await realme_rom_search(query) | ||
| if file_url == None: | ||
| if file_url is None: |
There was a problem hiding this comment.
Function rm_s refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| dur = datetime.timedelta(seconds=dur) | ||
| thumb, by, title = await shazam(music_file) | ||
| if title == None: | ||
| if title is None: |
There was a problem hiding this comment.
Function shazam_ refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| dl_url = None | ||
| if download.headers: | ||
| dl_url = download.headers.get("location") | ||
| dl_url = download.headers.get("location") if download.headers else None |
There was a problem hiding this comment.
Function AnyDL.gdrive refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Move setting of default value for variable into
elsebranch (introduce-default-else)
| if path == None: | ||
| if path is None: |
There was a problem hiding this comment.
Function AnyDL.mega_dl refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| if '/file/' in url: | ||
| url = url.replace(' ', '') | ||
| file_id = re.findall(r'\W\w\w\w\w\w\w\w\w\W', url)[0][1:-1] | ||
| id_index = re.search(file_id, url).end() | ||
| key = url[id_index + 1:] | ||
| return f'{file_id}!{key}' | ||
| elif '!' in url: | ||
| match = re.findall(r'/#!(.*)', url) | ||
| path = match[0] | ||
| return path | ||
| else: | ||
| return None | ||
| if '/file/' in url: | ||
| url = url.replace(' ', '') | ||
| file_id = re.findall(r'\W\w\w\w\w\w\w\w\w\W', url)[0][1:-1] | ||
| id_index = re.search(file_id, url).end() | ||
| key = url[id_index + 1:] | ||
| return f'{file_id}!{key}' | ||
| elif '!' in url: | ||
| match = re.findall(r'/#!(.*)', url) | ||
| return match[0] | ||
| else: | ||
| return None |
There was a problem hiding this comment.
Function parse_url refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| path = parse_url(url).split('!') | ||
| if path == None: | ||
| return None, None, None | ||
| file_handle = path[0] | ||
| file_key = path[1] | ||
| file_key = base64_to_a32(file_key) | ||
| file_data = await api_request({ | ||
| 'a': 'g', | ||
| 'g': 1, | ||
| 'p': file_handle | ||
| }) | ||
| k = (file_key[0] ^ file_key[4], file_key[1] ^ file_key[5], | ||
| file_key[2] ^ file_key[6], file_key[3] ^ file_key[7]) | ||
| if 'g' not in file_data: | ||
| return None, None, None | ||
| file_url = file_data['g'] | ||
| file_size = file_data['s'] | ||
| attribs = base64_url_decode(file_data['at']) | ||
| attribs = decrypt_attr(attribs, k) | ||
| file_name = attribs['n'] | ||
| return file_name,file_size, file_url | ||
| path = parse_url(url).split('!') | ||
| if path is None: | ||
| return None, None, None | ||
| file_handle = path[0] | ||
| file_key = path[1] | ||
| file_key = base64_to_a32(file_key) | ||
| file_data = await api_request({ | ||
| 'a': 'g', | ||
| 'g': 1, | ||
| 'p': file_handle | ||
| }) | ||
| k = (file_key[0] ^ file_key[4], file_key[1] ^ file_key[5], | ||
| file_key[2] ^ file_key[6], file_key[3] ^ file_key[7]) | ||
| if 'g' not in file_data: | ||
| return None, None, None | ||
| file_url = file_data['g'] | ||
| file_size = file_data['s'] | ||
| attribs = base64_url_decode(file_data['at']) | ||
| attribs = decrypt_attr(attribs, k) | ||
| file_name = attribs['n'] | ||
| return file_name,file_size, file_url |
There was a problem hiding this comment.
Function download_file refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| url = f'https://g.api.mega.co.nz/cs' | ||
| url = 'https://g.api.mega.co.nz/cs' |
There was a problem hiding this comment.
Function api_request refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.67%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Pull Request #11 refactored by Sourcery.
If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
unstablebranch, then run:Help us improve this pull request!