-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
"Open invite to beerparty! React with 🍻 to join!" + reason | ||
) | ||
f"Open invite to beerparty! React with 🍻 to join!{reason}" | ||
) | ||
await msg.add_reaction("\U0001f37b") | ||
await asyncio.sleep(60) | ||
msg = await ctx.channel.fetch_message(msg.id) | ||
users = [user async for user in msg.reactions[0].users()] | ||
users.remove(self.bot.user) | ||
if len(users) == 0: | ||
if not users: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Fun._beerparty
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Simplify sequence length comparison (
simplify-len-comparison
)
help_command = self.bot.get_command("help") | ||
if help_command: | ||
if help_command := self.bot.get_command("help"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function General._source
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
title="Definition of {}".format(word), | ||
title=f"Definition of {word}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function General.define
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
if official_helper_role not in ctx.author.roles: | ||
return False | ||
return True | ||
return official_helper_role in ctx.author.roles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Helper.cog_check
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
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
embed.description = "{} **Action:** {}\n**Reason:** {}\n".format( | ||
icon, action_string.title(), reason | ||
embed.description = ( | ||
f"{icon} **Action:** {action_string.title()}\n**Reason:** {reason}\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Helper.log
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
check_made = self.check_member_permission(ctx, member) | ||
if check_made: | ||
if check_made := self.check_member_permission(ctx, member): | ||
return await self.bot.reply(ctx, check_made) | ||
else: | ||
try: | ||
await member.send( | ||
"You have been :hammer: **Banned** :hammer: from " | ||
f"**{ctx.guild.name}**. \nReason: {reason}" | ||
) | ||
except (discord.Forbidden, discord.HTTPException): | ||
pass | ||
await ctx.guild.ban(member, reason=reason, delete_message_days=7) | ||
await self.bot.reply(ctx, f"Banned {member.mention}") | ||
evidence = await self.capture_evidence(ctx) | ||
await self.log(action="ban", moderator=ctx.author, member=member, | ||
undo=False, reason=reason, duration=None, evidence=evidence) | ||
try: | ||
await member.send( | ||
"You have been :hammer: **Banned** :hammer: from " | ||
f"**{ctx.guild.name}**. \nReason: {reason}" | ||
) | ||
except (discord.Forbidden, discord.HTTPException): | ||
pass | ||
await ctx.guild.ban(member, reason=reason, delete_message_days=7) | ||
await self.bot.reply(ctx, f"Banned {member.mention}") | ||
evidence = await self.capture_evidence(ctx) | ||
await self.log(action="ban", moderator=ctx.author, member=member, | ||
undo=False, reason=reason, duration=None, evidence=evidence) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Moderation.ban
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
check_made = self.check_member_permission(ctx, member) | ||
if check_made: | ||
if check_made := self.check_member_permission(ctx, member): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Moderation.mute
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
check_made = self.check_member_permission(ctx, member) | ||
if check_made: | ||
if check_made := self.check_member_permission(ctx, member): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Moderation.unmute
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
check_made = self.check_member_permission(ctx, user) | ||
if check_made: | ||
if check_made := self.check_member_permission(ctx, user): | ||
counter_dict["not_banned"].append(user) | ||
continue | ||
await ctx.guild.ban(user) # type: ignore | ||
counter_dict["banned"].append(user) | ||
embed = discord.Embed(color=discord.Color.red()) | ||
description = "Following members were banned:\n{}".format( | ||
", ".join(f"{user.mention}" for user in counter_dict["banned"]) | ||
) | ||
description = f'Following members were banned:\n{", ".join(f"{user.mention}" for user in counter_dict["banned"])}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Moderation.massban
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace call to format with f-string (
use-fstring-for-formatting
)
check = self.check_member_permission(ctx, member, priv_level=0) | ||
if check: | ||
if check := self.check_member_permission(ctx, member, priv_level=0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Moderation.warn
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
if moderator: | ||
moderator = moderator.mention | ||
else: | ||
moderator = "Unknown" | ||
moderator = moderator.mention if moderator else "Unknown" | ||
embed.add_field( | ||
name="`{}.` Reason: {}".format(i, warning.reason), | ||
name=f"`{i}.` Reason: {warning.reason}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Moderation.warnings
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Replace call to format with f-string (
use-fstring-for-formatting
)
elif not message and ctx.message.reference: | ||
elif not message: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Moderation.delete
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
if not self.bot.raid_mode_enabled: | ||
if self.bot.raid_checker.possible_raid: | ||
self.bot.raid_mode_enabled = True | ||
await self.bot.reply(ctx, "Raid mode is now enabled.") | ||
for member in self.bot.raid_checker.cache: | ||
if self.bot.raid_checker.check(member): | ||
await member.ban( | ||
reason="Raid mode enabled and met raid criteria." | ||
) | ||
else: | ||
await self.bot.reply( | ||
ctx, "There is no raid that has been detected yet." | ||
) | ||
else: | ||
if self.bot.raid_mode_enabled: | ||
await self.bot.reply(ctx, "Raid mode is already enabled.") | ||
|
||
elif self.bot.raid_checker.possible_raid: | ||
self.bot.raid_mode_enabled = True | ||
await self.bot.reply(ctx, "Raid mode is now enabled.") | ||
for member in self.bot.raid_checker.cache: | ||
if self.bot.raid_checker.check(member): | ||
await member.ban( | ||
reason="Raid mode enabled and met raid criteria." | ||
) | ||
else: | ||
await self.bot.reply( | ||
ctx, "There is no raid that has been detected yet." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Moderation.raid_mode_enable
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
tcr = self.bot.get_guild(681882711945641997) | ||
if tcr: | ||
if tcr := self.bot.get_guild(681882711945641997): | ||
if tcr.get_role(795145820210462771): | ||
statuses.append( | ||
random.choice(tcr.get_role(795145820210462771).members).name | ||
) # type: ignore | ||
if tcr.get_role(737517726737629214): | ||
statuses.append( | ||
random.choice(tcr.get_role(737517726737629214).members).name | ||
+ " (Server Booster)" | ||
) # type: ignore | ||
f"{random.choice(tcr.get_role(737517726737629214).members).name} (Server Booster)" | ||
) | ||
|
||
await self.bot.change_presence( | ||
activity=discord.Activity( | ||
type=discord.ActivityType.watching, | ||
name=random.choice(statuses) | ||
+ " | " | ||
+ self.bot.default_prefixes[0] | ||
+ "help", | ||
name=f"{random.choice(statuses)} | {self.bot.default_prefixes[0]}help", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function TaskCog.status_change
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation
)
chunk = tuple(itertools.islice(it, n)) | ||
if not chunk: | ||
if chunk := tuple(itertools.islice(it, n)): | ||
yield chunk | ||
else: | ||
return | ||
yield chunk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function grouper
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Swap if/else branches (
swap-if-else-branches
)
jishaku = self.get_cog("Jishaku") | ||
if jishaku: | ||
if jishaku := self.get_cog("Jishaku"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function CodingBot.setup_hook
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
rules = member.guild.rules_channel | ||
if rules: | ||
if rules := member.guild.rules_channel: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function CodingBot.on_member_join
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
title="compiling **[** {} **]**".format( | ||
int(time.time()) - self.timestamp | ||
) | ||
title=f"compiling **[** {int(time.time()) - self.timestamp} **]**" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Piston.timer
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
elif output: | ||
if len(output[-1].split("\n")) > 15: | ||
output.append(line + "\n") | ||
else: | ||
output[-1] += line + "\n" | ||
else: | ||
output.append(line + "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Piston.get_code_out
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Simplify sequence length comparison (
simplify-len-comparison
) - Swap positions of nested conditionals [×2] (
swap-nested-ifs
) - Hoist nested repeated code outside conditional statements [×2] (
hoist-similar-statement-from-if
)
if interaction.user == self.author: | ||
return True | ||
return False | ||
return interaction.user == self.author |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Piston.interaction_check
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
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
Branch
master
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
master
branch, then run:Help us improve this pull request!