Skip to content

Commit 665b144

Browse files
committed
refactor(db.py): increase batch_size from 10 to 25 to improve performance
style(error_handler.py): change error message format for better readability feat(poll.py): trim leading and trailing whitespaces from poll options for cleaner data refactor(rolecount.py): rename '_rhel' to '_redhat' for better clarity chore(tools.py): remove unused encoding and decoding methods to clean up code
1 parent e2d5375 commit 665b144

File tree

7 files changed

+11
-31
lines changed

7 files changed

+11
-31
lines changed

tux/cogs/admin/db.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
from tux.database.controllers import DatabaseController
1111

12-
# TODO: Move to a constants file or set a global check/error handler for all commands to avoid repetition.
13-
1412
GUILD_ONLY_MESSAGE = "This command can only be used in a guild."
1513

1614

@@ -41,7 +39,7 @@ async def seed_members(self, interaction: discord.Interaction) -> None:
4139

4240
members: Sequence[discord.Member] = interaction.guild.members
4341

44-
batch_size = 10
42+
batch_size = 25
4543

4644
for i in range(0, len(members), batch_size):
4745
batch = members[i : i + batch_size]
@@ -85,7 +83,7 @@ async def seed_roles(self, interaction: discord.Interaction) -> None:
8583

8684
roles: Sequence[discord.Role] = interaction.guild.roles
8785

88-
batch_size = 10
86+
batch_size = 25
8987

9088
for i in range(0, len(roles), batch_size):
9189
batch = roles[i : i + batch_size]
@@ -129,7 +127,7 @@ async def seed_user_roles(self, interaction: discord.Interaction) -> None:
129127
return
130128

131129
members: Sequence[discord.Member] = interaction.guild.members
132-
batch_size = 10
130+
batch_size = 25
133131

134132
for i in range(0, len(members), batch_size):
135133
batch = members[i : i + batch_size]

tux/cogs/error_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
commands.CheckFailure: "You are not allowed to use this command.",
2929
commands.CommandNotFound: "This command was not found.",
3030
commands.CommandOnCooldown: "This command is on cooldown. Try again in {error.retry_after:.2f} seconds.",
31-
commands.BadArgument: "Invalid argument passed. Correct usage:\n```{ctx.command.usage}```",
32-
commands.MissingRequiredArgument: "Missing required argument. Correct usage:\n```{ctx.command.usage}```",
31+
commands.BadArgument: "Invalid argument passed. Correct usage: `{ctx.command.usage}`",
32+
commands.MissingRequiredArgument: "Missing required argument. Correct usage: `{ctx.command.usage}`",
3333
commands.MissingRequiredAttachment: "Missing required attachment.",
3434
commands.NotOwner: "You are not the owner of this bot.",
3535
commands.BotMissingPermissions: "The bot is missing the required permissions to use this command.",

tux/cogs/utility/poll.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ async def poll(self, interaction: discord.Interaction, title: str, options: str)
3131
# Split the options by comma
3232
options_list = options.split(",")
3333

34+
# Remove any leading or trailing whitespaces from the options
35+
options_list = [option.strip() for option in options_list]
36+
3437
# Check if the options count is between 2-9
3538
if len(options_list) < 2 or len(options_list) > 9:
3639
embed = EmbedCreator.create_error_embed(

tux/cogs/utility/remindme.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ def get_closest_reminder(reminders: list[Reminders]) -> Reminders | None:
3030
return min(reminders, key=lambda x: x.expires_at) if reminders else None
3131

3232

33-
# TODO: Refactor and clean up this code
34-
35-
3633
class RemindMe(commands.Cog):
3734
def __init__(self, bot: commands.Bot) -> None:
3835
self.bot = bot

tux/cogs/utility/rolecount.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
[1192177499413684226, "_asahi"],
6161
[1207599112585740309, "_fedoraatomic"],
6262
[1232383833152819282, "_solus"],
63-
[1210000519272079411, "_rhel"],
63+
[1210000519272079411, "_redhat"],
6464
[1232199326722293790, "_mxlinux"],
6565
[1232387598107017227, "_netbsd"],
6666
[1232385920335089734, "_qubesos"],
@@ -136,7 +136,7 @@
136136
[1189236400571301958, "_chromium"],
137137
]
138138

139-
# # TODO: Figure out how to make this work without hard coding the roles and emojis.
139+
# # TODO: Figure out how to make rolecount work without hard coded ids
140140

141141

142142
class RoleCount(commands.Cog):

tux/cogs/utility/tldr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def get_autocomplete(
3535
A list of up to 25 command names as autocomplete choices.
3636
"""
3737

38-
# TODO: Why is interaction not used?
38+
# TODO: Resolve why interaction is not being used.
3939

4040
commands = self.get_tldrs()
4141

tux/cogs/utility/tools.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,9 @@ def __init__(self, bot: commands.Bot) -> None:
2222
self.bot = bot
2323
self.encodings = {
2424
"base64": self.encode_base64,
25-
# "md5": self.encode_md5,
26-
# "sha256": self.encode_sha256,
27-
# "sha512": self.encode_sha512,
2825
}
2926
self.decodings = {
3027
"base64": self.decode_base64,
31-
# "md5": self.decode_md5,
32-
# "sha256": self.decode_sha256,
33-
# "sha512": self.decode_sha512,
3428
}
3529

3630
def encode_base64(self, input_string: str):
@@ -39,15 +33,6 @@ def encode_base64(self, input_string: str):
3933
def decode_base64(self, input_string: str):
4034
return b64decode(input_string.encode()).decode()
4135

42-
# def encode_md5(self, input_string: str):
43-
# return hashlib.md5(input_string.encode()).hexdigest()
44-
45-
# def encode_sha256(self, input_string: str):
46-
# return hashlib.sha256(input_string.encode()).hexdigest()
47-
48-
# def encode_sha512(self, input_string: str):
49-
# return hashlib.sha512(input_string.encode()).hexdigest()
50-
5136
group = app_commands.Group(name="tools", description="Various tool commands.")
5237

5338
@group.command(name="colors", description="Converts a color to different formats.")
@@ -173,9 +158,6 @@ async def send_message(
173158
@app_commands.choices(
174159
encoding=[
175160
app_commands.Choice[str](name="base64", value="base64"),
176-
# app_commands.Choice[str](name="md5", value="md5"),
177-
# app_commands.Choice[str](name="sha256", value="sha256"),
178-
# app_commands.Choice[str](name="sha512", value="sha512"),
179161
]
180162
)
181163
async def encode(

0 commit comments

Comments
 (0)