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
Add files via upload (Sourcery refactored) #26
Conversation
if ufc is not None: | ||
auser = ufc | ||
else: | ||
auser = user | ||
auser = ufc if ufc is not None else user | ||
find_gc = await DC.find_one({'_id': gid}) | ||
if find_gc is not None and 'anime' in find_gc['cmd_list'].split(): | ||
return | ||
if len(text) == 1: | ||
k = await message.reply_text( | ||
"""Please give a query to search about | ||
if len(text) == 1: | ||
k = await message.reply_text( | ||
"""Please give a query to search about | ||
example: /anime Ao Haru Ride""" | ||
) | ||
await asyncio.sleep(5) | ||
return await k.delete() | ||
) | ||
await asyncio.sleep(5) | ||
return await k.delete() | ||
query = text[1] | ||
auth = False | ||
vars_ = {"search": query} | ||
if query.isdigit(): | ||
vars_ = {"id": int(query)} | ||
if (await AUTH_USERS.find_one({"id": auser})): | ||
auth = True | ||
auth = bool((await AUTH_USERS.find_one({"id": auser}))) |
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 anime_cmd
refactored with the following changes:
- Replace if statement with if expression [×2] (
assign-if-exp
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Move setting of default value for variable into
else
branch (introduce-default-else
)
if ufc is not None: | ||
auser = ufc | ||
else: | ||
auser = user | ||
auser = ufc if ufc is not None else user | ||
find_gc = await DC.find_one({'_id': gid}) | ||
if find_gc is not None and 'manga' in find_gc['cmd_list'].split(): | ||
return | ||
if len(text) == 1: | ||
k = await message.reply_text( | ||
"""Please give a query to search about | ||
if len(text) == 1: | ||
k = await message.reply_text( | ||
"""Please give a query to search about | ||
example: /manga The teasing master Takagi san""" | ||
) | ||
await asyncio.sleep(5) | ||
return await k.delete() | ||
) | ||
await asyncio.sleep(5) | ||
return await k.delete() | ||
query = text[1] | ||
qdb = rand_key() | ||
MANGA_DB[qdb] = query | ||
auth = False | ||
if (await AUTH_USERS.find_one({"id": auser})): | ||
auth = True | ||
auth = bool((await AUTH_USERS.find_one({"id": auser}))) |
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 manga_cmd
refactored with the following changes:
- Replace if statement with if expression [×2] (
assign-if-exp
) - Move setting of default value for variable into
else
branch (introduce-default-else
) - Simplify boolean if expression (
boolean-if-exp-identity
)
if ufc is not None: | ||
auser = ufc | ||
else: | ||
auser = user | ||
auser = ufc if ufc is not None else user |
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 character_cmd
refactored with the following changes:
- Replace if statement with if expression [×2] (
assign-if-exp
) - Move setting of default value for variable into
else
branch (introduce-default-else
) - Simplify boolean if expression (
boolean-if-exp-identity
)
if ufc is not None: | ||
auser = ufc | ||
else: | ||
auser = user | ||
auser = ufc if ufc is not None else user |
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 anilist_cmd
refactored with the following changes:
- Replace if statement with if expression [×2] (
assign-if-exp
) - Move setting of default value for variable into
else
branch (introduce-default-else
) - Simplify boolean if expression (
boolean-if-exp-identity
)
if not len(query) == 2: | ||
k = await message.reply_text( | ||
"""Please give an anilist username to search about | ||
if len(query) != 2: | ||
k = await message.reply_text( | ||
"""Please give an anilist username to search about | ||
example: /user Lostb053""" | ||
) | ||
await asyncio.sleep(5) | ||
return await k.delete() | ||
) | ||
await asyncio.sleep(5) | ||
return await k.delete() |
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 flex_cmd
refactored with the following changes:
- Simplify logical expression using De Morgan identities [×2] (
de-morgan
) - Replace if statement with if expression (
assign-if-exp
)
if "-100" in str(user): | ||
auser = await gcc(user) | ||
else: | ||
auser = user | ||
auser = await gcc(user) if "-100" in str(user) else user |
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 flex_btn
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if "-100" in str(q[5]): | ||
auser = await gcc(q[5]) | ||
else: | ||
auser = q[5] | ||
auser = await gcc(q[5]) if "-100" in str(q[5]) else q[5] |
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 favourites_btn
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if "-100" in str(query): | ||
auser = await gcc(query) | ||
else: | ||
auser = query | ||
auser = await gcc(query) if "-100" in str(query) else query |
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 get_user_back_btn
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if "-100" in str(user): | ||
auser = await gcc(user) | ||
else: | ||
auser = user | ||
auser = await gcc(user) if "-100" in str(user) else user |
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 toggle_favourites_btn
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
result = result[:940] + "..." | ||
if spoiler is False: | ||
result = f"{result[:940]}..." | ||
if not spoiler: |
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 additional_info_btn
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Simplify comparison to boolean (
simplify-boolean-comparison
)
if result[0] is False: | ||
await cq.answer("No Data Available!!!", show_alert=True) | ||
return | ||
if result[0] is False: | ||
await cq.answer("No Data Available!!!", show_alert=True) | ||
return |
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 featured_in_btn
refactored with the following changes:
- Hoist conditional out of nested conditional (
hoist-if-from-if
)
button.append([InlineKeyboardButton( | ||
text=f"{bt}", | ||
callback_data=f"{reqb}_{idm}_0_{qry}_{pg}_{auth}_{user}" | ||
)]) | ||
button.append([InlineKeyboardButton( | ||
text="Back", | ||
callback_data=f"page_CHARACTER_{qry}_{pg}_{auth}_{user}" | ||
)]) | ||
button.extend( | ||
( | ||
[ | ||
InlineKeyboardButton( | ||
text=f"{bt}", | ||
callback_data=f"{reqb}_{idm}_0_{qry}_{pg}_{auth}_{user}", | ||
) | ||
], | ||
[ | ||
InlineKeyboardButton( | ||
text="Back", | ||
callback_data=f"page_CHARACTER_{qry}_{pg}_{auth}_{user}", | ||
) | ||
], | ||
) | ||
) | ||
|
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 featured_in_switch_btn
refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
)
pin_msg = f"Auto Pin: OFF" | ||
else: | ||
await collection.insert_one({"_id": gid}) | ||
src_status = f"{srcname}: ON" | ||
pin_msg = f"Auto Pin: OFF" | ||
pin_msg = "Auto Pin: OFF" |
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 headlines_btn
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
) - Replace f-string with no interpolated values with string [×2] (
remove-redundant-fstring
)
unpin = int(qry) | ||
setting = {"unpin": 0} | ||
else: | ||
now = round(time.time(), -2) | ||
unpin = int(qry) | ||
setting = {"unpin": int(qry), "next_unpin": int(qry)+int(now)} | ||
unpin = int(qry) |
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 auto_unpin
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
enable = False if not 'enable' in cmd[0] else True | ||
enable = 'enable' in cmd[0] |
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 en_dis__able_cmd
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Hoist repeated code outside conditional statement [×3] (
hoist-statement-from-if
) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
) - Swap if/else branches of if expression to remove negation (
swap-if-expression
) - Simplify comparison to boolean (
simplify-boolean-comparison
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
elif int(page)==1: | ||
btns.append([ | ||
InlineKeyboardButton( | ||
"Next", callback_data=f"stuani_2_{id_}_{rp}_{qry}_{auth}_{duser}" | ||
) | ||
]) | ||
else: | ||
if int(page)==1: | ||
btns.append([ | ||
InlineKeyboardButton( | ||
"Next", callback_data=f"stuani_2_{id_}_{rp}_{qry}_{auth}_{duser}" | ||
) | ||
]) | ||
else: | ||
btns.append([ | ||
InlineKeyboardButton( | ||
"Prev", | ||
callback_data=f"stuani_{int(page)-1}_{id_}_{rp}_{qry}_{auth}_{duser}" | ||
), | ||
InlineKeyboardButton( | ||
"Next", | ||
callback_data=f"stuani_{int(page)+1}_{id_}_{rp}_{qry}_{auth}_{duser}" | ||
) | ||
]) | ||
btns.append([ | ||
InlineKeyboardButton( | ||
"Prev", | ||
callback_data=f"stuani_{int(page)-1}_{id_}_{rp}_{qry}_{auth}_{duser}" | ||
), | ||
InlineKeyboardButton( | ||
"Next", | ||
callback_data=f"stuani_{int(page)+1}_{id_}_{rp}_{qry}_{auth}_{duser}" | ||
) | ||
]) |
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 get_studio_animes
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
msg = "**Tags List:**\n\n`" | ||
kek = [] | ||
for i in result['data']['MediaTagCollection']: | ||
if text is not None and 'nsfw' in text: | ||
if str(i['isAdult'])!='False': | ||
kek.append(i['name']) | ||
else: | ||
if str(i['isAdult'])=='False': | ||
kek.append(i['name']) | ||
msg += ", ".join(kek) | ||
kek = [ | ||
i['name'] | ||
for i in result['data']['MediaTagCollection'] | ||
if text is not None | ||
and 'nsfw' in text | ||
and str(i['isAdult']) != 'False' | ||
or (text is None or 'nsfw' not in text) | ||
and str(i['isAdult']) == 'False' | ||
] | ||
|
||
msg = "**Tags List:**\n\n`" + ", ".join(kek) |
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 get_all_tags
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Convert for loop into list comprehension (
list-comprehension
) - Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign
)
if rc_ls == []: | ||
if not rc_ls: |
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 get_recommendations
refactored with the following changes:
- Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison
)
return [f"No results Found"] | ||
return ["No results Found"] | ||
nsls = await get_all_tags('nsfw') | ||
nsfw = True if gnr.lower() in nsls.lower() else False | ||
nsfw = gnr.lower() in nsls.lower() |
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 get_top_animes
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Simplify sequence length comparison (
simplify-len-comparison
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
out_ = [] | ||
if req == "ANI": | ||
out = "ANIMES:\n\n" | ||
out_ = [] |
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 get_featured_in_lists
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
) - Simplify comparison to string length (
simplify-str-len-comparison
)
charlist = [] | ||
for char in data["characters"]['edges']: | ||
charlist.append( | ||
f"• `{char['node']['name']['full']}` ({char['role']})" | ||
) | ||
charlist = [ | ||
f"• `{char['node']['name']['full']}` ({char['role']})" | ||
for char in data["characters"]['edges'] | ||
] | ||
|
||
chrctrs = ("\n").join(charlist) | ||
charls = f"{chrctrs}" if len(charlist) != 0 else "" | ||
charls = f"{chrctrs}" if charlist else "" | ||
return pic, charls, data["characters"]['pageInfo'] | ||
else: | ||
prqlsql = data.get("relations").get("edges") | ||
ps = "" | ||
for i in prqlsql: | ||
ps += ( | ||
ps = "".join( | ||
( | ||
f'• {i["node"]["title"]["romaji"]} ' | ||
+f'({i["node"]["type"]}) `{i["relationType"]}`\n' | ||
+ f'({i["node"]["type"]}) `{i["relationType"]}`\n' | ||
) | ||
for i in prqlsql | ||
) | ||
|
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 get_additional_info
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Simplify sequence length comparison (
simplify-len-comparison
) - Use str.join() instead of for loop (
use-join
)
URLS_SUFFIX = [re.search('translate.google.(.*)', url.strip()).group(1) for url in DEFAULT_SERVICE_URLS] | ||
URLS_SUFFIX = [ | ||
re.search('translate.google.(.*)', url.strip())[1] | ||
for url in DEFAULT_SERVICE_URLS | ||
] | ||
|
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.
Lines 193-193
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
return "{}. Probable cause: {}".format(premise, "timeout") | ||
# if tts.tld != 'com': | ||
# host = _translate_url(tld=tts.tld) | ||
# cause = "Host '{}' is not reachable".format(host) | ||
return f"{premise}. Probable cause: timeout" | ||
# if tts.tld != 'com': | ||
# host = _translate_url(tld=tts.tld) | ||
# cause = "Host '{}' is not reachable".format(host) |
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 google_new_transError.infer_msg
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
)
url_base = "https://translate.google.{}".format(self.url_suffix) | ||
self.url = url_base + "/_/TranslateWebserverUi/data/batchexecute" | ||
url_base = f"https://translate.google.{self.url_suffix}" | ||
self.url = f"{url_base}/_/TranslateWebserverUi/data/batchexecute" |
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 google_translator.__init__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
# text_urldecode = quote(text.strip()) | ||
freq_initial = "f.req={}&".format(quote(espaced_rpc)) | ||
freq = freq_initial | ||
return freq | ||
return f"f.req={quote(espaced_rpc)}&" |
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 google_translator._package_rpc
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
) - Inline variable that is immediately returned [×2] (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# text_urldecode = quote(text.strip())
th = ( | ||
"st" if x == "1" | ||
else "nd" if x == "2" | ||
else "rd" if x == "3" | ||
else "th" | ||
return ( | ||
"st" if x == "1" else "nd" if x == "2" else "rd" if x == "3" else "th" | ||
) | ||
return th |
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 pos_no
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
((str(days) + " Days, ") if days else "") | ||
+ ((str(hours) + " Hours, ") if hours else "") | ||
+ ((str(minutes) + " Minutes, ") if minutes else "") | ||
+ ((str(seconds) + " Seconds, ") if seconds else "") | ||
+ ((str(milliseconds) + " ms, ") if milliseconds else "") | ||
(f"{str(days)} Days, " if days else "") | ||
+ (f"{str(hours)} Hours, " if hours else "") | ||
+ (f"{str(minutes)} Minutes, " if minutes else "") | ||
+ (f"{str(seconds)} Seconds, " if seconds else "") | ||
+ (f"{str(milliseconds)} ms, " if milliseconds else "") | ||
) | ||
|
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 make_it_rw
refactored with the following changes:
- Use f-string instead of string concatenation [×5] (
use-fstring-for-concatenation
)
buttons.append([ | ||
InlineKeyboardButton( | ||
text="Characters", | ||
callback_data=( | ||
f"char_{result[2][0]}_ANI" | ||
+f"{qry}{pg}_{str(auth)}_1_{user}" | ||
) | ||
), | ||
InlineKeyboardButton( | ||
text="Description", | ||
callback_data=( | ||
f"desc_{result[2][0]}_ANI" | ||
+f"{qry}{pg}_{str(auth)}_{user}" | ||
) | ||
), | ||
InlineKeyboardButton( | ||
text="List Series", | ||
callback_data=( | ||
f"ls_{result[2][0]}_ANI" | ||
+f"{qry}{pg}_{str(auth)}_{user}" | ||
) | ||
), | ||
]) | ||
buttons.append( | ||
[ | ||
InlineKeyboardButton( | ||
text="Characters", | ||
callback_data=( | ||
f"char_{result[2][0]}_ANI" | ||
+ f"{qry}{pg}_{auth}_1_{user}" | ||
), | ||
), | ||
InlineKeyboardButton( | ||
text="Description", | ||
callback_data=( | ||
f"desc_{result[2][0]}_ANI" + f"{qry}{pg}_{auth}_{user}" | ||
), | ||
), | ||
InlineKeyboardButton( | ||
text="List Series", | ||
callback_data=( | ||
f"ls_{result[2][0]}_ANI" + f"{qry}{pg}_{auth}_{user}" | ||
), | ||
), | ||
] | ||
) | ||
|
||
if media == "CHARACTER": | ||
buttons.append([ | ||
InlineKeyboardButton( | ||
"Description", | ||
callback_data=( | ||
f"desc_{result[2][0]}_CHAR" | ||
+f"{qry}{pg}_{str(auth)}_{user}" | ||
) | ||
) | ||
]) | ||
buttons.append([ | ||
InlineKeyboardButton( | ||
"List Series", | ||
callback_data=f"lsc_{result[2][0]}{qry}{pg}_{str(auth)}_{user}" | ||
buttons.extend( | ||
( | ||
[ | ||
InlineKeyboardButton( | ||
"Description", | ||
callback_data=f"desc_{result[2][0]}_CHAR" | ||
+ f"{qry}{pg}_{auth}_{user}", | ||
) | ||
], | ||
[ | ||
InlineKeyboardButton( | ||
"List Series", | ||
callback_data=f"lsc_{result[2][0]}{qry}{pg}_{auth}_{user}", | ||
) | ||
], | ||
) | ||
]) | ||
) | ||
|
||
if media == "SCHEDULED": | ||
if result[0]!=0 and result[0]!=6: | ||
if result[0] not in [0, 6]: |
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 get_btns
refactored with the following changes:
- Remove unnecessary calls to
str()
from formatted values in f-strings [×13] (remove-str-from-fstring
) - Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
) - Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Simplify comparison to boolean (
simplify-boolean-comparison
) - Merge else clause's nested if statement into elif [×2] (
merge-else-if-into-elif
) - Swap if/else branches (
swap-if-else-branches
) - Swap positions of nested conditionals [×22] (
swap-nested-ifs
) - Hoist nested repeated code outside conditional statements [×22] (
hoist-similar-statement-from-if
) - Remove unnecessary casts to int, str, float or bool [×4] (
remove-unnecessary-cast
) - Remove redundant pass statement (
remove-redundant-pass
) - Remove redundant conditional (
remove-redundant-if
)
btn.append( | ||
InlineKeyboardButton( | ||
text=( | ||
"Add to Favs" if data[3] is not True | ||
else "Remove from Favs" | ||
btn.extend( | ||
( | ||
InlineKeyboardButton( | ||
text=( | ||
"Add to Favs" | ||
if data[3] is not True | ||
else "Remove from Favs" | ||
), | ||
callback_data=f"fav_{media}_{data[0]}{qry}{pg}_{user}", | ||
), | ||
InlineKeyboardButton( | ||
text="Add to List" | ||
if data[1] is False | ||
else "Update in List", | ||
callback_data=( | ||
f"lsadd_{media}_{data[0]}{qry}{pg}_{user}" | ||
if data[1] is False | ||
else f"lsupdt_{media}_{data[0]}_{data[2]}{qry}{pg}_{user}" | ||
), | ||
), | ||
callback_data=f"fav_{media}_{data[0]}{qry}{pg}_{user}" | ||
) | ||
) | ||
btn.append(InlineKeyboardButton( | ||
text="Add to List" if data[1] is False else "Update in List", | ||
callback_data=( | ||
f"lsadd_{media}_{data[0]}{qry}{pg}_{user}" if data[1] is False | ||
else f"lsupdt_{media}_{data[0]}_{data[2]}{qry}{pg}_{user}" | ||
) | ||
)) | ||
|
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 get_auth_btns
refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
)
if (await PIC_DB.find_one({'_id': link})) is None: | ||
await PIC_DB.insert_one({'_id': link}) | ||
if await PIC_DB.find_one({'_id': link}) is not None: | ||
continue | ||
await PIC_DB.insert_one({'_id': link}) | ||
try: | ||
me = await user.send_photo("me", f"{link}?a={ts}") | ||
msg = await user.send_photo("me", link) | ||
except ConnectionError: | ||
await asyncio.sleep(5) | ||
me = await user.send_photo("me", f"{link}?a={ts}") | ||
msg = await user.send_photo("me", link) | ||
await asyncio.sleep(7) | ||
dls1 = await user.download_media( | ||
msg.photo, | ||
file_name=DOWN_PATH + link.split("/").pop()+'(1).png', | ||
) | ||
dls2 = await user.download_media( | ||
me.photo, | ||
file_name=DOWN_PATH + link.split("/").pop()+'(2).png', | ||
) | ||
await asyncio.sleep(10) | ||
with open(dls1, 'rb') as p1: | ||
b1 = p1.read() | ||
with open(dls2, 'rb') as p2: | ||
b2 = p2.read() | ||
await user.delete_messages("me", [me.id, msg.id]) | ||
if b1!=b2: | ||
try: | ||
me = await user.send_photo("me", link+f"?a={ts}") | ||
msg = await user.send_photo("me", link) | ||
await user.send_message("webpagebot", link) | ||
except ConnectionError: | ||
await asyncio.sleep(5) | ||
me = await user.send_photo("me", link+f"?a={ts}") | ||
msg = await user.send_photo("me", link) | ||
await asyncio.sleep(7) | ||
dls1 = await user.download_media( | ||
msg.photo, | ||
file_name=DOWN_PATH + link.split("/").pop()+'(1).png', | ||
) | ||
dls2 = await user.download_media( | ||
me.photo, | ||
file_name=DOWN_PATH + link.split("/").pop()+'(2).png', | ||
) | ||
await asyncio.sleep(10) | ||
with open(dls1, 'rb') as p1: | ||
b1 = p1.read() | ||
with open(dls2, 'rb') as p2: | ||
b2 = p2.read() | ||
await user.delete_messages("me", [me.id, msg.id]) | ||
if b1!=b2: | ||
try: | ||
await user.send_message("webpagebot", link) | ||
except ConnectionError: | ||
await asyncio.sleep(5) | ||
await user.send_message("webpagebot", link) | ||
else: | ||
continue | ||
await user.send_message("webpagebot", link) |
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 update_pics_cache
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.35%.
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 #25 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
lostb053-patch-1
branch, then run:Help us improve this pull request!