Sourcery refactored main branch#11
Conversation
c86c97d to
de7157a
Compare
| 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}" |
There was a problem hiding this comment.
Function strf_delta refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| async def get_async(self): | ||
| async with httpx.AsyncClient(timeout=None) as client: | ||
| return await client.get(url) | ||
| return await client.get(self) |
There was a problem hiding this comment.
Function BotInfo.get_async refactored with the following changes:
- The first argument to instance methods should be
self(instance-method-first-arg-name)
|
|
||
| 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 | ||
| ]: |
There was a problem hiding this comment.
Function BotInfo.debug_info refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Convert for loop into list comprehension (
list-comprehension)
| 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} ]") |
There was a problem hiding this comment.
Function BotInfo._guild_names refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| 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() |
There was a problem hiding this comment.
Function DiscordVerification.create_thread refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass)
| 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", | ||
| ) |
There was a problem hiding this comment.
Function Tables.get_standings refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass) - Replace f-string with no interpolated values with string (
remove-redundant-fstring)
|
|
There was a problem hiding this comment.
Function Tables.get_all_standings refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass) - Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| 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) |
There was a problem hiding this comment.
Function Tags.tag_modal_rcv refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| 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 | ||
| ) |
There was a problem hiding this comment.
Function make_table refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend)
| 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() | ||
| } |
There was a problem hiding this comment.
Function get_git_changes refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.43%.
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
mainrefactored 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
mainbranch, then run:Help us improve this pull request!