style(aurora): reformat with ruff

This commit is contained in:
cswimr 2025-03-28 10:17:25 -05:00
parent ab22b791d1
commit df22f73d2e
Signed by: cswimr
GPG key ID: 0EC431A8DA8F8087
8 changed files with 64 additions and 102 deletions

View file

@ -17,13 +17,9 @@ class ImportAuroraView(ui.View):
self.message: Message = message self.message: Message = message
@ui.button(label="Yes", style=ButtonStyle.success) @ui.button(label="Yes", style=ButtonStyle.success)
async def import_button_y( async def import_button_y(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
self, interaction: Interaction, button: ui.Button
): # pylint: disable=unused-argument
await self.message.delete() await self.message.delete()
await interaction.response.send_message( await interaction.response.send_message("Deleting original table...", ephemeral=True)
"Deleting original table...", ephemeral=True
)
database = connect() database = connect()
cursor = database.cursor() cursor = database.cursor()
@ -101,16 +97,10 @@ class ImportAuroraView(ui.View):
await interaction.edit_original_response(content="Import complete.") await interaction.edit_original_response(content="Import complete.")
if failed_cases: if failed_cases:
await interaction.edit_original_response( await interaction.edit_original_response(content="Import complete.\n" + warning("Failed to import the following cases:\n") + box(failed_cases))
content="Import complete.\n"
+ warning("Failed to import the following cases:\n")
+ box(failed_cases)
)
@ui.button(label="No", style=ButtonStyle.danger) @ui.button(label="No", style=ButtonStyle.danger)
async def import_button_n( async def import_button_n(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
self, interaction: Interaction, button: ui.Button
): # pylint: disable=unused-argument
await self.message.edit(content="Import cancelled.", view=None) await self.message.edit(content="Import cancelled.", view=None)
await self.message.delete(10) await self.message.delete(10)
await self.ctx.message.delete(10) await self.ctx.message.delete(10)

View file

@ -16,13 +16,9 @@ class ImportGalacticBotView(ui.View):
self.message: Message = message self.message: Message = message
@ui.button(label="Yes", style=ButtonStyle.success) @ui.button(label="Yes", style=ButtonStyle.success)
async def import_button_y( async def import_button_y(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
self, interaction: Interaction, button: ui.Button
): # pylint: disable=unused-argument
await self.message.delete() await self.message.delete()
await interaction.response.send_message( await interaction.response.send_message("Deleting original table...", ephemeral=True)
"Deleting original table...", ephemeral=True
)
database = connect() database = connect()
cursor = database.cursor() cursor = database.cursor()
@ -92,9 +88,7 @@ class ImportGalacticBotView(ui.View):
if resolved_by is None: if resolved_by is None:
resolved_by = "?" resolved_by = "?"
if resolved_reason is None: if resolved_reason is None:
resolved_reason = ( resolved_reason = "Could not get resolve reason during moderation import."
"Could not get resolve reason during moderation import."
)
if resolved_timestamp is None: if resolved_timestamp is None:
resolved_timestamp = timestamp resolved_timestamp = timestamp
changes = [ changes = [
@ -142,16 +136,10 @@ class ImportGalacticBotView(ui.View):
await interaction.edit_original_response(content="Import complete.") await interaction.edit_original_response(content="Import complete.")
if failed_cases: if failed_cases:
await interaction.edit_original_response( await interaction.edit_original_response(content="Import complete.\n" + warning("Failed to import the following cases:\n") + box(failed_cases))
content="Import complete.\n"
+ warning("Failed to import the following cases:\n")
+ box(failed_cases)
)
@ui.button(label="No", style=ButtonStyle.danger) @ui.button(label="No", style=ButtonStyle.danger)
async def import_button_n( async def import_button_n(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
self, interaction: Interaction, button: ui.Button
): # pylint: disable=unused-argument
await self.message.edit(content="Import cancelled.", view=None) await self.message.edit(content="Import cancelled.", view=None)
await self.message.delete(10) await self.message.delete(10)
await self.ctx.message.delete(10) await self.ctx.message.delete(10)

View file

@ -23,7 +23,7 @@ class Addrole(ui.View):
return return
await interaction.response.defer() await interaction.response.defer()
async with config.guild(self.ctx.guild).addrole_whitelist() as addrole_whitelist: async with config.guild(self.ctx.guild).addrole_whitelist() as addrole_whitelist:
addrole_whitelist: list # type hint addrole_whitelist: list # type hint
for value in select.values: for value in select.values:
if value.id in addrole_whitelist: if value.id in addrole_whitelist:
addrole_whitelist.remove(value.id) addrole_whitelist.remove(value.id)
@ -32,7 +32,7 @@ class Addrole(ui.View):
await interaction.message.edit(embed=await addrole_embed(self.ctx)) await interaction.message.edit(embed=await addrole_embed(self.ctx))
@ui.button(label="Clear", style=ButtonStyle.red, row=1) @ui.button(label="Clear", style=ButtonStyle.red, row=1)
async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message(error("You must have the manage guild permission to clear the guild's addrole whitelist."), ephemeral=True) await interaction.response.send_message(error("You must have the manage guild permission to clear the guild's addrole whitelist."), ephemeral=True)
return return
@ -41,7 +41,7 @@ class Addrole(ui.View):
await interaction.message.edit(embed=await addrole_embed(self.ctx)) await interaction.message.edit(embed=await addrole_embed(self.ctx))
@ui.button(label="Close", style=ButtonStyle.gray) @ui.button(label="Close", style=ButtonStyle.gray)
async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message(error("You can't do that!"), ephemeral=True) await interaction.response.send_message(error("You can't do that!"), ephemeral=True)
return return

View file

@ -17,7 +17,7 @@ class Guild(ui.View):
await self.message.edit(view=None) await self.message.edit(view=None)
@ui.button(label="Show Moderator", style=ButtonStyle.green, row=0) @ui.button(label="Show Moderator", style=ButtonStyle.green, row=0)
async def show_moderator(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def show_moderator(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return
@ -27,7 +27,7 @@ class Guild(ui.View):
await interaction.message.edit(embed=await guild_embed(self.ctx)) await interaction.message.edit(embed=await guild_embed(self.ctx))
@ui.button(label="Use Discord Permissions", style=ButtonStyle.green, row=0) @ui.button(label="Use Discord Permissions", style=ButtonStyle.green, row=0)
async def use_discord_permissions(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def use_discord_permissions(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return
@ -37,7 +37,7 @@ class Guild(ui.View):
await interaction.message.edit(embed=await guild_embed(self.ctx)) await interaction.message.edit(embed=await guild_embed(self.ctx))
@ui.button(label="Respect Hierarchy", style=ButtonStyle.green, row=0) @ui.button(label="Respect Hierarchy", style=ButtonStyle.green, row=0)
async def respect_heirarchy(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def respect_heirarchy(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return
@ -47,7 +47,7 @@ class Guild(ui.View):
await interaction.message.edit(embed=await guild_embed(self.ctx)) await interaction.message.edit(embed=await guild_embed(self.ctx))
@ui.button(label="Ignore Modlog", style=ButtonStyle.green, row=0) @ui.button(label="Ignore Modlog", style=ButtonStyle.green, row=0)
async def ignore_modlog(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def ignore_modlog(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return
@ -57,7 +57,7 @@ class Guild(ui.View):
await interaction.message.edit(embed=await guild_embed(self.ctx)) await interaction.message.edit(embed=await guild_embed(self.ctx))
@ui.button(label="Ignore Other Bots", style=ButtonStyle.green, row=0) @ui.button(label="Ignore Other Bots", style=ButtonStyle.green, row=0)
async def ignore_other_bots(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def ignore_other_bots(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return
@ -67,7 +67,7 @@ class Guild(ui.View):
await interaction.message.edit(embed=await guild_embed(self.ctx)) await interaction.message.edit(embed=await guild_embed(self.ctx))
@ui.button(label="DM Users", style=ButtonStyle.green, row=1) @ui.button(label="DM Users", style=ButtonStyle.green, row=1)
async def dm_users(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def dm_users(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return
@ -77,7 +77,7 @@ class Guild(ui.View):
await interaction.message.edit(embed=await guild_embed(self.ctx)) await interaction.message.edit(embed=await guild_embed(self.ctx))
@ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=1) @ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=1)
async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return
@ -87,7 +87,7 @@ class Guild(ui.View):
await interaction.message.edit(embed=await guild_embed(self.ctx)) await interaction.message.edit(embed=await guild_embed(self.ctx))
@ui.button(label="Ephemeral", style=ButtonStyle.green, row=1) @ui.button(label="Ephemeral", style=ButtonStyle.green, row=1)
async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return
@ -97,7 +97,7 @@ class Guild(ui.View):
await interaction.message.edit(embed=await guild_embed(self.ctx)) await interaction.message.edit(embed=await guild_embed(self.ctx))
@ui.button(label="History Inline", style=ButtonStyle.green, row=1) @ui.button(label="History Inline", style=ButtonStyle.green, row=1)
async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return
@ -107,7 +107,11 @@ class Guild(ui.View):
await interaction.message.edit(embed=await guild_embed(self.ctx)) await interaction.message.edit(embed=await guild_embed(self.ctx))
@ui.select(placeholder="History Pagesize", options=create_pagesize_options(), row=2) @ui.select(placeholder="History Pagesize", options=create_pagesize_options(), row=2)
async def pagesize(self, interaction: Interaction, select: ui.Select,): async def pagesize(
self,
interaction: Interaction,
select: ui.Select,
):
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return
@ -119,7 +123,11 @@ class Guild(ui.View):
await interaction.message.edit(embed=await guild_embed(self.ctx)) await interaction.message.edit(embed=await guild_embed(self.ctx))
@ui.select(placeholder="History Inline Pagesize", options=create_pagesize_options(), row=3) @ui.select(placeholder="History Inline Pagesize", options=create_pagesize_options(), row=3)
async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): async def inline_pagesize(
self,
interaction: Interaction,
select: ui.Select,
):
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True) await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
return return

View file

@ -23,7 +23,7 @@ class Immune(ui.View):
return return
await interaction.response.defer() await interaction.response.defer()
async with config.guild(self.ctx.guild).immune_roles() as immune_roles: async with config.guild(self.ctx.guild).immune_roles() as immune_roles:
immune_roles: list # type hint immune_roles: list # type hint
for value in select.values: for value in select.values:
if value.id in immune_roles: if value.id in immune_roles:
immune_roles.remove(value.id) immune_roles.remove(value.id)
@ -32,7 +32,7 @@ class Immune(ui.View):
await interaction.message.edit(embed=await immune_embed(self.ctx)) await interaction.message.edit(embed=await immune_embed(self.ctx))
@ui.button(label="Clear", style=ButtonStyle.red, row=1) @ui.button(label="Clear", style=ButtonStyle.red, row=1)
async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def clear(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message(error("You must have the manage guild permission to clear the guild's immune roles."), ephemeral=True) await interaction.response.send_message(error("You must have the manage guild permission to clear the guild's immune roles."), ephemeral=True)
return return
@ -41,7 +41,7 @@ class Immune(ui.View):
await interaction.message.edit(embed=await immune_embed(self.ctx)) await interaction.message.edit(embed=await immune_embed(self.ctx))
@ui.button(label="Close", style=ButtonStyle.gray) @ui.button(label="Close", style=ButtonStyle.gray)
async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def close(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator: if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
await interaction.response.send_message(error("You can't do that!"), ephemeral=True) await interaction.response.send_message(error("You can't do that!"), ephemeral=True)
return return

View file

@ -17,7 +17,7 @@ class Overrides(ui.View):
await self.message.edit(view=None) await self.message.edit(view=None)
@ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=0) @ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=0)
async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if self.ctx.author != interaction.user: if self.ctx.author != interaction.user:
await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
return return
@ -32,7 +32,7 @@ class Overrides(ui.View):
await interaction.message.edit(embed=await overrides_embed(self.ctx)) await interaction.message.edit(embed=await overrides_embed(self.ctx))
@ui.button(label="Ephemeral", style=ButtonStyle.green, row=0) @ui.button(label="Ephemeral", style=ButtonStyle.green, row=0)
async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if self.ctx.author != interaction.user: if self.ctx.author != interaction.user:
await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
return return
@ -47,7 +47,7 @@ class Overrides(ui.View):
await interaction.message.edit(embed=await overrides_embed(self.ctx)) await interaction.message.edit(embed=await overrides_embed(self.ctx))
@ui.button(label="Inline", style=ButtonStyle.green, row=0) @ui.button(label="Inline", style=ButtonStyle.green, row=0)
async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
if self.ctx.author != interaction.user: if self.ctx.author != interaction.user:
await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
return return
@ -62,7 +62,11 @@ class Overrides(ui.View):
await interaction.message.edit(embed=await overrides_embed(self.ctx)) await interaction.message.edit(embed=await overrides_embed(self.ctx))
@ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1) @ui.select(placeholder="Inline Pagesize", options=create_pagesize_options(), row=1)
async def inline_pagesize(self, interaction: Interaction, select: ui.Select,): async def inline_pagesize(
self,
interaction: Interaction,
select: ui.Select,
):
if self.ctx.author != interaction.user: if self.ctx.author != interaction.user:
await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
return return
@ -74,7 +78,11 @@ class Overrides(ui.View):
await interaction.message.edit(embed=await overrides_embed(self.ctx)) await interaction.message.edit(embed=await overrides_embed(self.ctx))
@ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2) @ui.select(placeholder="Pagesize", options=create_pagesize_options(), row=2)
async def pagesize(self, interaction: Interaction, select: ui.Select,): async def pagesize(
self,
interaction: Interaction,
select: ui.Select,
):
if self.ctx.author != interaction.user: if self.ctx.author != interaction.user:
await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True) await interaction.response.send_message("You cannot change this setting for other users.", ephemeral=True)
return return

View file

@ -8,23 +8,18 @@ from discord import Guild
from redbot.core import data_manager from redbot.core import data_manager
from .logger import logger from .logger import logger
from .utils import (convert_timedelta_to_str, generate_dict, from .utils import convert_timedelta_to_str, generate_dict, get_next_case_number
get_next_case_number)
def connect() -> sqlite3.Connection: def connect() -> sqlite3.Connection:
"""Connects to the SQLite database, and returns a connection object.""" """Connects to the SQLite database, and returns a connection object."""
try: try:
connection = sqlite3.connect( connection = sqlite3.connect(database=data_manager.cog_data_path(raw_name="Aurora") / "aurora.db")
database=data_manager.cog_data_path(raw_name="Aurora") / "aurora.db"
)
return connection return connection
except sqlite3.OperationalError as e: except sqlite3.OperationalError as e:
logger.error("Unable to access the SQLite database!\nError:\n%s", e.msg) logger.error("Unable to access the SQLite database!\nError:\n%s", e.msg)
raise ConnectionRefusedError( raise ConnectionRefusedError(f"Unable to access the SQLite Database!\n{e.msg}") from e
f"Unable to access the SQLite Database!\n{e.msg}"
) from e
async def create_guild_table(guild: Guild): async def create_guild_table(guild: Guild):

View file

@ -32,24 +32,17 @@ def check_permissions(
raise (KeyError) raise (KeyError)
for permission in permissions: for permission in permissions:
if ( if not getattr(resolved_permissions, permission, False) and resolved_permissions.administrator is not True:
not getattr(resolved_permissions, permission, False)
and resolved_permissions.administrator is not True
):
return permission return permission
return False return False
async def check_moddable( async def check_moddable(target: Union[User, Member], interaction: Interaction, permissions: list) -> bool:
target: Union[User, Member], interaction: Interaction, permissions: list
) -> bool:
"""Checks if a moderator can moderate a target.""" """Checks if a moderator can moderate a target."""
if check_permissions(interaction.client.user, permissions, guild=interaction.guild): if check_permissions(interaction.client.user, permissions, guild=interaction.guild):
await interaction.response.send_message( await interaction.response.send_message(
error( error(f"I do not have the `{permissions}` permission, required for this action."),
f"I do not have the `{permissions}` permission, required for this action."
),
ephemeral=True, ephemeral=True,
) )
return False return False
@ -57,43 +50,30 @@ async def check_moddable(
if await config.guild(interaction.guild).use_discord_permissions() is True: if await config.guild(interaction.guild).use_discord_permissions() is True:
if check_permissions(interaction.user, permissions, guild=interaction.guild): if check_permissions(interaction.user, permissions, guild=interaction.guild):
await interaction.response.send_message( await interaction.response.send_message(
error( error(f"You do not have the `{permissions}` permission, required for this action."),
f"You do not have the `{permissions}` permission, required for this action."
),
ephemeral=True, ephemeral=True,
) )
return False return False
if interaction.user.id == target.id: if interaction.user.id == target.id:
await interaction.response.send_message( await interaction.response.send_message(content="You cannot moderate yourself!", ephemeral=True)
content="You cannot moderate yourself!", ephemeral=True
)
return False return False
if target.bot: if target.bot:
await interaction.response.send_message( await interaction.response.send_message(content="You cannot moderate bots!", ephemeral=True)
content="You cannot moderate bots!", ephemeral=True
)
return False return False
if isinstance(target, Member): if isinstance(target, Member):
if interaction.user.top_role <= target.top_role and await config.guild(interaction.guild).respect_hierarchy() is True: if interaction.user.top_role <= target.top_role and await config.guild(interaction.guild).respect_hierarchy() is True:
await interaction.response.send_message( await interaction.response.send_message(
content=error( content=error("You cannot moderate members with a higher role than you!"),
"You cannot moderate members with a higher role than you!"
),
ephemeral=True, ephemeral=True,
) )
return False return False
if ( if interaction.guild.get_member(interaction.client.user.id).top_role <= target.top_role:
interaction.guild.get_member(interaction.client.user.id).top_role
<= target.top_role
):
await interaction.response.send_message( await interaction.response.send_message(
content=error( content=error("You cannot moderate members with a role higher than the bot!"),
"You cannot moderate members with a role higher than the bot!"
),
ephemeral=True, ephemeral=True,
) )
return False return False
@ -118,9 +98,7 @@ async def get_next_case_number(guild_id: str, cursor=None) -> int:
if not cursor: if not cursor:
database = connect() database = connect()
cursor = database.cursor() cursor = database.cursor()
cursor.execute( cursor.execute(f"SELECT moderation_id FROM `moderation_{guild_id}` ORDER BY moderation_id DESC LIMIT 1")
f"SELECT moderation_id FROM `moderation_{guild_id}` ORDER BY moderation_id DESC LIMIT 1"
)
result = cursor.fetchone() result = cursor.fetchone()
return (result[0] + 1) if result else 1 return (result[0] + 1) if result else 1
@ -171,7 +149,6 @@ async def fetch_user_dict(client: commands.Bot, user_id: str) -> dict:
"discriminator": "0", "discriminator": "0",
} }
return user_dict return user_dict
@ -216,9 +193,7 @@ async def log(interaction: Interaction, moderation_id: int, resolved: bool = Fal
case = await fetch_case(moderation_id, interaction.guild.id) case = await fetch_case(moderation_id, interaction.guild.id)
if case: if case:
embed = await log_factory( embed = await log_factory(interaction=interaction, case_dict=case, resolved=resolved)
interaction=interaction, case_dict=case, resolved=resolved
)
try: try:
await logging_channel.send(embed=embed) await logging_channel.send(embed=embed)
except Forbidden: except Forbidden:
@ -229,11 +204,7 @@ async def send_evidenceformat(interaction: Interaction, case_dict: dict) -> None
"""This function sends an ephemeral message to the moderator who took the moderation action, with a pre-made codeblock for use in the mod-evidence channel.""" """This function sends an ephemeral message to the moderator who took the moderation action, with a pre-made codeblock for use in the mod-evidence channel."""
from .factory import evidenceformat_factory from .factory import evidenceformat_factory
send_evidence_bool = ( send_evidence_bool = await config.user(interaction.user).auto_evidenceformat() or await config.guild(interaction.guild).auto_evidenceformat() or False
await config.user(interaction.user).auto_evidenceformat()
or await config.guild(interaction.guild).auto_evidenceformat()
or False
)
if send_evidence_bool is False: if send_evidence_bool is False:
return return
@ -286,12 +257,14 @@ def create_pagesize_options() -> list[SelectOption]:
) )
return options return options
def timedelta_from_relativedelta(relativedelta: rd) -> td: def timedelta_from_relativedelta(relativedelta: rd) -> td:
"""Converts a relativedelta object to a timedelta object.""" """Converts a relativedelta object to a timedelta object."""
now = datetime.now() now = datetime.now()
then = now - relativedelta then = now - relativedelta
return now - then return now - then
def get_footer_image(coginstance: commands.Cog) -> File: def get_footer_image(coginstance: commands.Cog) -> File:
"""Returns the footer image for the embeds.""" """Returns the footer image for the embeds."""
image_path = data_manager.bundled_data_path(coginstance) / "arrow.png" image_path = data_manager.bundled_data_path(coginstance) / "arrow.png"