chore: ruff formatting

This commit is contained in:
neoarz
2025-11-02 23:32:52 -05:00
parent 2ce2c69a87
commit 1eff6c9f53
91 changed files with 3824 additions and 2518 deletions

View File

@@ -8,13 +8,17 @@ class CogManagement(commands.Cog, name="cog_management"):
def __init__(self, bot) -> None:
self.bot = bot
async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False) -> None:
async def send_embed(
self, context: Context, embed: discord.Embed, *, ephemeral: bool = False
) -> None:
interaction = getattr(context, "interaction", None)
if interaction is not None:
if interaction.response.is_done():
await interaction.followup.send(embed=embed, ephemeral=ephemeral)
else:
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
await interaction.response.send_message(
embed=embed, ephemeral=ephemeral
)
else:
await context.send(embed=embed)
@@ -38,15 +42,20 @@ class CogManagement(commands.Cog, name="cog_management"):
except Exception as e:
embed = discord.Embed(
title="Error",
description=f"Could not load the `{cog}` cog.\n```{str(e)}```", color=0xE02B2B
description=f"Could not load the `{cog}` cog.\n```{str(e)}```",
color=0xE02B2B,
)
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed, ephemeral=True)
return
embed = discord.Embed(
description=f"Successfully loaded the `{cog}` cog.", color=0x7289DA
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed)
@commands.hybrid_command(
@@ -69,15 +78,20 @@ class CogManagement(commands.Cog, name="cog_management"):
except Exception as e:
embed = discord.Embed(
title="Error",
description=f"Could not unload the `{cog}` cog.\n```{str(e)}```", color=0xE02B2B
description=f"Could not unload the `{cog}` cog.\n```{str(e)}```",
color=0xE02B2B,
)
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed, ephemeral=True)
return
embed = discord.Embed(
description=f"Successfully unloaded the `{cog}` cog.", color=0x7289DA
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed)
@commands.hybrid_command(
@@ -100,16 +114,22 @@ class CogManagement(commands.Cog, name="cog_management"):
except Exception as e:
embed = discord.Embed(
title="Error",
description=f"Could not reload the `{cog}` cog.\n```{str(e)}```", color=0xE02B2B
description=f"Could not reload the `{cog}` cog.\n```{str(e)}```",
color=0xE02B2B,
)
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed, ephemeral=True)
return
embed = discord.Embed(
title="Cog Management",
description=f"Successfully reloaded the `{cog}` cog.", color=0x7289DA
description=f"Successfully reloaded the `{cog}` cog.",
color=0x7289DA,
)
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed)
async def cog_command_error(self, context: Context, error) -> None:
@@ -117,9 +137,11 @@ class CogManagement(commands.Cog, name="cog_management"):
embed = discord.Embed(
title="Permission Denied",
description="You are not the owner of the bot!",
color=0xE02B2B
color=0xE02B2B,
)
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed, ephemeral=True)
else:
raise error

View File

@@ -10,13 +10,17 @@ class Invite(commands.Cog, name="invite"):
def __init__(self, bot) -> None:
self.bot = bot
async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False) -> None:
async def send_embed(
self, context: Context, embed: discord.Embed, *, ephemeral: bool = False
) -> None:
interaction = getattr(context, "interaction", None)
if interaction is not None:
if interaction.response.is_done():
await interaction.followup.send(embed=embed, ephemeral=ephemeral)
else:
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
await interaction.response.send_message(
embed=embed, ephemeral=ephemeral
)
else:
await context.send(embed=embed)
@@ -38,9 +42,15 @@ class Invite(commands.Cog, name="invite"):
await context.send("Bot is not ready. Try again shortly.")
return
invite_link = os.getenv("INVITE_LINK")
embed = discord.Embed(title="Install", description=f"Install me by clicking [here]({invite_link}).", color=0x7289DA)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed = discord.Embed(
title="Install",
description=f"Install me by clicking [here]({invite_link}).",
color=0x7289DA,
)
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=False)
async def cog_command_error(self, context: Context, error) -> None:
@@ -48,9 +58,11 @@ class Invite(commands.Cog, name="invite"):
embed = discord.Embed(
title="Permission Denied",
description="You are not the owner of this bot.",
color=0xE02B2B
color=0xE02B2B,
)
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed, ephemeral=True)
else:
raise error

View File

@@ -10,18 +10,24 @@ from utils.checks import is_owner_or_friend
class Logs(commands.Cog, name="logs"):
def __init__(self, bot) -> None:
self.bot = bot
async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False) -> None:
async def send_embed(
self, context: Context, embed: discord.Embed, *, ephemeral: bool = False
) -> None:
interaction = getattr(context, "interaction", None)
if interaction is not None:
if interaction.response.is_done():
await interaction.followup.send(embed=embed, ephemeral=ephemeral)
else:
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
await interaction.response.send_message(
embed=embed, ephemeral=ephemeral
)
else:
await context.send(embed=embed)
async def send_file(self, context: Context, *, file: discord.File, ephemeral: bool = False) -> None:
async def send_file(
self, context: Context, *, file: discord.File, ephemeral: bool = False
) -> None:
interaction = getattr(context, "interaction", None)
if interaction is not None:
if interaction.response.is_done():
@@ -35,7 +41,9 @@ class Logs(commands.Cog, name="logs"):
name="logs",
description="View the bot's log file",
)
@app_commands.describe(lines="Number of lines to read from the end of the log file (default: 50, max: 200)")
@app_commands.describe(
lines="Number of lines to read from the end of the log file (default: 50, max: 200)"
)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
@app_commands.allowed_installs(guilds=True, users=True)
@is_owner_or_friend()
@@ -44,12 +52,15 @@ class Logs(commands.Cog, name="logs"):
lines = 200
elif lines < 1:
lines = 1
log_file_path = os.getenv("LOG_FILE", "logs/discord.log")
if not os.path.isabs(log_file_path):
log_file_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), log_file_path)
log_file_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
log_file_path,
)
try:
if not os.path.exists(log_file_path):
embed = discord.Embed(
@@ -57,47 +68,57 @@ class Logs(commands.Cog, name="logs"):
description=f"Log file not found at: `{log_file_path}`",
color=0xE02B2B,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=True)
return
with open(log_file_path, 'r', encoding='utf-8', errors='replace') as f:
with open(log_file_path, "r", encoding="utf-8", errors="replace") as f:
all_lines = f.readlines()
if not all_lines:
embed = discord.Embed(
title="Logs",
description="Log file is empty.",
color=0x7289DA,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=True)
return
selected_lines = all_lines[-lines:] if len(all_lines) > lines else all_lines
log_content = ''.join(selected_lines)
log_content = "".join(selected_lines)
log_file = f"logs.txt"
with open(log_file, "w", encoding="utf-8") as f:
f.write(f"Bot logs extracted at {discord.utils.utcnow().strftime('%Y-%m-%d %H:%M:%S')} UTC\n")
f.write(f"Last {len(selected_lines)} lines from {os.path.basename(log_file_path)}\n")
f.write(
f"Bot logs extracted at {discord.utils.utcnow().strftime('%Y-%m-%d %H:%M:%S')} UTC\n"
)
f.write(
f"Last {len(selected_lines)} lines from {os.path.basename(log_file_path)}\n"
)
f.write(f"Total lines in log file: {len(all_lines)}\n")
f.write("-" * 50 + "\n\n")
f.write(ascii_plain + "\n\n")
f.write(log_content)
file_obj = discord.File(log_file)
await self.send_file(context, file=file_obj, ephemeral=True)
os.remove(log_file)
except PermissionError:
embed = discord.Embed(
title="Error",
description=f"Permission denied when trying to read log file: `{log_file_path}`",
color=0xE02B2B,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=True)
except Exception as e:
embed = discord.Embed(
@@ -105,7 +126,9 @@ class Logs(commands.Cog, name="logs"):
description=f"An error occurred while reading the log file:\n```\n{str(e)}\n```",
color=0xE02B2B,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=True)
async def cog_command_error(self, context: Context, error) -> None:
@@ -115,7 +138,9 @@ class Logs(commands.Cog, name="logs"):
description="You are not the owner of this bot!",
color=0xE02B2B,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=True)
else:
raise error
@@ -123,4 +148,3 @@ class Logs(commands.Cog, name="logs"):
async def setup(bot) -> None:
await bot.add_cog(Logs(bot))

View File

@@ -9,13 +9,24 @@ class Say(commands.Cog, name="say"):
def __init__(self, bot) -> None:
self.bot = bot
async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False, allowed_mentions: discord.AllowedMentions = None) -> None:
async def send_embed(
self,
context: Context,
embed: discord.Embed,
*,
ephemeral: bool = False,
allowed_mentions: discord.AllowedMentions = None,
) -> None:
interaction = getattr(context, "interaction", None)
if interaction is not None:
if interaction.response.is_done():
await interaction.followup.send(embed=embed, ephemeral=ephemeral, allowed_mentions=allowed_mentions)
await interaction.followup.send(
embed=embed, ephemeral=ephemeral, allowed_mentions=allowed_mentions
)
else:
await interaction.response.send_message(embed=embed, ephemeral=ephemeral, allowed_mentions=allowed_mentions)
await interaction.response.send_message(
embed=embed, ephemeral=ephemeral, allowed_mentions=allowed_mentions
)
else:
await context.send(embed=embed, allowed_mentions=allowed_mentions)
@@ -42,9 +53,9 @@ class Say(commands.Cog, name="say"):
self.bot.logger.info(
f"Say command used in DMs by {context.author} (ID: {context.author.id}): {message}"
)
allowed_mentions = discord.AllowedMentions.none()
interaction = getattr(context, "interaction", None)
if interaction is not None:
is_in_guild = context.guild is not None
@@ -57,7 +68,9 @@ class Say(commands.Cog, name="say"):
except:
pass
except discord.Forbidden:
await interaction.followup.send(message, allowed_mentions=allowed_mentions)
await interaction.followup.send(
message, allowed_mentions=allowed_mentions
)
else:
try:
await context.message.delete()
@@ -88,28 +101,34 @@ class Say(commands.Cog, name="say"):
self.bot.logger.info(
f"Embed command used in DMs by {context.author} (ID: {context.author.id}): {message}"
)
allowed_mentions = discord.AllowedMentions.none()
embed = discord.Embed(
title="Say",
description=message,
color=0x7289DA,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
interaction = getattr(context, "interaction", None)
if interaction is not None:
is_in_guild = context.guild is not None
await interaction.response.defer(ephemeral=is_in_guild)
try:
await context.channel.send(embed=embed, allowed_mentions=allowed_mentions)
await context.channel.send(
embed=embed, allowed_mentions=allowed_mentions
)
if is_in_guild:
try:
await interaction.delete_original_response()
except:
pass
except discord.Forbidden:
await interaction.followup.send(embed=embed, allowed_mentions=allowed_mentions)
await interaction.followup.send(
embed=embed, allowed_mentions=allowed_mentions
)
else:
try:
await context.message.delete()
@@ -117,7 +136,6 @@ class Say(commands.Cog, name="say"):
pass
await context.send(embed=embed, allowed_mentions=allowed_mentions)
async def cog_command_error(self, context: Context, error) -> None:
if isinstance(error, (commands.NotOwner, commands.CheckFailure)):
embed = discord.Embed(
@@ -125,7 +143,9 @@ class Say(commands.Cog, name="say"):
description="You are not the owner of this bot!",
color=0xE02B2B,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=True)
else:
raise error

View File

@@ -9,14 +9,18 @@ from discord.ext.commands import Context
class Shutdown(commands.Cog, name="shutdown"):
def __init__(self, bot) -> None:
self.bot = bot
async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False) -> None:
async def send_embed(
self, context: Context, embed: discord.Embed, *, ephemeral: bool = False
) -> None:
interaction = getattr(context, "interaction", None)
if interaction is not None:
if interaction.response.is_done():
await interaction.followup.send(embed=embed, ephemeral=ephemeral)
else:
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
await interaction.response.send_message(
embed=embed, ephemeral=ephemeral
)
else:
await context.send(embed=embed)
@@ -42,7 +46,7 @@ class Shutdown(commands.Cog, name="shutdown"):
self.bot.logger.info(
f"Executed shutdown command by {context.author} (ID: {context.author.id}) in DMs"
)
embed = discord.Embed(
title="Shutdown",
description="Shutting down. Bye! <a:PandaThanos:1417483671253811262>",
@@ -59,7 +63,9 @@ class Shutdown(commands.Cog, name="shutdown"):
description="You are not the owner of this bot!",
color=0xE02B2B,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=True)
else:
raise error

View File

@@ -8,13 +8,17 @@ class Sync(commands.Cog, name="sync"):
def __init__(self, bot) -> None:
self.bot = bot
async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False) -> None:
async def send_embed(
self, context: Context, embed: discord.Embed, *, ephemeral: bool = False
) -> None:
interaction = getattr(context, "interaction", None)
if interaction is not None:
if interaction.response.is_done():
await interaction.followup.send(embed=embed, ephemeral=ephemeral)
else:
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
await interaction.response.send_message(
embed=embed, ephemeral=ephemeral
)
else:
await context.send(embed=embed)
@@ -40,7 +44,9 @@ class Sync(commands.Cog, name="sync"):
description="Slash commands have been globally synchronized.",
color=0x7289DA,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed)
return
elif scope == "guild":
@@ -51,7 +57,9 @@ class Sync(commands.Cog, name="sync"):
description="Slash commands have been synchronized in this guild.",
color=0x7289DA,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed)
return
embed = discord.Embed(
@@ -59,7 +67,9 @@ class Sync(commands.Cog, name="sync"):
description="The scope must be `global` or `guild`.",
color=0xE02B2B,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=True)
@commands.hybrid_command(
@@ -87,7 +97,9 @@ class Sync(commands.Cog, name="sync"):
description="Slash commands have been globally unsynchronized.",
color=0x7289DA,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed)
return
elif scope == "guild":
@@ -98,7 +110,9 @@ class Sync(commands.Cog, name="sync"):
description="Slash commands have been unsynchronized in this guild.",
color=0x7289DA,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed)
return
embed = discord.Embed(
@@ -106,10 +120,11 @@ class Sync(commands.Cog, name="sync"):
description="The scope must be `global` or `guild`.",
color=0xE02B2B,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=True)
async def cog_command_error(self, context: Context, error) -> None:
if isinstance(error, commands.NotOwner):
embed = discord.Embed(
@@ -117,7 +132,9 @@ class Sync(commands.Cog, name="sync"):
description="You are not the owner of this bot!",
color=0xE02B2B,
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
embed.set_author(
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
)
await self.send_embed(context, embed, ephemeral=True)
else:
raise error