Skip to content

Sourcery refactored main branch#11

Open
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main
Open

Sourcery refactored main branch#11
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Dec 16, 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!

Comment thread extensions/botutil.py
if show_seconds:
return f"{minutes_fmt} and {seconds_fmt}"
return f"{minutes_fmt}"
return f"{minutes_fmt} and {seconds_fmt}" if show_seconds else f"{minutes_fmt}"
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 strf_delta refactored with the following changes:

Comment thread extensions/botutil.py
async def get_async(self):
async with httpx.AsyncClient(timeout=None) as client:
return await client.get(url)
return await client.get(self)
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 BotInfo.get_async refactored with the following changes:

Comment thread extensions/botutil.py
Comment on lines -145 to +149

e.add_field("Loaded Extensions", ", ".join(self.bot.ext))
guild_names = []
for guild in self.bot.guilds:
guild_names.append(guild.name)
guild_names = [guild.name for guild in self.bot.guilds]
e.add_field(f"Connected to **{len(self.bot.guilds)}** Guilds", guild_names)
privileged_intents = [i.name for i in self.bot.intents if i in Intents.PRIVILEGED]
if privileged_intents:
if privileged_intents := [
i.name for i in self.bot.intents if i in Intents.PRIVILEGED
]:
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 BotInfo.debug_info refactored with the following changes:

Comment thread extensions/botutil.py
Comment on lines -211 to -214
guild_list = []
guild_list = [f"[ {guild.name} ]" for guild in self.bot.guilds]

for guild in self.bot.guilds:
guild_list.append(f"[ {guild.name} ]")
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 BotInfo._guild_names refactored with the following changes:

Comment on lines -92 to +134
await ctx.author.add_role(await RoleConverter().convert(ctx, "Waiting Verification"), "Waiting for verification.")
await ctx.author.remove_role(await RoleConverter().convert(ctx, "New Member"), "Verification started")

thread = await channel.create_private_thread(
name=f"{ctx.author.display_name}'s Verification",
auto_archive_duration=AutoArchiveDuration.ONE_WEEK,
reason="Verification Thread",
invitable=False,
)
await thread.add_member(ctx.author.id)

if not previous_tag:
previous_tag = "--"

await thread.send(
f"Welcome to your verification thread, {ctx.author.mention}."
"\nThis thread was created automatically by the bot due to your Gamer Tag not being found.\n\n"
"**Provided Information:**\n\n"
f"Gamertag: **{current_tag}**\n"
f"Previous Gamertags: **{previous_tag}**\n"
"Verified Onsite: **False**"
"\n\n**Please make sure you have Direct Messages enabled for this server."
"\nYou will be notified via DM when access is granted.**"
"\nTo enble DMs for this server only on mobile, click server name > Allow Direct Messages."
"\nTo enable DMs for this server only on desktop, click server name > Privacy Settings > Allow Direct Messages."
"\n\n**Discord verifications are automatically checked every 48 hours.**"
)
await ctx.author.add_role(await RoleConverter().convert(ctx, "Waiting Verification"), "Waiting for verification.")
await ctx.author.remove_role(await RoleConverter().convert(ctx, "New Member"), "Verification started")

thread = await channel.create_private_thread(
name=f"{ctx.author.display_name}'s Verification",
auto_archive_duration=AutoArchiveDuration.ONE_WEEK,
reason="Verification Thread",
invitable=False,
)
await thread.add_member(ctx.author.id)

if not previous_tag:
previous_tag = "--"

await thread.send(
f"Welcome to your verification thread, {ctx.author.mention}."
"\nThis thread was created automatically by the bot due to your Gamer Tag not being found.\n\n"
"**Provided Information:**\n\n"
f"Gamertag: **{current_tag}**\n"
f"Previous Gamertags: **{previous_tag}**\n"
"Verified Onsite: **False**"
"\n\n**Please make sure you have Direct Messages enabled for this server."
"\nYou will be notified via DM when access is granted.**"
"\nTo enble DMs for this server only on mobile, click server name > Allow Direct Messages."
"\nTo enable DMs for this server only on desktop, click server name > Privacy Settings > Allow Direct Messages."
"\n\n**Discord verifications are automatically checked every 48 hours.**"
)

await ctx.send(f"{ctx.author.mention} Your verification thread has been created here: {thread.mention}", ephemeral=True)

existing_verification = await VerificationQueue.find_one({"discord_id": ctx.author.id})
if existing_verification is None:
waiting_verification = VerificationQueue(
discord_id=ctx.author.id,
discord_name=ctx.author.display_name,
gamertag=current_tag,
status="New",
reason="Waiting for website verification",
updated=datetime.now(),
discord_thread=thread.id,
)
await waiting_verification.save()

await ctx.send(f"{ctx.author.mention} Your verification thread has been created here: {thread.mention}", ephemeral=True)

existing_verification = await VerificationQueue.find_one({"discord_id": ctx.author.id})
if existing_verification is None:
waiting_verification = VerificationQueue(
discord_id=ctx.author.id,
discord_name=ctx.author.display_name,
gamertag=current_tag,
status="New",
reason="Waiting for website verification",
updated=datetime.now(),
discord_thread=thread.id,
)
await waiting_verification.save()
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 DiscordVerification.create_thread refactored with the following changes:

Comment thread extensions/tables.py
Comment on lines -124 to +132
else:
pass
console = Console()
with console.capture() as cap:
console.print(table)
# table_out = cap.get()
e.description = f"```ansi\n{cap.get()}\n```"
e.set_footer(text=f"proclubsnation.com", icon_url="https://proclubsnation.com/wp-content/uploads/2021/10/PCN_logo_new.png")
e.set_footer(
text="proclubsnation.com",
icon_url="https://proclubsnation.com/wp-content/uploads/2021/10/PCN_logo_new.png",
)
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 Tables.get_standings refactored with the following changes:

Comment thread extensions/tables.py
Comment on lines -146 to +147

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 Tables.get_all_standings refactored with the following changes:

Comment thread extensions/tags.py
Comment on lines -238 to +257
return await ctx.send(f"A tag with the name `{name}` already exists")
else:
if edit_mode:
tag = tag_lookup
tag.name = name.lower()
tag.modifier_id = ctx.author.id
tag.modified = datetime.now()
tag.content = content
if not tag:
tag = TagStorage(
name=name.lower(),
content=content,
author_id=ctx.author.id,
creation=datetime.now(),
guild=ctx.guild.id,
)
await tag.save()
if edit_mode:
self.tags.pop(name.lower().replace("_", " "))
self.tags[name] = tag
else:
self.tags[name] = tag
await ctx.send(f"{'Edited' if edit_mode else 'Created'} `{name}`", ephemeral=True)
return await ctx.send(f"A tag with the name `{name}` already exists")
if edit_mode:
tag = tag_lookup
tag.name = name.lower()
tag.modifier_id = ctx.author.id
tag.modified = datetime.now()
tag.content = content
if not tag:
tag = TagStorage(
name=name.lower(),
content=content,
author_id=ctx.author.id,
creation=datetime.now(),
guild=ctx.guild.id,
)
await tag.save()
if edit_mode:
self.tags.pop(name.lower().replace("_", " "))
self.tags[name] = tag
await ctx.send(f"{'Edited' if edit_mode else 'Created'} `{name}`", ephemeral=True)
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 Tags.tag_modal_rcv refactored with the following changes:

Comment thread helpers/tablemaker.py
Comment on lines -31 to +36
for row in rows:
lines.append(_make_data_line(column_widths, row, data_left, data_middle, data_right, align))
lines.extend(
_make_data_line(
column_widths, row, data_left, data_middle, data_right, align
)
for row in rows
)
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 make_table refactored with the following changes:

Comment thread helpers/updates.py
Comment on lines -78 to +81
file_changes.update(
{key: {"insertions": 0, "deletions": 0, "lines": 0} for key in files.keys()}
)
file_changes |= {
key: {"insertions": 0, "deletions": 0, "lines": 0}
for key in files.keys()
}
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_git_changes refactored with the following changes:

@sourcery-ai
Copy link
Copy Markdown
Author

sourcery-ai Bot commented Dec 16, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 16.44 🙂 16.00 🙂 -0.44 👍
Method Length 128.01 😞 127.33 😞 -0.68 👍
Working memory 11.51 😞 11.43 😞 -0.08 👍
Quality 47.48% 😞 47.91% 😞 0.43% 👍
Other metrics Before After Change
Lines 1514 1508 -6
Changed files Quality Before Quality After Quality Change
extensions/botutil.py 54.12% 🙂 54.20% 🙂 0.08% 👍
extensions/discord_verifier.py 30.88% 😞 31.24% 😞 0.36% 👍
extensions/find.py 36.29% 😞 38.96% 😞 2.67% 👍
extensions/player.py 49.86% 😞 49.95% 😞 0.09% 👍
extensions/tables.py 56.11% 🙂 56.19% 🙂 0.08% 👍
extensions/tags.py 56.94% 🙂 57.99% 🙂 1.05% 👍
helpers/tablemaker.py 72.15% 🙂 72.72% 🙂 0.57% 👍
helpers/updates.py 28.28% 😞 28.31% 😞 0.03% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
extensions/discord_verifier.py DiscordVerification.create_thread 53 ⛔ 662 ⛔ 22 ⛔ 5.80% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
helpers/updates.py update 63 ⛔ 402 ⛔ 19 ⛔ 7.57% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
extensions/tags.py Tags.tag 49 ⛔ 345 ⛔ 15 😞 14.13% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
extensions/find.py PlayerFinder.find 30 😞 340 ⛔ 16 ⛔ 19.23% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
extensions/botutil.py BotInfo.debug_info 11 🙂 589 ⛔ 15 😞 31.44% 😞 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