Skip to content

Sourcery refactored demon branch#2

Open
sourcery-ai[bot] wants to merge 1 commit intodemonfrom
sourcery/demon
Open

Sourcery refactored demon branch#2
sourcery-ai[bot] wants to merge 1 commit intodemonfrom
sourcery/demon

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot commented Dec 15, 2021

Branch demon 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 demon branch, then run:

git fetch origin sourcery/demon
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from arshsisodiya December 15, 2021 19:34
Copy link
Copy Markdown
Author

@sourcery-ai sourcery-ai bot left a 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.

@@ -5,6 +5,7 @@
#
""" Userbot initialization. """

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 86-90 refactored with the following changes:

Comment on lines -269 to +266
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)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_readable_time refactored with the following changes:

Comment on lines -326 to -327
else:
pass
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function start refactored with the following changes:

Comment on lines -65 to -67
else:
pass

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register.decorator.wrapper refactored with the following changes:

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.

Comment on lines -15 to -20
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function __list_all_modules refactored with the following changes:

Comment on lines -715 to +694
if event.reply_to_msg_id and not len(args) == 2:
if event.reply_to_msg_id and len(args) != 2:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_user_from_event refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -764 to +743
title = info.title if info.title else "this chat"
title = info.title or "this chat"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_usersdel refactored with the following changes:

Comment on lines -810 to +788
if event.reply_to_msg_id and not len(args) == 2:
if event.reply_to_msg_id and len(args) != 2:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_userdel_from_event refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -861 to +839
title = info.title if info.title else "this chat"
title = info.title or "this chat"
Copy link
Copy Markdown
Author

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:

Comment on lines -53 to +57
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:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function mention_afk refactored with the following changes:

Comment on lines -137 to +139
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function download_api refactored with the following changes:

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"]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getKitsu refactored with the following changes:

Comment on lines -227 to +229
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)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function anime refactored with the following changes:

Comment on lines -293 to +286
genres = ""
for genre in genre_lst:
genres += genre.get("name") + ", "
genres = "".join(genre.get("name") + ", " for genre in genre_lst)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function manga refactored with the following changes:

  • Use str.join() instead of for loop (use-join)

Comment on lines -496 to +489
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)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fban refactored with the following changes:

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]:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function unfban refactored with the following changes:

path = cat
else:
path = os.getcwd()
path = cat or os.getcwd()
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function lst refactored with the following changes:

Comment on lines -32 to +39
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)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function filter_incoming_handler refactored with the following changes:

Comment on lines -142 to +143
transact += "`{}`\n".format(filt.keyword)
else:
transact += "`{}`\n".format(filt.keyword)

transact += "`{}`\n".format(filt.keyword)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function filters_active refactored with the following changes:

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}`')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function startgmute refactored with the following changes:

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}`')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function endgmute refactored with the following changes:

@@ -9,6 +9,7 @@
Google Drive manager for Userbot
"""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 82-92 refactored with the following changes:

Comment on lines -188 to +184
service = build("drive", "v3", credentials=creds, cache_discovery=False)
return service
return build("drive", "v3", credentials=creds, cache_discovery=False)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_app refactored with the following changes:

Comment on lines -190 to +192
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
Copy link
Copy Markdown
Author

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:

create_file = True
if i == 'ContentFile(path="' + file_name + '")':
return await mone.edit("`File Already Exists`")
create_file = False
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function git_commit refactored with the following changes:

Comment on lines -44 to +45
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'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function hack_func refactored with the following changes:

Comment on lines -21 to +22
hashtxt = open("hashdis.txt", "w+")
hashtxt.write(hashtxt_)
hashtxt.close()
with open("hashdis.txt", "w+") as hashtxt:
hashtxt.write(hashtxt_)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function gethash refactored with the following changes:

Comment on lines -46 to +49
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)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function variable refactored with the following changes:

@sourcery-ai
Copy link
Copy Markdown
Author

sourcery-ai bot commented Dec 15, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.87%.

Quality metrics Before After Change
Complexity 20.84 😞 19.58 😞 -1.26 👍
Method Length 105.62 🙂 104.64 🙂 -0.98 👍
Working memory 13.43 😞 13.30 😞 -0.13 👍
Quality 44.91% 😞 45.78% 😞 0.87% 👍
Other metrics Before After Change
Lines 16744 16435 -309
Changed files Quality Before Quality After Quality Change
userbot/init.py 30.55% 😞 30.32% 😞 -0.23% 👎
userbot/events.py 25.54% 😞 29.02% 😞 3.48% 👍
userbot/modules/init.py 89.36% ⭐ 91.93% ⭐ 2.57% 👍
userbot/modules/admin.py 49.33% 😞 50.64% 🙂 1.31% 👍
userbot/modules/afk.py 51.34% 🙂 51.80% 🙂 0.46% 👍
userbot/modules/android.py 32.41% 😞 33.27% 😞 0.86% 👍
userbot/modules/anime.py 40.66% 😞 42.24% 😞 1.58% 👍
userbot/modules/anti_spambot.py 4.99% ⛔ 5.15% ⛔ 0.16% 👍
userbot/modules/archive.py 38.81% 😞 39.01% 😞 0.20% 👍
userbot/modules/blacklist.py 73.61% 🙂 73.84% 🙂 0.23% 👍
userbot/modules/chatinfo.py 15.91% ⛔ 16.09% ⛔ 0.18% 👍
userbot/modules/clone.py 67.77% 🙂 66.93% 🙂 -0.84% 👎
userbot/modules/create.py 35.87% 😞 48.78% 😞 12.91% 👍
userbot/modules/deezload.py 40.18% 😞 37.53% 😞 -2.65% 👎
userbot/modules/dogbin.py 45.66% 😞 48.39% 😞 2.73% 👍
userbot/modules/evaluators.py 45.09% 😞 45.11% 😞 0.02% 👍
userbot/modules/fban.py 48.10% 😞 48.77% 😞 0.67% 👍
userbot/modules/filemanager.py 18.96% ⛔ 19.30% ⛔ 0.34% 👍
userbot/modules/filter.py 61.81% 🙂 61.78% 🙂 -0.03% 👎
userbot/modules/gban.py 36.96% 😞 36.99% 😞 0.03% 👍
userbot/modules/gdrive.py 23.29% ⛔ 23.53% ⛔ 0.24% 👍
userbot/modules/getmusic.py 54.03% 🙂 54.88% 🙂 0.85% 👍
userbot/modules/github.py 55.83% 🙂 55.93% 🙂 0.10% 👍
userbot/modules/hack.py 82.30% ⭐ 82.43% ⭐ 0.13% 👍
userbot/modules/hash.py 59.22% 🙂 60.15% 🙂 0.93% 👍
userbot/modules/heroku.py 47.61% 😞 49.77% 😞 2.16% 👍
userbot/modules/imgmemes.py 66.23% 🙂 66.31% 🙂 0.08% 👍
userbot/modules/invite.py 47.79% 😞 49.91% 😞 2.12% 👍
userbot/modules/lastfm.py 45.39% 😞 45.72% 😞 0.33% 👍
userbot/modules/locks.py 26.60% 😞 26.73% 😞 0.13% 👍
userbot/modules/lyrics.py 55.35% 🙂 55.63% 🙂 0.28% 👍
userbot/modules/mega.py 29.25% 😞 29.58% 😞 0.33% 👍
userbot/modules/memes.py 78.80% ⭐ 79.04% ⭐ 0.24% 👍
userbot/modules/misc.py 85.26% ⭐ 85.63% ⭐ 0.37% 👍
userbot/modules/multimemes.py 49.59% 😞 50.73% 🙂 1.14% 👍
userbot/modules/notes.py 64.63% 🙂 64.92% 🙂 0.29% 👍
userbot/modules/pmpermit.py 46.05% 😞 46.96% 😞 0.91% 👍
userbot/modules/profile.py 68.70% 🙂 67.78% 🙂 -0.92% 👎
userbot/modules/purge.py 70.49% 🙂 70.75% 🙂 0.26% 👍
userbot/modules/qrcode.py 57.30% 🙂 58.39% 🙂 1.09% 👍
userbot/modules/remove_bg.py 55.95% 🙂 54.91% 🙂 -1.04% 👎
userbot/modules/reverse.py 51.90% 🙂 53.41% 🙂 1.51% 👍
userbot/modules/scrapers.py 45.42% 😞 46.70% 😞 1.28% 👍
userbot/modules/sed.py 40.23% 😞 40.36% 😞 0.13% 👍
userbot/modules/spam.py 73.66% 🙂 74.03% 🙂 0.37% 👍
userbot/modules/spotifynow.py 57.39% 🙂 57.49% 🙂 0.10% 👍
userbot/modules/stickers.py 25.99% 😞 26.20% 😞 0.21% 👍
userbot/modules/system_stats.py 57.45% 🙂 58.38% 🙂 0.93% 👍
userbot/modules/updater.py 45.84% 😞 45.71% 😞 -0.13% 👎
userbot/modules/upload_download.py 15.79% ⛔ 17.50% ⛔ 1.71% 👍
userbot/modules/weather.py 38.97% 😞 36.98% 😞 -1.99% 👎
userbot/modules/welcomes.py 39.84% 😞 41.82% 😞 1.98% 👍
userbot/modules/whois.py 49.84% 😞 49.87% 😞 0.03% 👍
userbot/modules/sql_helper/init.py 96.92% ⭐ 97.09% ⭐ 0.17% 👍
userbot/modules/sql_helper/filter_sql.py 81.99% ⭐ 82.68% ⭐ 0.69% 👍
userbot/modules/sql_helper/google_drive_sql.py 90.46% ⭐ 90.68% ⭐ 0.22% 👍
userbot/modules/sql_helper/notes_sql.py 81.75% ⭐ 82.48% ⭐ 0.73% 👍
userbot/modules/sql_helper/snips_sql.py 85.50% ⭐ 86.27% ⭐ 0.77% 👍
userbot/utils/chrome.py 90.91% ⭐ 92.64% ⭐ 1.73% 👍
userbot/utils/duckduckgoscraper.py 57.57% 🙂 57.67% 🙂 0.10% 👍
userbot/utils/google_images_download.py 38.18% 😞 39.60% 😞 1.42% 👍
userbot/utils/tools.py 57.87% 🙂 58.34% 🙂 0.47% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
userbot/modules/chatinfo.py fetch_info 78 ⛔ 877 ⛔ 40 ⛔ 0.80% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
userbot/modules/gdrive.py download_gdrive 74 ⛔ 830 ⛔ 31 ⛔ 1.54% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
userbot/modules/upload_download.py upload 88 ⛔ 607 ⛔ 27 ⛔ 1.91% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
userbot/modules/anti_spambot.py ANTI_SPAMBOTS 87 ⛔ 467 ⛔ 22 ⛔ 4.09% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
userbot/modules/gdrive.py google_drive 90 ⛔ 562 ⛔ 19 ⛔ 5.35% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants