Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cogs/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@ async def _beerparty(
):
reason = ("\nReason: " + reason) if reason else ""
msg = await ctx.send(
"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:
Comment on lines -259 to +266
Copy link
Author

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:

return await ctx.send("Nobody joined the beerparty :(")
await ctx.send(
", ".join(user.display_name for user in users) + " joined the beerparty!"
Expand Down
5 changes: 2 additions & 3 deletions cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Copy link
Author

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:

embed.description = help_command.help.format(prefix=ctx.prefix)
else:
obj = self.bot.get_command(command.replace(".", " "))
Expand Down Expand Up @@ -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
Copy link
Author

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:

description=f"**Meaning**: {definition.meaning}\n",
color=discord.Color.random(),
)
Expand Down
15 changes: 5 additions & 10 deletions cogs/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

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:


async def capture_evidence(
self, ctx: commands.Context[CodingBot]
Expand Down Expand Up @@ -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
Copy link
Author

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:

)
if duration:
embed.description += "**Duration:** {}\n".format(
Expand Down Expand Up @@ -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}",
Copy link
Author

Choose a reason for hiding this comment

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

Function Helper.help_warnings refactored with the following changes:

value=f"Issued by: {helper} - <t:{int(warning.date)}:f>",
inline=False,
)
Expand Down
99 changes: 47 additions & 52 deletions cogs/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Author

Choose a reason for hiding this comment

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

Function ListenerCog.__init__ refactored with the following changes:


self.valid_gh_sect = valid_gh_sect

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function ListenerCog.afk_user_messaage refactored with the following changes:


@commands.Cog.listener("on_message")
async def user_mentioned(self, message: discord.Message):
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function ListenerCog.user_mentioned refactored with the following changes:


@commands.Cog.listener()
async def on_message_edit(
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function ListenerCog.on_command_error refactored with the following changes:

traceback.print_exception(
type(error), error, error.__traceback__, file=sys.stderr
)
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function ListenerCog.track_sent_message refactored with the following changes:

return await self.bot.conn.insert_record(
"metrics",
table="message_metric",
Expand Down
21 changes: 8 additions & 13 deletions cogs/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function Miscellaneous.thank_leaderboard refactored with the following changes:


@commands.hybrid_group(invoke_without_command=True)
async def trainee(self, ctx: commands.Context[CodingBot]):
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function Miscellaneous.trainee_list refactored with the following changes:

embed = discord.Embed(
title="Trainees list", description=trainees, color=discord.Color.blue()
)
Expand Down
Loading