fix(moderation): reduced fatal error levels to error level, and info to debug
This commit is contained in:
parent
2703fb2fc0
commit
0e0c75f987
1 changed files with 58 additions and 10 deletions
|
@ -92,7 +92,7 @@ class Moderation(commands.Cog):
|
|||
])
|
||||
|
||||
if conf:
|
||||
self.logger.fatal("Failed to create tables, due to MySQL connection configuration being unset.")
|
||||
self.logger.error("Failed to create tables, due to MySQL connection configuration being unset.")
|
||||
return
|
||||
|
||||
guilds: list[discord.Guild] = self.bot.guilds
|
||||
|
@ -194,7 +194,7 @@ class Moderation(commands.Cog):
|
|||
return connection
|
||||
|
||||
except mysql.connector.ProgrammingError as e:
|
||||
self.logger.fatal("Unable to access the MySQL database!\nError:\n%s", e.msg)
|
||||
self.logger.error("Unable to access the MySQL database!\nError:\n%s", e.msg)
|
||||
raise ConnectionRefusedError(f"Unable to access the MySQL Database!\n{e.msg}") from e
|
||||
|
||||
async def create_guild_table(self, guild: discord.Guild):
|
||||
|
@ -203,7 +203,7 @@ class Moderation(commands.Cog):
|
|||
|
||||
try:
|
||||
cursor.execute(f"SELECT * FROM `moderation_{guild.id}`")
|
||||
self.logger.info("MySQL Table exists for server %s (%s)", guild.name, guild.id)
|
||||
self.logger.debug("MySQL Table exists for server %s (%s)", guild.name, guild.id)
|
||||
|
||||
except mysql.connector.errors.ProgrammingError:
|
||||
query = f"""
|
||||
|
@ -243,7 +243,7 @@ class Moderation(commands.Cog):
|
|||
|
||||
database.commit()
|
||||
|
||||
self.logger.info("MySQL Table (moderation_%s) created for %s (%s)", guild.id, guild.name, guild.id)
|
||||
self.logger.debug("MySQL Table (moderation_%s) created for %s (%s)", guild.id, guild.name, guild.id)
|
||||
|
||||
database.close()
|
||||
|
||||
|
@ -668,13 +668,61 @@ class Moderation(commands.Cog):
|
|||
await interaction.edit_original_response(content=f"{target.mention} has been warned! (Case `#{moderation_id:n}`)\n**Reason** - `{reason}`")
|
||||
await self.log(interaction, moderation_id)
|
||||
|
||||
# @app_commands.group(name="blacklist")
|
||||
# async def blacklist(self, interaction: discord.Interaction):
|
||||
# """Blacklist users."""
|
||||
async def blacklist_autocomplete(self, interaction: discord.Interaction, current: str,) -> list[app_commands.Choice[str]]:
|
||||
"""Autocompletes a blacklist role."""
|
||||
blacklist_roles = await self.config.guild(interaction.guild).blacklist_roles()
|
||||
|
||||
# @blacklist.command(name="add")
|
||||
# async def blacklist_add(self, interaction: discord.Interaction, target: discord.Member, reason: str, silent: bool = None):
|
||||
# """"""
|
||||
if blacklist_roles:
|
||||
return [app_commands.Choice(name=role.name, value=role.id) for role in interaction.guild.roles if role.id in blacklist_roles]
|
||||
else:
|
||||
return []
|
||||
|
||||
@app_commands.command(name="blacklist")
|
||||
@app_commands.autocomplete(blacklist_autocomplete)
|
||||
async def blacklist(self, interaction: discord.Interaction, target: discord.Member, role: str, reason: str, silent: bool = None):
|
||||
"""Add a blacklist role to a user.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
target: discord.Member
|
||||
Who are you blacklisting?
|
||||
role: str
|
||||
What blacklist type are you applying to the target?
|
||||
reason: str
|
||||
Why are you blacklisting this user?
|
||||
silent: bool
|
||||
Should the user be messaged?"""
|
||||
blacklist_roles = await self.config.guild(interaction.guild).blacklist_roles()
|
||||
|
||||
if not blacklist_roles:
|
||||
await interaction.response.send_message(content=f"There are no blacklist types set for this server!", ephemeral=True)
|
||||
return
|
||||
|
||||
matching_role = None
|
||||
|
||||
for role_dict in blacklist_roles:
|
||||
if role_dict['id'] == role:
|
||||
matching_role = role_dict
|
||||
break
|
||||
|
||||
if not matching_role:
|
||||
await interaction.response.send_message(content=f"Please provide a valid blacklist type!", ephemeral=True)
|
||||
return
|
||||
|
||||
if not await self.check_moddable(target, interaction, ['moderate_members', 'manage_roles']):
|
||||
return
|
||||
|
||||
if role in [role.id for role in target.roles]:
|
||||
await interaction.response.send_message(content=f"{target.mention} already has the blacklist role!", ephemeral=True)
|
||||
return
|
||||
|
||||
role_obj = interaction.guild.get_role(role)
|
||||
await target.add_roles(role, reason=f"Blacklisted by {interaction.user.id} for {humanize.precisedelta(matching_role['duration'])} for: {reason}")
|
||||
await interaction.response.send_message(content=f"{target.mention} has been blacklisted with the {role_obj.name} role for {humanize.precisedelta(matching_role['duration'])}!\n**Reason** - `{reason}`")
|
||||
|
||||
moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'BLACKLIST', target.id, role, matching_role['duration'], reason)
|
||||
await interaction.edit_original_response(content=f"{target.mention} has been blacklisted with the {role_obj.name} role for {humanize.precisedelta(matching_role['duration'])}! (Case `#{moderation_id:n}`)\n**Reason** - `{reason}`")
|
||||
await self.log(interaction, moderation_id)
|
||||
|
||||
@app_commands.command(name="mute")
|
||||
async def mute(self, interaction: discord.Interaction, target: discord.Member, duration: str, reason: str, silent: bool = None):
|
||||
|
|
Loading…
Reference in a new issue