feat(moderation): added silent options to all moderation commands and a config value for automatically dming moderated users
All checks were successful
Pylint / Pylint (push) Successful in 1m13s

This commit is contained in:
Seaswimmer 2023-10-05 20:06:07 -04:00
parent 0c004ecf48
commit 25ac0a3c0c
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -22,7 +22,8 @@ class Moderation(commands.Cog):
mysql_database = " ",
mysql_username = " ",
mysql_password = " ",
ignore_other_bots = True
ignore_other_bots = True,
dm_users = True
)
disable_dateutil()
self.handle_expiry.start() # pylint: disable=no-member
@ -218,9 +219,12 @@ class Moderation(commands.Cog):
raise(TypeError("'type' argument is invalid!"))
@app_commands.command(name="note")
async def note(self, interaction: discord.Interaction, target: discord.Member, reason: str):
async def note(self, interaction: discord.Interaction, target: discord.Member, reason: str, silent: bool = None):
"""Add a note to a user."""
await interaction.response.send_message(content=f"{target.mention} has recieved a note!\n**Reason** - `{reason}`")
if silent is None:
silent = not await self.config.dm_users()
if silent is False:
try:
embed = await self.embed_factory('message', interaction.guild, reason, 'note', await interaction.original_response())
await target.send(embed=embed)
@ -229,9 +233,12 @@ class Moderation(commands.Cog):
await self.mysql_log(interaction.guild.id, interaction.user.id, 'NOTE', target.id, 'NULL', reason)
@app_commands.command(name="warn")
async def warn(self, interaction: discord.Interaction, target: discord.Member, reason: str):
async def warn(self, interaction: discord.Interaction, target: discord.Member, reason: str, silent: bool = None):
"""Warn a user."""
await interaction.response.send_message(content=f"{target.mention} has been warned!\n**Reason** - `{reason}`")
if silent is None:
silent = not await self.config.dm_users()
if silent is False:
try:
embed = await self.embed_factory('message', interaction.guild, reason, 'warned', await interaction.original_response())
await target.send(embed=embed)
@ -240,7 +247,7 @@ class Moderation(commands.Cog):
await self.mysql_log(interaction.guild.id, interaction.user.id, 'WARN', target.id, 'NULL', reason)
@app_commands.command(name="mute")
async def mute(self, interaction: discord.Interaction, target: discord.Member, duration: str, reason: str):
async def mute(self, interaction: discord.Interaction, target: discord.Member, duration: str, reason: str, silent: bool = None):
"""Mute a user."""
if target.is_timed_out() is True:
await interaction.response.send_message(f"{target.mention} is already muted!", allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True)
@ -255,6 +262,9 @@ class Moderation(commands.Cog):
return
await target.timeout(parsed_time, reason=f"Muted by {interaction.user.id} for: {reason}")
await interaction.response.send_message(content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}!\n**Reason** - `{reason}`")
if silent is None:
silent = not await self.config.dm_users()
if silent is False:
try:
embed = await self.embed_factory('message', interaction.guild, reason, 'muted', await interaction.original_response(), parsed_time)
await target.send(embed=embed)
@ -263,7 +273,7 @@ class Moderation(commands.Cog):
await self.mysql_log(interaction.guild.id, interaction.user.id, 'MUTE', target.id, parsed_time, reason)
@app_commands.command(name="unmute")
async def unmute(self, interaction: discord.Interaction, target: discord.Member, reason: str = None):
async def unmute(self, interaction: discord.Interaction, target: discord.Member, reason: str = None, silent: bool = None):
"""Unmute a user."""
if target.is_timed_out() is False:
await interaction.response.send_message(f"{target.mention} is not muted!", allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True)
@ -274,6 +284,9 @@ class Moderation(commands.Cog):
await target.timeout(None, reason=f"Unbanned by {interaction.user.id}")
reason = "No reason given."
await interaction.response.send_message(content=f"{target.mention} has been unmuted!\n**Reason** - `{reason}`")
if silent is None:
silent = not await self.config.dm_users()
if silent is False:
try:
embed = await self.embed_factory('message', interaction.guild, reason, 'unmuted', await interaction.original_response())
await target.send(embed=embed)
@ -282,9 +295,12 @@ class Moderation(commands.Cog):
await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNMUTE', target.id, 'NULL', reason)
@app_commands.command(name="kick")
async def kick(self, interaction: discord.Interaction, target: discord.Member, reason: str):
async def kick(self, interaction: discord.Interaction, target: discord.Member, reason: str, silent: bool = None):
"""Kick a user."""
await interaction.response.send_message(content=f"{target.mention} has been kicked!\n**Reason** - `{reason}`")
if silent is None:
silent = not await self.config.dm_users()
if silent is False:
try:
embed = await self.embed_factory('message', interaction.guild, reason, 'kicked', await interaction.original_response())
await target.send(embed=embed)
@ -326,6 +342,9 @@ class Moderation(commands.Cog):
await self.mysql_log(interaction.guild.id, interaction.user.id, 'TEMPBAN', target.id, parsed_time, reason)
else:
await interaction.response.send_message(content=f"{target.mention} has been banned!\n**Reason** - `{reason}`")
if silent is None:
silent = not await self.config.dm_users()
if silent is False:
try:
embed = await self.embed_factory('message', interaction.guild, reason, 'banned', await interaction.original_response())
await target.send(embed=embed)
@ -348,6 +367,9 @@ class Moderation(commands.Cog):
await interaction.guild.unban(target, reason=f"Unbanned by {interaction.user.id}")
reason = "No reason given."
await interaction.response.send_message(content=f"{target.mention} has been unbanned!\n**Reason** - `{reason}`")
if silent is None:
silent = not await self.config.dm_users()
if silent is False:
try:
embed = await self.embed_factory('message', interaction.guild, reason, 'unbanned', await interaction.original_response())
await target.send(embed=embed)
@ -482,9 +504,19 @@ class Moderation(commands.Cog):
@moderationset.command(name="ignorebots")
@checks.admin()
async def moderationset_ignorebots(self, ctx: commands.Context):
"""Toggle if the cog should ignore other bots' moderations."""
await self.config.ignore_other_bots.set(not await self.config.ignore_other_bots())
await ctx.send(f"Ignore bots setting set to {await self.config.ignore_other_bots()}")
@moderationset.command(name="dm")
@checks.admin()
async def moderationset_dm(self, ctx: commands.Context):
"""Toggle automatically messaging moderated users.
This option can be overridden by specifying the `silent` argument in any moderation command."""
await self.config.dm_users.set(not await self.config.dm_users())
await ctx.send(f"DM users setting set to {await self.config.dm_users()}")
@moderationset.command(name="mysql")
@checks.is_owner()
async def moderationset_mysql(self, ctx: commands.Context):