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
Sourcery refactored dev branch #127
Conversation
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.
Due to GitHub API limits, only the first 60 comments can be shown.
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.
Message that will be displayed on users first pull request
6d8e00a
to
a9a4df2
Compare
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.
Due to GitHub API limits, only the first 60 comments can be shown.
button = [Button.inline("« Bᴀᴄᴋ", data=f"{name}")] | ||
return button | ||
return [Button.inline("« Bᴀᴄᴋ", data=f"{name}")] |
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_back_button
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
else: | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) |
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 rmbgapi
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
else: | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) |
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 rmbgapi
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
else: | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) |
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 rmbgapi
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
assistant/callbackstuffs.py
Outdated
thumb = "" | ||
for m in choices(sorted(glob("resources/extras/*.jpg"))): | ||
thumb += m | ||
thumb = "".join(choices(sorted(glob("resources/extras/*.jpg")))) | ||
await eve.answer("Sending...") | ||
if name.startswith("def"): | ||
plug_name = name.replace(f"def_plugin_", "") | ||
plug_name = name.replace('def_plugin_', "") |
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 send
refactored with the following changes:
- Use str.join() instead of for loop (
use-join
) - Simplify generator expression (
simplify-generator
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
else: | ||
if len(themssg) > 4090: | ||
return await conv.send_message( | ||
"Message too long!\nGive a shorter message please!!", | ||
buttons=get_back_button("pmcstm"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}\n\nAfter Setting All Things Do restart".format( | ||
name, | ||
themssg, | ||
), | ||
if len(themssg) > 4090: | ||
return await conv.send_message( | ||
"Message too long!\nGive a shorter message please!!", | ||
buttons=get_back_button("pmcstm"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}\n\nAfter Setting All Things Do restart".format( | ||
name, | ||
themssg, | ||
), | ||
buttons=get_back_button("pmcstm"), | ||
) |
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 name
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
and not response.text == "" | ||
and response.text != "" |
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 media
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
assistant/callbackstuffs.py
Outdated
f"Done!! AUTOAPPROVE Started!!", | ||
'Done!! AUTOAPPROVE Started!!', |
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 apon
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
assistant/callbackstuffs.py
Outdated
f"Done!! PMLOGGER Started!!", | ||
'Done!! PMLOGGER Started!!', |
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 pmlog
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
assistant/callbackstuffs.py
Outdated
f"Done! PMPermit has been turned on!!", | ||
'Done! PMPermit has been turned on!!', |
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 pmonn
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
assistant/callbackstuffs.py
Outdated
f"Done! PMPermit has been turned off!!", | ||
'Done! PMPermit has been turned 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 pmofff
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
assistant/callbackstuffs.py
Outdated
f"From This Feature U can chat with ppls Via ur Assistant Bot.\n[More info](https://t.me/UltroidUpdates/2)", | ||
'From This Feature U can chat with ppls Via ur Assistant Bot.\n[More info](https://t.me/UltroidUpdates/2)', |
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 chbot
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
else: | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}".format( | ||
name, | ||
themssg, | ||
), | ||
buttons=get_back_button("chatbot"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}".format( | ||
name, | ||
themssg, | ||
), | ||
buttons=get_back_button("chatbot"), | ||
) |
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 name
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
assistant/callbackstuffs.py
Outdated
f"From This Feature U can play songs in group voice chat\n\n[moreinfo](https://t.me/UltroidUpdates/4)", | ||
'From This Feature U can play songs in group voice chat\n\n[moreinfo](https://t.me/UltroidUpdates/4)', |
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 vcb
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
else: | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}\n\nAfter Setting All Things Do restart".format( | ||
name, | ||
themssg, | ||
), | ||
buttons=get_back_button("vcb"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}\n\nAfter Setting All Things Do restart".format( | ||
name, | ||
themssg, | ||
), | ||
buttons=get_back_button("vcb"), | ||
) |
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 name
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
plugins/_inline.py
Outdated
await o.answer(RES, switch_pm=f"👥 ULTROID PORTAL", switch_pm_param="start") | ||
await o.answer(RES, switch_pm='👥 ULTROID PORTAL', switch_pm_param="start") |
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 inline_alive
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
plugins/_inline.py
Outdated
changelog_str = changelog + f"\n\nClick the below button to update!" | ||
changelog_str = changelog + '\n\nClick the below button to update!' | ||
if len(changelog_str) > 1024: | ||
await event.edit(get_string("upd_4")) | ||
file = open(f"ultroid_updates.txt", "w+") | ||
file.write(tl_chnglog) | ||
file.close() | ||
with open('ultroid_updates.txt', "w+") as file: | ||
file.write(tl_chnglog) |
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
with
when opening file to ensure closure (ensure-file-closed
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
if emoji: | ||
multi = emoji | ||
else: | ||
multi = "✘" | ||
helpable_plugins = [] | ||
multi = emoji or "✘" | ||
global upage | ||
upage = page_number | ||
for p in loaded_plugins: | ||
helpable_plugins.append(p) | ||
helpable_plugins = [p for p in loaded_plugins] |
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 page_num
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Simplify if expression by using or (
or-if-exp-identity
) - Convert for loop into list comprehension (
list-comprehension
)
plugins/_wspr.py
Outdated
sur = e.builder.article( | ||
title="Type ur msg", | ||
text=f"You Didn't Type Your Msg", | ||
) | ||
sur = e.builder.article(title="Type ur msg", text="You Didn't Type Your Msg") |
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:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
plugins/admintools.py
Outdated
return await eor(msg, f"**ERROR:**`{str(e)}`") | ||
return await eor(msg, f'**ERROR:**`{e}`') |
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 pin
refactored with the following changes:
- Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
)
plugins/admintools.py
Outdated
return await xx.edit(f"**ERROR:**\n`{str(e)}`") | ||
return await xx.edit(f'**ERROR:**\n`{e}`') | ||
elif ch == "all": | ||
try: | ||
await ult.client.unpin_message(ult.chat_id) | ||
except BadRequestError: | ||
return await xx.edit("`Hmm.. Guess I have no rights here!`") | ||
except Exception as e: | ||
return await xx.edit(f"**ERROR:**`{str(e)}`") | ||
return await xx.edit(f'**ERROR:**`{e}`') |
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 unp
refactored with the following changes:
- Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
)
count = count + 1 | ||
count += 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 fastpurger
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
count = count + 1 | ||
count += 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 fastpurgerme
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
if e.reply_to_msg_id: | ||
name = (await e.get_reply_message()).sender | ||
try: | ||
await e.client(DeleteUserHistoryRequest(e.chat_id, name.id)) | ||
await eod(e, f"Successfully Purged All Messages from {name.first_name}") | ||
except Exception as er: | ||
return await eod(xx, str(er)) | ||
else: | ||
if not e.reply_to_msg_id: | ||
return await eod( | ||
xx, | ||
"`Reply to someone's msg to delete.`", | ||
) | ||
|
||
name = (await e.get_reply_message()).sender | ||
try: | ||
await e.client(DeleteUserHistoryRequest(e.chat_id, name.id)) | ||
await eod(e, f"Successfully Purged All Messages from {name.first_name}") | ||
except Exception as er: | ||
return await eod(xx, str(er)) |
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:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if event.is_private: | ||
if Redis("PMSETTING") == "True": | ||
if not is_approved(event.chat_id): | ||
return | ||
if ( | ||
event.is_private | ||
and Redis("PMSETTING") == "True" | ||
and not is_approved(event.chat_id) | ||
): | ||
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 set_not_afk
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
a = open(b) | ||
code = a.read() | ||
a.close() | ||
with open(b) as a: | ||
code = a.read() |
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 crbn
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
a = open(b) | ||
code = a.read() | ||
a.close() | ||
with open(b) as a: | ||
code = a.read() |
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 crbn
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
if not udB.get("AUTOPOST") == "True": | ||
if udB.get("AUTOPOST") != "True": |
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:
- Simplify logical expression using De Morgan identities (
de-morgan
)
elif type_of_group == "g" or type_of_group == "c": | ||
elif type_of_group in ["g", "c"]: | ||
try: | ||
r = await e.client( | ||
CreateChannelRequest( | ||
title=group_name, | ||
about="Join @TeamUltroid", | ||
megagroup=False if type_of_group == "c" else True, | ||
), | ||
megagroup=type_of_group != "c", | ||
) | ||
) | ||
|
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:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
plugins/compressor.py
Outdated
time_diff = time.time() - int(d_time) | ||
speed = round(elapse / time_diff, 2) | ||
if int(speed) != 0: | ||
some_eta = ((int(total_frames) - elapse) / speed) * 1000 | ||
text = f"`Compressing {file_name} at {crf} CRF.\n`" | ||
progress_str = "`[{0}{1}] {2}%\n\n`".format( | ||
"".join("●" for i in range(math.floor(per / 5))), | ||
"".join("" for i in range(20 - math.floor(per / 5))), | ||
round(per, 2), | ||
) | ||
] | ||
await e.client.send_file( | ||
e.chat_id, | ||
mmmm, | ||
thumb="resources/extras/ultroid.jpg", | ||
caption=caption, | ||
attributes=attributes, | ||
force_document=False, | ||
reply_to=e.reply_to_msg_id, | ||
) | ||
else: | ||
await e.client.send_file( | ||
e.chat_id, | ||
mmmm, | ||
thumb="resources/extras/ultroid.jpg", | ||
caption=caption, | ||
force_document=True, | ||
reply_to=e.reply_to_msg_id, | ||
|
||
e_size = ( | ||
humanbytes(size) + " of ~" + humanbytes((size / per) * 100) | ||
) | ||
eta = "~" + time_formatter(some_eta) | ||
try: | ||
await xxx.edit( | ||
text | ||
+ progress_str | ||
+ "`" | ||
+ e_size | ||
+ "`" | ||
+ "\n\n`" | ||
+ eta | ||
+ "`" | ||
) | ||
except MessageNotModifiedError: | ||
pass | ||
os.remove(file.name) | ||
c_size = os.path.getsize(out) | ||
f_time = time.time() | ||
difff = time_formatter((f_time - d_time) * 1000) | ||
await xxx.edit( | ||
f"`Compressed {humanbytes(o_size)} to {humanbytes(c_size)} in {difff}\nTrying to Upload...`" | ||
) | ||
differ = 100 - ((c_size / o_size) * 100) | ||
caption = f"**Original Size: **`{humanbytes(o_size)}`\n" | ||
caption += f"**Compressed Size: **`{humanbytes(c_size)}`\n" | ||
caption += f"**Compression Ratio: **`{differ:.2f}%`\n" | ||
caption += f"\n**Time Taken To Compress: **`{difff}`" | ||
mmmm = await uploader( | ||
out, | ||
out, | ||
f_time, | ||
xxx, | ||
"Uploading " + out + "...", | ||
) | ||
if to_stream: | ||
metadata = extractMetadata(createParser(out)) | ||
duration = metadata.get("duration").seconds | ||
hi, _ = await bash(f'mediainfo "{out}" | grep "Height"') | ||
wi, _ = await bash(f'mediainfo "{out}" | grep "Width"') | ||
height = int(hi.split(":")[1].split("pixels")[0].replace(" ", "")) | ||
width = int(wi.split(":")[1].split("pixels")[0].replace(" ", "")) | ||
attributes = [ | ||
DocumentAttributeVideo( | ||
duration=duration, w=width, h=height, supports_streaming=True | ||
) | ||
await xxx.delete() | ||
os.remove(out) | ||
] | ||
await e.client.send_file( | ||
e.chat_id, | ||
mmmm, | ||
thumb="resources/extras/ultroid.jpg", | ||
caption=caption, | ||
attributes=attributes, | ||
force_document=False, | ||
reply_to=e.reply_to_msg_id, | ||
) | ||
else: | ||
await eod(e, "`Reply To Video File Only`") | ||
await e.client.send_file( | ||
e.chat_id, | ||
mmmm, | ||
thumb="resources/extras/ultroid.jpg", | ||
caption=caption, | ||
force_document=True, | ||
reply_to=e.reply_to_msg_id, | ||
) | ||
await xxx.delete() | ||
os.remove(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 _
refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Replace unneeded comprehension with generator (
comprehension-to-generator
)
0fd1761
to
c518960
Compare
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.
Due to GitHub API limits, only the first 60 comments can be shown.
button = [Button.inline("« Bᴀᴄᴋ", data=f"{name}")] | ||
return button | ||
return [Button.inline("« Bᴀᴄᴋ", data=f"{name}")] |
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_back_button
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
else: | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) |
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 rmbgapi
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
else: | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) |
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 rmbgapi
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
else: | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
f"{name} changed to {themssg}", | ||
buttons=get_back_button("apiset"), | ||
) |
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 rmbgapi
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
assistant/callbackstuffs.py
Outdated
thumb = "" | ||
for m in choices(sorted(glob("resources/extras/*.jpg"))): | ||
thumb += m | ||
thumb = "".join(choices(sorted(glob("resources/extras/*.jpg")))) | ||
await eve.answer("Sending...") | ||
if name.startswith("def"): | ||
plug_name = name.replace(f"def_plugin_", "") | ||
plug_name = name.replace('def_plugin_', "") |
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 send
refactored with the following changes:
- Use str.join() instead of for loop (
use-join
) - Simplify generator expression (
simplify-generator
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
else: | ||
if len(themssg) > 4090: | ||
return await conv.send_message( | ||
"Message too long!\nGive a shorter message please!!", | ||
buttons=get_back_button("pmcstm"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}\n\nAfter Setting All Things Do restart".format( | ||
name, | ||
themssg, | ||
), | ||
if len(themssg) > 4090: | ||
return await conv.send_message( | ||
"Message too long!\nGive a shorter message please!!", | ||
buttons=get_back_button("pmcstm"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}\n\nAfter Setting All Things Do restart".format( | ||
name, | ||
themssg, | ||
), | ||
buttons=get_back_button("pmcstm"), | ||
) |
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 name
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
and not response.text == "" | ||
and response.text != "" |
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 media
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
assistant/callbackstuffs.py
Outdated
f"Done!! AUTOAPPROVE Started!!", | ||
'Done!! AUTOAPPROVE Started!!', |
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 apon
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
assistant/callbackstuffs.py
Outdated
f"Done!! PMLOGGER Started!!", | ||
'Done!! PMLOGGER Started!!', |
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 pmlog
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
assistant/callbackstuffs.py
Outdated
f"Done! PMPermit has been turned on!!", | ||
'Done! PMPermit has been turned on!!', |
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 pmonn
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
assistant/callbackstuffs.py
Outdated
f"Done! PMPermit has been turned off!!", | ||
'Done! PMPermit has been turned 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 pmofff
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
assistant/callbackstuffs.py
Outdated
f"From This Feature U can chat with ppls Via ur Assistant Bot.\n[More info](https://t.me/UltroidUpdates/2)", | ||
'From This Feature U can chat with ppls Via ur Assistant Bot.\n[More info](https://t.me/UltroidUpdates/2)', |
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 chbot
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
else: | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}".format( | ||
name, | ||
themssg, | ||
), | ||
buttons=get_back_button("chatbot"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}".format( | ||
name, | ||
themssg, | ||
), | ||
buttons=get_back_button("chatbot"), | ||
) |
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 name
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
assistant/callbackstuffs.py
Outdated
f"From This Feature U can play songs in group voice chat\n\n[moreinfo](https://t.me/UltroidUpdates/4)", | ||
'From This Feature U can play songs in group voice chat\n\n[moreinfo](https://t.me/UltroidUpdates/4)', |
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 vcb
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
else: | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}\n\nAfter Setting All Things Do restart".format( | ||
name, | ||
themssg, | ||
), | ||
buttons=get_back_button("vcb"), | ||
) | ||
await setit(event, var, themssg) | ||
await conv.send_message( | ||
"{} changed to {}\n\nAfter Setting All Things Do restart".format( | ||
name, | ||
themssg, | ||
), | ||
buttons=get_back_button("vcb"), | ||
) |
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 name
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
plugins/_inline.py
Outdated
await o.answer(RES, switch_pm=f"👥 ULTROID PORTAL", switch_pm_param="start") | ||
await o.answer(RES, switch_pm='👥 ULTROID PORTAL', switch_pm_param="start") |
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 inline_alive
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
plugins/_inline.py
Outdated
changelog_str = changelog + f"\n\nClick the below button to update!" | ||
changelog_str = changelog + '\n\nClick the below button to update!' | ||
if len(changelog_str) > 1024: | ||
await event.edit(get_string("upd_4")) | ||
file = open(f"ultroid_updates.txt", "w+") | ||
file.write(tl_chnglog) | ||
file.close() | ||
with open('ultroid_updates.txt', "w+") as file: | ||
file.write(tl_chnglog) |
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
with
when opening file to ensure closure (ensure-file-closed
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
if emoji: | ||
multi = emoji | ||
else: | ||
multi = "✘" | ||
helpable_plugins = [] | ||
multi = emoji or "✘" | ||
global upage | ||
upage = page_number | ||
for p in loaded_plugins: | ||
helpable_plugins.append(p) | ||
helpable_plugins = [p for p in loaded_plugins] |
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 page_num
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Simplify if expression by using or (
or-if-exp-identity
) - Convert for loop into list comprehension (
list-comprehension
)
plugins/_wspr.py
Outdated
sur = e.builder.article( | ||
title="Type ur msg", | ||
text=f"You Didn't Type Your Msg", | ||
) | ||
sur = e.builder.article(title="Type ur msg", text="You Didn't Type Your Msg") |
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:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
plugins/admintools.py
Outdated
return await eor(msg, f"**ERROR:**`{str(e)}`") | ||
return await eor(msg, f'**ERROR:**`{e}`') |
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 pin
refactored with the following changes:
- Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
)
plugins/admintools.py
Outdated
return await xx.edit(f"**ERROR:**\n`{str(e)}`") | ||
return await xx.edit(f'**ERROR:**\n`{e}`') | ||
elif ch == "all": | ||
try: | ||
await ult.client.unpin_message(ult.chat_id) | ||
except BadRequestError: | ||
return await xx.edit("`Hmm.. Guess I have no rights here!`") | ||
except Exception as e: | ||
return await xx.edit(f"**ERROR:**`{str(e)}`") | ||
return await xx.edit(f'**ERROR:**`{e}`') |
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 unp
refactored with the following changes:
- Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
)
count = count + 1 | ||
count += 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 fastpurger
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
count = count + 1 | ||
count += 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 fastpurgerme
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
if e.reply_to_msg_id: | ||
name = (await e.get_reply_message()).sender | ||
try: | ||
await e.client(DeleteUserHistoryRequest(e.chat_id, name.id)) | ||
await eod(e, f"Successfully Purged All Messages from {name.first_name}") | ||
except Exception as er: | ||
return await eod(xx, str(er)) | ||
else: | ||
if not e.reply_to_msg_id: | ||
return await eod( | ||
xx, | ||
"`Reply to someone's msg to delete.`", | ||
) | ||
|
||
name = (await e.get_reply_message()).sender | ||
try: | ||
await e.client(DeleteUserHistoryRequest(e.chat_id, name.id)) | ||
await eod(e, f"Successfully Purged All Messages from {name.first_name}") | ||
except Exception as er: | ||
return await eod(xx, str(er)) |
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:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if event.is_private: | ||
if Redis("PMSETTING") == "True": | ||
if not is_approved(event.chat_id): | ||
return | ||
if ( | ||
event.is_private | ||
and Redis("PMSETTING") == "True" | ||
and not is_approved(event.chat_id) | ||
): | ||
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 set_not_afk
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
a = open(b) | ||
code = a.read() | ||
a.close() | ||
with open(b) as a: | ||
code = a.read() |
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 crbn
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
a = open(b) | ||
code = a.read() | ||
a.close() | ||
with open(b) as a: | ||
code = a.read() |
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 crbn
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
if not udB.get("AUTOPOST") == "True": | ||
if udB.get("AUTOPOST") != "True": |
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:
- Simplify logical expression using De Morgan identities (
de-morgan
)
elif type_of_group == "g" or type_of_group == "c": | ||
elif type_of_group in ["g", "c"]: | ||
try: | ||
r = await e.client( | ||
CreateChannelRequest( | ||
title=group_name, | ||
about="Join @TeamUltroid", | ||
megagroup=False if type_of_group == "c" else True, | ||
), | ||
megagroup=type_of_group != "c", | ||
) | ||
) | ||
|
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:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
plugins/compressor.py
Outdated
time_diff = time.time() - int(d_time) | ||
speed = round(elapse / time_diff, 2) | ||
if int(speed) != 0: | ||
some_eta = ((int(total_frames) - elapse) / speed) * 1000 | ||
text = f"`Compressing {file_name} at {crf} CRF.\n`" | ||
progress_str = "`[{0}{1}] {2}%\n\n`".format( | ||
"".join("●" for i in range(math.floor(per / 5))), | ||
"".join("" for i in range(20 - math.floor(per / 5))), | ||
round(per, 2), | ||
) | ||
] | ||
await e.client.send_file( | ||
e.chat_id, | ||
mmmm, | ||
thumb="resources/extras/ultroid.jpg", | ||
caption=caption, | ||
attributes=attributes, | ||
force_document=False, | ||
reply_to=e.reply_to_msg_id, | ||
) | ||
else: | ||
await e.client.send_file( | ||
e.chat_id, | ||
mmmm, | ||
thumb="resources/extras/ultroid.jpg", | ||
caption=caption, | ||
force_document=True, | ||
reply_to=e.reply_to_msg_id, | ||
|
||
e_size = ( | ||
humanbytes(size) + " of ~" + humanbytes((size / per) * 100) | ||
) | ||
eta = "~" + time_formatter(some_eta) | ||
try: | ||
await xxx.edit( | ||
text | ||
+ progress_str | ||
+ "`" | ||
+ e_size | ||
+ "`" | ||
+ "\n\n`" | ||
+ eta | ||
+ "`" | ||
) | ||
except MessageNotModifiedError: | ||
pass | ||
os.remove(file.name) | ||
c_size = os.path.getsize(out) | ||
f_time = time.time() | ||
difff = time_formatter((f_time - d_time) * 1000) | ||
await xxx.edit( | ||
f"`Compressed {humanbytes(o_size)} to {humanbytes(c_size)} in {difff}\nTrying to Upload...`" | ||
) | ||
differ = 100 - ((c_size / o_size) * 100) | ||
caption = f"**Original Size: **`{humanbytes(o_size)}`\n" | ||
caption += f"**Compressed Size: **`{humanbytes(c_size)}`\n" | ||
caption += f"**Compression Ratio: **`{differ:.2f}%`\n" | ||
caption += f"\n**Time Taken To Compress: **`{difff}`" | ||
mmmm = await uploader( | ||
out, | ||
out, | ||
f_time, | ||
xxx, | ||
"Uploading " + out + "...", | ||
) | ||
if to_stream: | ||
metadata = extractMetadata(createParser(out)) | ||
duration = metadata.get("duration").seconds | ||
hi, _ = await bash(f'mediainfo "{out}" | grep "Height"') | ||
wi, _ = await bash(f'mediainfo "{out}" | grep "Width"') | ||
height = int(hi.split(":")[1].split("pixels")[0].replace(" ", "")) | ||
width = int(wi.split(":")[1].split("pixels")[0].replace(" ", "")) | ||
attributes = [ | ||
DocumentAttributeVideo( | ||
duration=duration, w=width, h=height, supports_streaming=True | ||
) | ||
await xxx.delete() | ||
os.remove(out) | ||
] | ||
await e.client.send_file( | ||
e.chat_id, | ||
mmmm, | ||
thumb="resources/extras/ultroid.jpg", | ||
caption=caption, | ||
attributes=attributes, | ||
force_document=False, | ||
reply_to=e.reply_to_msg_id, | ||
) | ||
else: | ||
await eod(e, "`Reply To Video File Only`") | ||
await e.client.send_file( | ||
e.chat_id, | ||
mmmm, | ||
thumb="resources/extras/ultroid.jpg", | ||
caption=caption, | ||
force_document=True, | ||
reply_to=e.reply_to_msg_id, | ||
) | ||
await xxx.delete() | ||
os.remove(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 _
refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Replace unneeded comprehension with generator (
comprehension-to-generator
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 1.19%.
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! |
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 1.19%.
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! |
@sourcery-ai[bot] Rip @sppidy's update codes |
@buddhhu Please stop usig that |
Branch
dev
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
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
dev
branch, then run:Help us improve this pull request!