-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,8 +48,7 @@ async def _source( | |
src = type(self.bot.help_command) | ||
module = src.__module__ | ||
filename = inspect.getsourcefile(src) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
embed.description = help_command.help.format(prefix=ctx.prefix) | ||
else: | ||
obj = self.bot.get_command(command.replace(".", " ")) | ||
|
@@ -97,7 +96,7 @@ async def define(self, ctx: commands.Context[CodingBot], *, word: str): | |
return await ctx.send(f"Could not find definition for `{word}`") | ||
definition = definition[0] | ||
embed = discord.Embed( | ||
title="Definition of {}".format(word), | ||
title=f"Definition of {word}", | ||
Comment on lines
-100
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
description=f"**Meaning**: {definition.meaning}\n", | ||
color=discord.Color.random(), | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,9 +53,7 @@ async def cog_check(self, ctx: commands.Context[CodingBot]) -> bool: | |
|
||
official_helper_role = ctx.guild.get_role(OFFICIAL_HELPER_ROLE_ID) | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
async def capture_evidence( | ||
self, ctx: commands.Context[CodingBot] | ||
|
@@ -175,8 +173,8 @@ async def log( | |
|
||
embed = discord.Embed(color=color, timestamp=discord.utils.utcnow()) | ||
|
||
embed.description = "{} **Action:** {}\n**Reason:** {}\n".format( | ||
icon, action_string.title(), reason | ||
embed.description = ( | ||
f"{icon} **Action:** {action_string.title()}\n**Reason:** {reason}\n" | ||
Comment on lines
-178
to
+177
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
) | ||
if duration: | ||
embed.description += "**Duration:** {}\n".format( | ||
|
@@ -272,12 +270,9 @@ async def help_warnings( | |
|
||
for i, warning in enumerate(records, 1): | ||
helper = ctx.guild.get_member(warning.helper_id) | ||
if helper: | ||
helper = helper.mention | ||
else: | ||
helper = "Unknown" | ||
helper = helper.mention if helper 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 commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
value=f"Issued by: {helper} - <t:{int(warning.date)}:f>", | ||
inline=False, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,7 @@ def valid_gh_sect(name: str): | |
return False | ||
if name.startswith("-") or name.endswith("-"): | ||
return False | ||
if not name.replace("-", "").isalnum(): | ||
return False | ||
return True | ||
return name.replace("-", "").isalnum() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
self.valid_gh_sect = valid_gh_sect | ||
|
||
|
@@ -81,39 +79,39 @@ async def afk_user_messaage(self, message: discord.Message): | |
record = self.bot.afk_cache.get(message.guild.id) | ||
if record: | ||
record = record.get(message.author.id) | ||
if record: | ||
_, time = record | ||
if (datetime.utcnow() - datetime.utcfromtimestamp(time)).seconds < 30: | ||
return | ||
await self.bot.conn.delete_record( | ||
"afk", | ||
table="afk", | ||
where=("user_id",), | ||
values=(message.author.id,), | ||
) | ||
if record: | ||
_, time = record | ||
if (datetime.utcnow() - datetime.utcfromtimestamp(time)).seconds < 30: | ||
return | ||
await self.bot.conn.delete_record( | ||
"afk", | ||
table="afk", | ||
where=("user_id",), | ||
values=(message.author.id,), | ||
) | ||
try: | ||
if "[AFK]" in message.author.display_name: | ||
name = message.author.display_name.split(" ")[1:] | ||
await message.author.edit(nick=" ".join(name)) | ||
except (discord.HTTPException, discord.Forbidden): | ||
pass | ||
|
||
staff_role = message.guild.get_role(795145820210462771) | ||
if staff_role and staff_role in message.author.roles: | ||
on_pat_staff = message.guild.get_role(726441123966484600) | ||
try: | ||
if "[AFK]" in message.author.display_name: | ||
name = message.author.display_name.split(" ")[1:] | ||
await message.author.edit(nick=" ".join(name)) | ||
except (discord.HTTPException, discord.Forbidden): | ||
await message.author.add_roles(on_pat_staff) | ||
except (discord.Forbidden, discord.HTTPException): | ||
pass | ||
|
||
staff_role = message.guild.get_role(795145820210462771) | ||
if staff_role and staff_role in message.author.roles: | ||
on_pat_staff = message.guild.get_role(726441123966484600) | ||
try: | ||
await message.author.add_roles(on_pat_staff) | ||
except (discord.Forbidden, discord.HTTPException): | ||
pass | ||
del self.bot.afk_cache[message.guild.id][message.author.id] | ||
em = discord.Embed( | ||
description=f"{message.author.mention} Welcome back, " | ||
"I removed your AFK!", | ||
color=discord.Color.dark_gold(), | ||
) | ||
msg = await message.reply(embed=em) | ||
await asyncio.sleep(5) | ||
await msg.delete() | ||
del self.bot.afk_cache[message.guild.id][message.author.id] | ||
em = discord.Embed( | ||
description=f"{message.author.mention} Welcome back, " | ||
"I removed your AFK!", | ||
color=discord.Color.dark_gold(), | ||
) | ||
msg = await message.reply(embed=em) | ||
await asyncio.sleep(5) | ||
await msg.delete() | ||
Comment on lines
-84
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@commands.Cog.listener("on_message") | ||
async def user_mentioned(self, message: discord.Message): | ||
|
@@ -134,14 +132,14 @@ async def user_mentioned(self, message: discord.Message): | |
record = self.bot.afk_cache.get(message.guild.id) | ||
if record: | ||
record = record.get(member.id) | ||
if record: | ||
reason, time_ = record | ||
em = discord.Embed( | ||
description=f"{member.mention} is AFK: {reason} " | ||
f"(<t:{time_}:R>)", | ||
color=discord.Color.dark_blue(), | ||
) | ||
await message.reply(embed=em) | ||
if record: | ||
reason, time_ = record | ||
em = discord.Embed( | ||
description=f"{member.mention} is AFK: {reason} " | ||
f"(<t:{time_}:R>)", | ||
color=discord.Color.dark_blue(), | ||
) | ||
await message.reply(embed=em) | ||
Comment on lines
-137
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@commands.Cog.listener() | ||
async def on_message_edit( | ||
|
@@ -191,10 +189,7 @@ async def on_command_error(self, ctx: commands.Context, error: Exception) -> Non | |
) | ||
return await ctx.send(embed=embed, ephemeral=True) | ||
else: | ||
print( | ||
"Ignoring exception in command {}:".format(ctx.command), | ||
file=sys.stderr, | ||
) | ||
print(f"Ignoring exception in command {ctx.command}:", file=sys.stderr) | ||
Comment on lines
-194
to
+192
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
traceback.print_exception( | ||
type(error), error, error.__traceback__, file=sys.stderr | ||
) | ||
|
@@ -209,17 +204,17 @@ async def track_sent_message(self, message: discord.Message): | |
return | ||
|
||
values = [message.author.id, message.guild.id, 1, 1] | ||
columns = ["user_id", "guild_id", "message_count"] | ||
|
||
columns.append(status := message.author.status.name) | ||
columns = [ | ||
"user_id", | ||
"guild_id", | ||
"message_count", | ||
status := message.author.status.name, | ||
] | ||
|
||
staff_role = message.guild.get_role(TCR_STAFF_ROLE_ID) | ||
if staff_role and staff_role in message.author.roles: # type: ignore | ||
columns.append("is_staff") | ||
values.append(1) | ||
else: | ||
pass | ||
|
||
Comment on lines
-212
to
-222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return await self.bot.conn.insert_record( | ||
"metrics", | ||
table="message_metric", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,19 +367,16 @@ async def thank_leaderboard(self, ctx: commands.Context[CodingBot]): | |
ctx, | ||
check=lambda i: i.user.id == ctx.author.id, | ||
) | ||
paginator.add_button( | ||
"delete", label="Delete", style=discord.ButtonStyle.danger | ||
) | ||
await paginator.start() | ||
else: | ||
paginator = pg.Paginator(self.bot, embeds, ctx) | ||
paginator.add_button("back", emoji="◀️") | ||
paginator.add_button("goto", style=discord.ButtonStyle.primary) | ||
paginator.add_button("next", emoji="▶️") | ||
paginator.add_button( | ||
"delete", label="Delete", style=discord.ButtonStyle.danger | ||
) | ||
await paginator.start() | ||
|
||
paginator.add_button( | ||
"delete", label="Delete", style=discord.ButtonStyle.danger | ||
) | ||
await paginator.start() | ||
Comment on lines
-370
to
+379
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@commands.hybrid_group(invoke_without_command=True) | ||
async def trainee(self, ctx: commands.Context[CodingBot]): | ||
|
@@ -400,14 +397,12 @@ async def trainee_list(self, ctx: commands.Context[CodingBot]): | |
""" | ||
|
||
trainee_role = ctx.guild.get_role(729537643951554583) # type: ignore | ||
members = trainee_role.members | ||
|
||
if not members: | ||
trainees = "No trainees yet." | ||
else: | ||
if members := trainee_role.members: | ||
trainees = "\n".join( | ||
f"{i}. {member.mention}" for i, member in enumerate(members, 1) | ||
) | ||
else: | ||
trainees = "No trainees yet." | ||
Comment on lines
-403
to
+405
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
embed = discord.Embed( | ||
title="Trainees list", description=trainees, color=discord.Color.blue() | ||
) | ||
|
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-fstring-for-concatenation
)simplify-len-comparison
)