Conversation
| @@ -5,6 +5,7 @@ | |||
| # | |||
| """ Userbot initialization. """ | |||
|
|
|||
There was a problem hiding this comment.
Lines 86-90 refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if count < 3: | ||
| remainder, result = divmod(seconds, 60) | ||
| else: | ||
| remainder, result = divmod(seconds, 24) | ||
| remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24) |
There was a problem hiding this comment.
Function get_readable_time refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| else: | ||
| pass |
There was a problem hiding this comment.
Function start refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass)
| else: | ||
| pass | ||
|
|
There was a problem hiding this comment.
Function register.decorator.wrapper refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass) - Hoist repeated code outside conditional statement (
hoist-statement-from-if) - Use
withwhen opening file to ensure closure (ensure-file-closed) - Replace f-string with no interpolated values with string (
remove-redundant-fstring)
This removes the following comments ( why? ):
# spam chats
# This is a gay exception and must be passed out. So that it doesnt
# Raise StopPropagation to Raise StopPropagation
# This needed for AFK to working properly
# Thanks to @kandnub for this HACK.
| all_modules = [ | ||
| return [ | ||
| basename(f)[:-3] | ||
| for f in mod_paths | ||
| if isfile(f) and f.endswith(".py") and not f.endswith("__init__.py") | ||
| ] | ||
| return all_modules |
There was a problem hiding this comment.
Function __list_all_modules refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if event.reply_to_msg_id and not len(args) == 2: | ||
| if event.reply_to_msg_id and len(args) != 2: |
There was a problem hiding this comment.
Function get_user_from_event refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| title = info.title if info.title else "this chat" | ||
| title = info.title or "this chat" |
There was a problem hiding this comment.
Function get_usersdel refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity) - Use
withwhen opening file to ensure closure (ensure-file-closed)
| if event.reply_to_msg_id and not len(args) == 2: | ||
| if event.reply_to_msg_id and len(args) != 2: |
There was a problem hiding this comment.
Function get_userdel_from_event refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| title = info.title if info.title else "this chat" | ||
| title = info.title or "this chat" |
There was a problem hiding this comment.
Function _ refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity)
| is_bot = False | ||
| if (sender := await mention.get_sender()): | ||
| is_bot = sender.bot | ||
| if not is_bot and mention.sender_id not in USERS: | ||
| if AFKREASON: | ||
| await mention.reply("I'm AFK right now." f"\nBecause `{AFKREASON}`") | ||
| else: | ||
| await mention.reply(str(choice(AFKSTR))) | ||
| USERS.update({mention.sender_id: 1}) | ||
| else: | ||
| if not is_bot and sender: | ||
| is_bot = sender.bot if ((sender := await mention.get_sender())) else False | ||
| if is_bot: | ||
| pass | ||
| elif mention.sender_id in USERS: | ||
| if sender: |
There was a problem hiding this comment.
Function mention_afk refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Swap if/else branches (
swap-if-else-branches) - Split conditional into multiple branches (
split-or-ifs) - Remove redundant conditional (
remove-redundant-if)
| if len(error) > 0: | ||
| if error[0].text == "File Not Found.": | ||
| await dl.edit(f"`FileNotFoundError`: {URL} is not found.") | ||
| return | ||
| if len(error) > 0 and error[0].text == "File Not Found.": | ||
| await dl.edit(f"`FileNotFoundError`: {URL} is not found.") | ||
| return |
There was a problem hiding this comment.
Function download_api refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs) - Replace if statement with if expression (
assign-if-exp) - Simplify comparison to boolean (
simplify-boolean-comparison)
| link = f"https://kitsu.io/api/edge/mappings/{result}/item?fields[anime]=slug" | ||
| kitsu = requests.get(link).json()["data"]["id"] | ||
| return kitsu | ||
| return requests.get(link).json()["data"]["id"] |
There was a problem hiding this comment.
Function getKitsu refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| genres = "" | ||
| for genre in genre_lst: | ||
| genres += genre.get("name") + ", " | ||
| genres = "".join(genre.get("name") + ", " for genre in genre_lst) | ||
| genres = genres[:-2] | ||
| studios = "" | ||
| studio_lst = anime.get("studios") | ||
| for studio in studio_lst: | ||
| studios += studio.get("name") + ", " | ||
| studios = "".join(studio.get("name") + ", " for studio in studio_lst) |
There was a problem hiding this comment.
Function anime refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass) - Use str.join() instead of for loop (
use-join)
| genres = "" | ||
| for genre in genre_lst: | ||
| genres += genre.get("name") + ", " | ||
| genres = "".join(genre.get("name") + ", " for genre in genre_lst) |
There was a problem hiding this comment.
Function manga refactored with the following changes:
- Use str.join() instead of for loop (
use-join)
| genress_md = "" | ||
| producer_md = "" | ||
| studio_md = "" | ||
| for i in genres_list: | ||
| genress_md += f"{i['name']} " | ||
| for i in producer_list: | ||
| producer_md += f"[{i['name']}]({i['url']}) " | ||
| for i in studios_list: | ||
| studio_md += f"[{i['name']}]({i['url']}) " | ||
|
|
||
| genress_md = "".join(f"{i['name']} " for i in genres_list) | ||
| producer_md = "".join(f"[{i['name']}]({i['url']}) " for i in producer_list) | ||
| studio_md = "".join(f"[{i['name']}]({i['url']}) " for i in studios_list) |
There was a problem hiding this comment.
Function get_anime refactored with the following changes:
- Use str.join() instead of for loop (
use-join)
| return await term.edit("`That's a dangerous operation! Not Permitted!`") | ||
|
|
||
| if not re.search(r"echo[ \-\w]*\$\w+", command) is None: | ||
| if re.search(r"echo[ \-\w]*\$\w+", command) is not None: |
There was a problem hiding this comment.
Function terminal_runner refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| self_user = await event.client.get_me() | ||
|
|
||
| if fban_id == self_user.id or fban_id == "@" + self_user.username: | ||
| if fban_id in [self_user.id, "@" + self_user.username]: |
There was a problem hiding this comment.
Function fban refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| self_user = await event.client.get_me() | ||
|
|
||
| if unfban_id == self_user.id or unfban_id == "@" + self_user.username: | ||
| if unfban_id in [self_user.id, "@" + self_user.username]: |
There was a problem hiding this comment.
Function unfban refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| path = cat | ||
| else: | ||
| path = os.getcwd() | ||
| path = cat or os.getcwd() |
There was a problem hiding this comment.
Function lst refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if) - Split conditional into multiple branches (
split-or-ifs) - Merge duplicate blocks in conditional (
merge-duplicate-blocks) - Remove redundant conditional (
remove-redundant-if) - Replace if statement with if expression (
assign-if-exp) - Simplify if expression by using or (
or-if-exp-identity)
| if pro and trigger.f_mesg_id: | ||
| msg_o = await handler.client.get_messages( | ||
| entity=BOTLOG_CHATID, ids=int(trigger.f_mesg_id) | ||
| ) | ||
| await handler.reply(msg_o.message, file=msg_o.media) | ||
| elif pro and trigger.reply: | ||
| await handler.reply(trigger.reply) | ||
| if pro: | ||
| if trigger.f_mesg_id: | ||
| msg_o = await handler.client.get_messages( | ||
| entity=BOTLOG_CHATID, ids=int(trigger.f_mesg_id) | ||
| ) | ||
| await handler.reply(msg_o.message, file=msg_o.media) | ||
| elif trigger.reply: | ||
| await handler.reply(trigger.reply) |
There was a problem hiding this comment.
Function filter_incoming_handler refactored with the following changes:
- Lift repeated conditional into its own if statement (
lift-duplicated-conditional)
| transact += "`{}`\n".format(filt.keyword) | ||
| else: | ||
| transact += "`{}`\n".format(filt.keyword) | ||
|
|
||
| transact += "`{}`\n".format(filt.keyword) |
There was a problem hiding this comment.
Function filters_active refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| mute(userid, "gmute") | ||
| except Exception as e: | ||
| await edit_or_reply(event, f"**Error**\n`{str(e)}`") | ||
| await edit_or_reply(event, f'**Error**\n`{e}`') |
There was a problem hiding this comment.
Function startgmute refactored with the following changes:
- Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting)
| unmute(userid, "gmute") | ||
| except Exception as e: | ||
| await edit_or_reply(event, f"**Error**\n`{str(e)}`") | ||
| await edit_or_reply(event, f'**Error**\n`{e}`') |
There was a problem hiding this comment.
Function endgmute refactored with the following changes:
- Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting)
| @@ -9,6 +9,7 @@ | |||
| Google Drive manager for Userbot | |||
| """ | |||
|
|
|||
There was a problem hiding this comment.
Lines 82-92 refactored with the following changes:
- Swap if/else to remove empty if body (
remove-pass-body) - Replace if statement with if expression (
assign-if-exp) - Simplify boolean if expression (
boolean-if-exp-identity)
| service = build("drive", "v3", credentials=creds, cache_discovery=False) | ||
| return service | ||
| return build("drive", "v3", credentials=creds, cache_discovery=False) |
There was a problem hiding this comment.
Function create_app refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| duration = 0 | ||
| width = 0 | ||
| height = 0 | ||
| if metadata.has("duration"): | ||
| duration = metadata.get("duration").seconds | ||
| if metadata.has("width"): | ||
| width = metadata.get("width") | ||
| if metadata.has("height"): | ||
| height = metadata.get("height") | ||
| duration = metadata.get("duration").seconds if metadata.has("duration") else 0 | ||
| width = metadata.get("width") if metadata.has("width") else 0 | ||
| height = metadata.get("height") if metadata.has("height") else 0 |
There was a problem hiding this comment.
Function _ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| create_file = True | ||
| if i == 'ContentFile(path="' + file_name + '")': | ||
| return await mone.edit("`File Already Exists`") | ||
| create_file = False |
There was a problem hiding this comment.
Function git_commit refactored with the following changes:
- Remove unreachable code (
remove-unreachable-code)
| hecked = (f"**Targeted Account Hacked**\n\nPay 69$ To hackerman\nTo Remove This Hack") | ||
| hecked = '**Targeted Account Hacked**\n\nPay 69$ To hackerman\nTo Remove This Hack' | ||
|
|
There was a problem hiding this comment.
Function hack_func refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| hashtxt = open("hashdis.txt", "w+") | ||
| hashtxt.write(hashtxt_) | ||
| hashtxt.close() | ||
| with open("hashdis.txt", "w+") as hashtxt: | ||
| hashtxt.write(hashtxt_) |
There was a problem hiding this comment.
Function gethash refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
| if variable != "": | ||
| if variable in heroku_var: | ||
| if BOTLOG: | ||
| await var.client.send_message( | ||
| BOTLOG_CHATID, | ||
| "#CONFIGVAR\n\n" | ||
| "**ConfigVar**:\n" | ||
| f"`{variable}` = `{heroku_var[variable]}`\n", | ||
| ) | ||
| await var.edit("`Received to BOTLOG_CHATID...`") | ||
| return True | ||
| else: | ||
| await var.edit("`Please set BOTLOG to True...`") | ||
| return False | ||
| else: | ||
| await var.edit("`Information don't exists...`") | ||
| return True | ||
| else: | ||
| if variable == "": | ||
| configvars = heroku_var.to_dict() | ||
| msg = "" | ||
| if BOTLOG: | ||
| for item in configvars: | ||
| msg += f"`{item}` = `{configvars[item]}`\n" | ||
| msg = "".join(f"`{item}` = `{configvars[item]}`\n" for item in configvars) |
There was a problem hiding this comment.
Function variable refactored with the following changes:
- Move assignments closer to their usage (
move-assign) - Use str.join() instead of for loop (
use-join) - Swap if/else branches (
swap-if-else-branches) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.87%.
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! |
Branch
demonrefactored 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
demonbranch, then run:Help us improve this pull request!