Skip to content

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Apr 1, 2022

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

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from Squidtoon99 April 1, 2022 03:20
if bool(os.getenv("PRODUCTION")):
db = client.Main
else:
db = client.Test
return db
return client.Main if bool(os.getenv("PRODUCTION")) else client.Test
Copy link
Author

Choose a reason for hiding this comment

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

Function setup_db refactored with the following changes:

Comment on lines -62 to +63
if url := os.getenv("REDIS_URL"):
k = {}
if password := os.getenv("REDIS_PASS"):
k["password"] = password
redis: Redis = Redis.from_url(url, **k)
else:
redis: Redis = Redis()
return redis
if not (url := os.getenv("REDIS_URL")):
return Redis()
k = {}
if password := os.getenv("REDIS_PASS"):
k["password"] = password
return Redis.from_url(url, **k)
Copy link
Author

Choose a reason for hiding this comment

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

Function setup_redis refactored with the following changes:

Comment on lines -110 to +104
settings = Settings.from_data(req.json())

return settings
return Settings.from_data(req.json())
Copy link
Author

Choose a reason for hiding this comment

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

Function setup_settings refactored with the following changes:

Comment on lines -20 to +22
raise CommandFailed("Item `{}` not found!".format(item))
raise CommandFailed(f"Item `{item}` not found!")

item_name = redis.get("dank:item:{}:name".format(actual_item[0]))
item_name = redis.get(f"dank:item:{actual_item[0]}:name")
Copy link
Author

Choose a reason for hiding this comment

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

Function DankMemer.dankitem refactored with the following changes:

plugins/fun.py Outdated
return "\N{KEYCAP TEN}" if c == 10 else str(c) + "\u20e3"
return "\N{KEYCAP TEN}" if c == 10 else f'{c}⃣'
Copy link
Author

Choose a reason for hiding this comment

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

Function to_keycap refactored with the following changes:

Comment on lines 36 to 38
url, headers={"Authorization": self.bot.amari_auth}
) as req:
if req.status_code == 200:
data = req.json()["data"]
else:
data = []

url, headers={"Authorization": self.bot.amari_auth}
) as req:
data = req.json()["data"] if req.status_code == 200 else []
Copy link
Author

Choose a reason for hiding this comment

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

Function Amari.fetch_guild_data refactored with the following changes:

return "Mee6 Level: " + str(data[0])
return f"Mee6 Level: {str(data[0])}"
Copy link
Author

Choose a reason for hiding this comment

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

Function Mee6.display refactored with the following changes:

return (
"Required Role" + s(data) + ": " + format_list([f"<@&{i}>" for i in data])
)
return (f"Required Role{s(data)}: " + format_list([f"<@&{i}>" for i in data]))
Copy link
Author

Choose a reason for hiding this comment

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

Function Role.display refactored with the following changes:

Comment on lines -25 to +23
raise ArgumentParsingError("Invalid role ID ({})".format(role_str))
raise ArgumentParsingError(f"Invalid role ID ({role_str})")
Copy link
Author

Choose a reason for hiding this comment

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

Function Role.convert refactored with the following changes:

Comment on lines 16 to 19
"Response must be an InteractionResponse object but recieved {}: ({})".format(
type(response), response.__repr__()
)
f"Response must be an InteractionResponse object but recieved {type(response)}: ({response.__repr__()})"
)


Copy link
Author

Choose a reason for hiding this comment

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

Function flask_compat.wrapper refactored with the following changes:

Comment on lines -64 to +67
r = {}
for v, k in self.settings.get(ctx.command.cog.db_name, {}).items():
r[v] = data.get(ctx.command.cog.db_name, {}).get(v, k.default)
return r
return {
v: data.get(ctx.command.cog.db_name, {}).get(v, k.default)
for v, k in self.settings.get(ctx.command.cog.db_name, {}).items()
}
Copy link
Author

Choose a reason for hiding this comment

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

Function Settings.guild_settings refactored with the following changes:

Comment on lines -12 to +17
if len(l) == 0:
if not l:
return ""
elif len(l) == 1:
return str(l[0])
elif len(l) == 2:
return "{} and {}".format(l[0], l[1])
return f"{l[0]} and {l[1]}"
Copy link
Author

Choose a reason for hiding this comment

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

Function format_list refactored with the following changes:

value = seconds // count
if value:
if value := seconds // count:
Copy link
Author

Choose a reason for hiding this comment

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

Function display_time refactored with the following changes:

), "Could not parse any time information from '{}'. Examples of valid strings: '8h', '2d8h5m20s', '2m4s'".format(
time_str
)
), f"Could not parse any time information from '{time_str}'. Examples of valid strings: '8h', '2d8h5m20s', '2m4s'"

Copy link
Author

Choose a reason for hiding this comment

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

Function parse_time refactored with the following changes:

description="Unknown interaction: {}".format(ctx.interaction.data.name),
description=f"Unknown interaction: {ctx.interaction.data.name}",
Copy link
Author

Choose a reason for hiding this comment

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

Function SquidBot.unknown_command refactored with the following changes:

parent = self.full_parent_name
if parent:
return parent + " " + self.name
if parent := self.full_parent_name:
return f'{parent} {self.name}'
Copy link
Author

Choose a reason for hiding this comment

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

Function SquidCommand.qualified_name refactored with the following changes:

if self._user["member"]:
return self._user["member"]
return self._user["user"]
return self._user["member"] or self._user["user"]
Copy link
Author

Choose a reason for hiding this comment

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

Function SquidContext.author refactored with the following changes:

Comment on lines -79 to -86
if remaining == "0" and response.status_code != 429:
pass
# we've depleted our current bucket
# delta = utils._parse_ratelimit_header(response, use_clock=self.use_clock)
# # _log.debug('A rate limit bucket has been exhausted (bucket: %s, retry: %s).', bucket, delta)
# maybe_lock.defer()
# self.loop.call_later(delta, lock.release)

Copy link
Author

Choose a reason for hiding this comment

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

Function HttpClient.request refactored with the following changes:

This removes the following comments ( why? ):

# maybe_lock.defer()
# we've depleted our current bucket
# This is handling exceptions from the request
# delta = utils._parse_ratelimit_header(response, use_clock=self.use_clock)
# self.loop.call_later(delta, lock.release)
# # _log.debug('A rate limit bucket has been exhausted (bucket: %s, retry: %s).', bucket, delta)

if isinstance(o, InteractionResponseType):
return None
return o.__dict__
return None if isinstance(o, InteractionResponseType) else o.__dict__
Copy link
Author

Choose a reason for hiding this comment

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

Function InteractionResponse.default refactored with the following changes:

Comment on lines 115 to 117
return (self.name if len(self.name) <= 32 else self.name[:32] + "...").replace(
"@", "@\u200b"
)
return (
self.name if len(self.name) <= 32 else f'{self.name[:32]}...'
).replace("@", "@\u200b")
Copy link
Author

Choose a reason for hiding this comment

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

Function Member.safe_name refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Apr 1, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.04%.

Quality metrics Before After Change
Complexity 5.91 ⭐ 5.67 ⭐ -0.24 👍
Method Length 40.34 ⭐ 40.19 ⭐ -0.15 👍
Working memory 8.16 🙂 8.22 🙂 0.06 👎
Quality 73.41% 🙂 73.37% 🙂 -0.04% 👎
Other metrics Before After Change
Lines 2820 2777 -43
Changed files Quality Before Quality After Quality Change
main.py 77.61% ⭐ 77.70% ⭐ 0.09% 👍
plugins/dankmemer.py 59.20% 🙂 59.13% 🙂 -0.07% 👎
plugins/fun.py 77.79% ⭐ 76.63% ⭐ -1.16% 👎
plugins/timers.py 60.22% 🙂 60.31% 🙂 0.09% 👍
plugins/utility.py 75.13% ⭐ 75.15% ⭐ 0.02% 👍
plugins/giveaways/plugin.py 56.62% 🙂 55.18% 🙂 -1.44% 👎
plugins/giveaways/requirement.py 88.30% ⭐ 88.38% ⭐ 0.08% 👍
plugins/giveaways/requirements/amari.py 83.69% ⭐ 84.71% ⭐ 1.02% 👍
plugins/giveaways/requirements/mee6.py 77.55% ⭐ 77.54% ⭐ -0.01% 👎
plugins/giveaways/requirements/roles.py 86.02% ⭐ 85.98% ⭐ -0.04% 👎
squid/flask_support.py 90.16% ⭐ 82.02% ⭐ -8.14% 👎
squid/settings.py 80.96% ⭐ 81.18% ⭐ 0.22% 👍
squid/utils.py 57.67% 🙂 57.00% 🙂 -0.67% 👎
squid/bot/bot.py 76.96% ⭐ 78.27% ⭐ 1.31% 👍
squid/bot/command.py 77.73% ⭐ 77.81% ⭐ 0.08% 👍
squid/bot/context.py 75.95% ⭐ 75.57% ⭐ -0.38% 👎
squid/http/client.py 43.43% 😞 45.04% 😞 1.61% 👍
squid/models/interaction.py 80.85% ⭐ 80.49% ⭐ -0.36% 👎
squid/models/member.py 74.12% 🙂 74.12% 🙂 0.00%

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

File Function Complexity Length Working Memory Quality Recommendation
squid/utils.py evaluate_annotation 35 ⛔ 206 ⛔ 14 😞 25.29% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
squid/http/client.py HttpClient.request 34 ⛔ 261 ⛔ 10 😞 29.08% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
plugins/giveaways/plugin.py Giveaways.gstart 3 ⭐ 271 ⛔ 24 ⛔ 37.15% 😞 Try splitting into smaller methods. Extract out complex expressions
plugins/dankmemer.py DankMemer.trades 5 ⭐ 248 ⛔ 21 ⛔ 37.56% 😞 Try splitting into smaller methods. Extract out complex expressions
plugins/timers.py Timers.timers 8 ⭐ 206 ⛔ 16 ⛔ 41.12% 😞 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