Skip to content

Commit fe57c02

Browse files
committed
feat(neofetch.py): add new neofetch command to display system and server stats
chore(.pre-commit-config.yaml): add new pre-commit hooks for trailing commas and gitleaks refactor(cog_loader.py): improve error logging for cog loading failures style(.pre-commit-config.yaml, cog_loader.py): apply code formatting rules style(dev.py, eval.py, git.py, mail.py, random.py): improve code readability by breaking down long lines of code into multiple lines refactor(eval.py): add trailing comma to logger.warning for better code formatting refactor(git.py): simplify import statement for Issue from githubkit.versions.latest.models refactor(mail.py): add line breaks for better readability and code consistency refactor(random.py): add line breaks in function parameters and conditions for better readability style(xkcd.py, config.py, export.py): refactor function arguments to multi-line for better readability style: reformat code for better readability in audit.py, commands.py, gate.py, member.py, run.py, temp_vc.py, tty_roles.py, purge.py refactor: improve code readability by breaking down complex expressions and function calls into multiple lines style: reformat code for better readability and PEP8 compliance in multiple files refactor: simplify list declaration in guide.py for better readability refactor: improve function parameter formatting in multiple files for better readability refactor: improve string formatting in multiple files for better readability refactor: improve function declaration formatting in multiple files for better readability refactor: improve embed creation in rolecount.py for better readability style(snippets.py, tldr.py, tools.py, wiki.py): reformat code for better readability refactor(tools.py): simplify dictionary initialization for encodings and decodings perf(tldr.py, tools.py): reduce subprocess.run arguments to improve performance fix(wiki.py): correct the order of error handling and embed creation for better error management refactor(case.py): improve readability by breaking down long function signatures into multiple lines style(case.py): add trailing commas to improve code formatting and ease of future changes style(case.py): improve readability by breaking down long function parameters into multiple lines refactor(case.py): add trailing commas in dictionary to make future changes cleaner and more readable style(guild_config.py): refactor function definitions to improve readability and adhere to PEP8 line length standards style: apply PEP 8 style guide to improve readability and maintainability refactor: add trailing commas to improve diff readability in future changes fix(event_handler.py): add missing comma in message string to fix syntax error style: apply black formatting to improve code readability and maintain consistency across the codebase
1 parent 2625d93 commit fe57c02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+889
-329
lines changed

tux/cogs/fun/neofetch.py renamed to .archive/neofetch.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, bot: commands.Bot) -> None:
2424
async def neofetch(self, interaction: discord.Interaction) -> None:
2525
if interaction.guild is None:
2626
await interaction.response.send_message(
27-
content="This command cannot be used in direct messages.", ephemeral=True
27+
content="This command cannot be used in direct messages.", ephemeral=True,
2828
)
2929
return
3030

@@ -52,21 +52,23 @@ async def neofetch(self, interaction: discord.Interaction) -> None:
5252
⠙⠲⠦⠥⢥⣅⡕⡐⡐⡐⡐⠌⢌⡾⠟⠟⠛⠛⠛⠛⠽⠾⣇⢂⢂⠢⡑⢌⢂⡶⠋⠀⠀⠀⠀
5353
⠀⠀⠀⠀⠀⠀⠈⠑⠒⠶⠬⠞⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠢⣆⣑⡬⠖⠋⠀⠀⠀⠀⠀⠀"""
5454

55+
56+
5557
# get uptime in the format of days, hours, minutes
5658
uptime = time.strftime("%d days, %H hours, %M minutes", time.gmtime(time.time() - psutil.boot_time()))
5759
cpuusage = psutil.cpu_percent()
5860
memusage = psutil.virtual_memory().percent
5961

6062
lines = f"""{yellow}tux{reset}@{yellow}{interaction.guild.name.lower().replace(" ", "")}{reset}
61-
------------------
63+
------------------
6264
Tux Stats{reset}
6365
{red}OS{reset}: Tux Alpha
6466
{yellow}Kernel{reset}: 6.9
6567
{green}Uptime{reset}: {uptime}
6668
{cyan}CPU{reset}: {cpuusage}%
6769
{blue}Memory{reset}: {memusage}%
6870
{pink}Ping{reset}: {round(self.bot.latency * 1000)}ms
69-
------------------
71+
------------------
7072
Server Stats{reset}
7173
{red}Name{reset}: {interaction.guild.name}
7274
{yellow}Owner{reset}: {interaction.guild.owner}

.pre-commit-config.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
repos:
2+
- repo: https://github.com/asottile/add-trailing-comma
3+
rev: v3.1.0
4+
hooks:
5+
- id: add-trailing-comma
6+
27
- repo: https://github.com/astral-sh/ruff-pre-commit
38
rev: v0.5.0
49
hooks:
@@ -7,3 +12,10 @@ repos:
712
args: [--fix]
813
# Run the formatter.
914
- id: ruff-format
15+
16+
- repo: https://github.com/gitleaks/gitleaks
17+
rev: v8.16.1
18+
hooks:
19+
- id: gitleaks
20+
21+
exclude: ".archive/"

tux/cog_loader.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ async def load_cogs(self, apath: AsyncPath) -> None:
7676
logger.debug(f"Successfully loaded cog: {module}")
7777

7878
except Exception as e:
79-
logger.error(f"Failed to load cog {module}. Error: {e}\n{traceback.format_exc()}")
79+
logger.error(
80+
f"Failed to load cog {module}. Error: {e}\n{traceback.format_exc()}",
81+
)
8082

8183
except Exception as e:
8284
logger.error(f"An error occurred while processing {apath}: {e}")

tux/cogs/admin/dev.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ async def dev(self, ctx: commands.Context[commands.Bot]) -> None:
1515
await ctx.send_help("dev")
1616

1717
@commands.has_guild_permissions(administrator=True)
18-
@dev.command(name="sync_tree", description="Syncs the app command tree.", usage="dev sync_tree <guild>")
18+
@dev.command(
19+
name="sync_tree",
20+
description="Syncs the app command tree.",
21+
usage="dev sync_tree <guild>",
22+
)
1923
async def sync_tree(self, ctx: commands.Context[commands.Bot], guild: discord.Guild) -> None:
2024
"""
2125
Syncs the application commands to Discord.
@@ -47,7 +51,11 @@ async def sync_tree(self, ctx: commands.Context[commands.Bot], guild: discord.Gu
4751
await ctx.reply("Application command tree synced.")
4852

4953
@commands.has_guild_permissions(administrator=True)
50-
@dev.command(name="clear_tree", description="Clears the app command tree.", usage="dev clear_tree")
54+
@dev.command(
55+
name="clear_tree",
56+
description="Clears the app command tree.",
57+
usage="dev clear_tree",
58+
)
5159
async def clear_tree(self, ctx: commands.Context[commands.Bot]) -> None:
5260
"""
5361
Parameters
@@ -79,7 +87,11 @@ async def clear_tree(self, ctx: commands.Context[commands.Bot]) -> None:
7987
await ctx.reply("Slash command tree cleared.")
8088

8189
@commands.has_guild_permissions(administrator=True)
82-
@dev.command(name="load_cog", description="Loads a cog into the bot.", usage="dev load_cog <cog>")
90+
@dev.command(
91+
name="load_cog",
92+
description="Loads a cog into the bot.",
93+
usage="dev load_cog <cog>",
94+
)
8395
@app_commands.describe(cog="The name of the cog to load.")
8496
async def load_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) -> None:
8597
"""
@@ -120,7 +132,11 @@ async def load_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) -> No
120132
logger.info(f"Cog {cog} loaded.")
121133

122134
@commands.has_guild_permissions(administrator=True)
123-
@dev.command(name="unload_cog", description="Unloads a cog from the bot.", usage="dev unload_cog <cog>")
135+
@dev.command(
136+
name="unload_cog",
137+
description="Unloads a cog from the bot.",
138+
usage="dev unload_cog <cog>",
139+
)
124140
async def unload_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) -> None:
125141
"""
126142
Unloads an cog from the bot.
@@ -154,7 +170,11 @@ async def unload_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) ->
154170
await ctx.send(f"Cog {cog} unloaded.")
155171

156172
@commands.has_guild_permissions(administrator=True)
157-
@dev.command(name="reload_cog", description="Reloads a cog into the bot.", usage="dev reload_cog <cog>")
173+
@dev.command(
174+
name="reload_cog",
175+
description="Reloads a cog into the bot.",
176+
usage="dev reload_cog <cog>",
177+
)
158178
async def reload_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) -> None:
159179
"""
160180
Reloads a cog in the bot.

tux/cogs/admin/eval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def run(self, ctx: commands.Context[commands.Bot], *, cmd: str) -> None:
5757
# Check if the user is the bot owner
5858
if ctx.author.id != CONST.BOT_OWNER_ID:
5959
logger.warning(
60-
f"{ctx.author} tried to run eval but is not the bot owner. (Owner ID: {self.bot.owner_id}, User ID: {ctx.author.id})"
60+
f"{ctx.author} tried to run eval but is not the bot owner. (Owner ID: {self.bot.owner_id}, User ID: {ctx.author.id})",
6161
)
6262
await ctx.send("You are not the bot owner. Better luck next time!")
6363
return

tux/cogs/admin/git.py

+13-31
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import discord
22
from discord import app_commands
33
from discord.ext import commands
4-
from githubkit.versions.latest.models import (
5-
Issue,
6-
)
4+
from githubkit.versions.latest.models import Issue
75
from loguru import logger
86

97
from tux.services.github import GitHubService
@@ -15,11 +13,7 @@ class LinkButton(discord.ui.View):
1513
def __init__(self, url: str) -> None:
1614
super().__init__()
1715
self.add_item(
18-
discord.ui.Button(
19-
style=discord.ButtonStyle.link,
20-
label="View on Github",
21-
url=url,
22-
)
16+
discord.ui.Button(style=discord.ButtonStyle.link, label="View on Github", url=url),
2317
)
2418

2519

@@ -88,12 +82,7 @@ async def get_repo(self, interaction: discord.Interaction) -> None:
8882

8983
@app_commands.checks.has_any_role("Contributor", "Root", "Admin")
9084
@git.command(name="create_issue", description="Create an issue.")
91-
async def create_issue(
92-
self,
93-
interaction: discord.Interaction,
94-
title: str,
95-
body: str,
96-
) -> None:
85+
async def create_issue(self, interaction: discord.Interaction, title: str, body: str) -> None:
9786
"""
9887
Create an issue.
9988
@@ -168,16 +157,15 @@ async def create_issue_comment(
168157
logger.error(f"Error creating comment: {e}")
169158

170159
else:
171-
await interaction.followup.send(embed=embed, view=LinkButton(created_issue_comment.html_url))
160+
await interaction.followup.send(
161+
embed=embed,
162+
view=LinkButton(created_issue_comment.html_url),
163+
)
172164
logger.info(f"{interaction.user} created a comment.")
173165

174166
@app_commands.checks.has_any_role("Contributor", "Root", "Admin")
175167
@git.command(name="close_issue", description="Close an issue.")
176-
async def close_issue(
177-
self,
178-
interaction: discord.Interaction,
179-
issue_number: int,
180-
) -> None:
168+
async def close_issue(self, interaction: discord.Interaction, issue_number: int) -> None:
181169
"""
182170
Close an issue.
183171
@@ -211,11 +199,7 @@ async def close_issue(
211199

212200
@app_commands.checks.has_any_role("Contributor", "Root", "Admin")
213201
@git.command(name="get_issue", description="Get an issue.")
214-
async def get_issue(
215-
self,
216-
interaction: discord.Interaction,
217-
issue_number: int,
218-
) -> None:
202+
async def get_issue(self, interaction: discord.Interaction, issue_number: int) -> None:
219203
"""
220204
Get an issue.
221205
@@ -321,7 +305,9 @@ async def get_closed_issues(self, interaction: discord.Interaction) -> None:
321305
else:
322306
await interaction.followup.send(
323307
embed=embed,
324-
view=LinkButton("https://github.com/allthingslinux/tux/issues?q=is%3Aissue+is%3Aclosed"),
308+
view=LinkButton(
309+
"https://github.com/allthingslinux/tux/issues?q=is%3Aissue+is%3Aclosed",
310+
),
325311
)
326312
logger.info(f"{interaction.user} fetched closed issues.")
327313

@@ -401,11 +387,7 @@ async def get_closed_pulls(self, interaction: discord.Interaction) -> None:
401387

402388
@app_commands.checks.has_any_role("Contributor", "Root", "Admin")
403389
@git.command(name="get_pull", description="Get a pull request.")
404-
async def get_pull(
405-
self,
406-
interaction: discord.Interaction,
407-
pull_number: int,
408-
) -> None:
390+
async def get_pull(self, interaction: discord.Interaction, pull_number: int) -> None:
409391
"""
410392
Get a pull request.
411393

tux/cogs/admin/mail.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ def __init__(self, bot: commands.Bot) -> None:
3535

3636
@mail.command(name="register", description="Registers a user for mail.")
3737
@app_commands.checks.has_any_role("Root", "Admin", "Mod")
38-
async def register(self, interaction: discord.Interaction, member: discord.Member, username: str) -> None:
38+
async def register(
39+
self,
40+
interaction: discord.Interaction,
41+
member: discord.Member,
42+
username: str,
43+
) -> None:
3944
if not username.isalnum():
4045
await interaction.response.send_message(
41-
"Username must be alphanumeric and contain no spaces.", ephemeral=True
46+
"Username must be alphanumeric and contain no spaces.",
47+
ephemeral=True,
4248
)
4349
return
4450

@@ -71,7 +77,11 @@ async def register(self, interaction: discord.Interaction, member: discord.Membe
7177

7278
async with httpx.AsyncClient(timeout=10.0) as client:
7379
try:
74-
response = await client.post(api_endpoint, headers=self.headers, json=mailbox_data)
80+
response = await client.post(
81+
api_endpoint,
82+
headers=self.headers,
83+
json=mailbox_data,
84+
)
7585
if response.status_code == 200:
7686
result = response.json()
7787
logger.info(f"Response JSON: {result}")
@@ -93,7 +103,8 @@ async def register(self, interaction: discord.Interaction, member: discord.Membe
93103
return
94104

95105
await interaction.response.send_message(
96-
f"Successfully registered {mailbox_info} for mail.", ephemeral=True
106+
f"Successfully registered {mailbox_info} for mail.",
107+
ephemeral=True,
97108
)
98109

99110
dm_message = f"""
@@ -123,7 +134,8 @@ async def register(self, interaction: discord.Interaction, member: discord.Membe
123134

124135
elif response.status_code == 401:
125136
await interaction.response.send_message(
126-
"Unauthorized. Check your API credentials.", ephemeral=True
137+
"Unauthorized. Check your API credentials.",
138+
ephemeral=True,
127139
)
128140
else:
129141
await interaction.response.send_message(
@@ -132,12 +144,14 @@ async def register(self, interaction: discord.Interaction, member: discord.Membe
132144
)
133145
except httpx.RequestError as exc:
134146
await interaction.response.send_message(
135-
f"An error occurred while requesting {exc.request.url!r}.", ephemeral=True
147+
f"An error occurred while requesting {exc.request.url!r}.",
148+
ephemeral=True,
136149
)
137150
logger.error(f"An error occurred while requesting, {exc}")
138151
else:
139152
await interaction.response.send_message(
140-
"This command can only be used in a guild (server).", ephemeral=True
153+
"This command can only be used in a guild (server).",
154+
ephemeral=True,
141155
)
142156

143157

tux/cogs/fun/random.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ async def coinflip(self, ctx: commands.Context[commands.Bot]) -> None:
2727
The context object for the command.
2828
"""
2929

30-
await ctx.send(content="You got heads!" if random.choice([True, False]) else "You got tails!")
30+
await ctx.send(
31+
content="You got heads!" if random.choice([True, False]) else "You got tails!",
32+
)
3133

3234
@random.command(name="8ball", description="Ask the magic 8ball a question.")
3335
@app_commands.describe(question="The question to ask the 8ball.")
@@ -123,7 +125,12 @@ async def dice(self, ctx: commands.Context[commands.Bot], sides: int = 6) -> Non
123125
minimum="The minimum value of the random number. (default: 0)",
124126
maximum="The maximum value of the random number. (default: 100)",
125127
)
126-
async def random_number(self, ctx: commands.Context[commands.Bot], minimum: int = 0, maximum: int = 100) -> None:
128+
async def random_number(
129+
self,
130+
ctx: commands.Context[commands.Bot],
131+
minimum: int = 0,
132+
maximum: int = 100,
133+
) -> None:
127134
"""
128135
Generate a random number.
129136
@@ -138,7 +145,10 @@ async def random_number(self, ctx: commands.Context[commands.Bot], minimum: int
138145
"""
139146

140147
if minimum > maximum:
141-
await ctx.reply(content="The minimum value must be less than the maximum value.", ephemeral=True)
148+
await ctx.reply(
149+
content="The minimum value must be less than the maximum value.",
150+
ephemeral=True,
151+
)
142152
return
143153

144154
await ctx.reply(content=f"Your random number is: {random.randint(minimum, maximum)}")

tux/cogs/fun/xkcd.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,10 @@ class XkcdLinkButtons(discord.ui.View):
1111
def __init__(self, explain_url: str, webpage_url: str) -> None:
1212
super().__init__()
1313
self.add_item(
14-
discord.ui.Button(
15-
style=discord.ButtonStyle.link,
16-
label="Explainxkcd",
17-
url=explain_url,
18-
)
14+
discord.ui.Button(style=discord.ButtonStyle.link, label="Explainxkcd", url=explain_url),
1915
)
2016
self.add_item(
21-
discord.ui.Button(
22-
style=discord.ButtonStyle.link,
23-
label="Webpage",
24-
url=webpage_url,
25-
)
17+
discord.ui.Button(style=discord.ButtonStyle.link, label="Webpage", url=webpage_url),
2618
)
2719

2820

@@ -61,7 +53,9 @@ async def specific(self, interaction: discord.Interaction, comic_id: int) -> Non
6153
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
6254

6355
async def get_comic_and_embed(
64-
self, latest: bool = False, number: int | None = None
56+
self,
57+
latest: bool = False,
58+
number: int | None = None,
6559
) -> tuple[discord.Embed, discord.ui.View | None, bool]:
6660
"""
6761
Get the xkcd comic and create an embed.

0 commit comments

Comments
 (0)