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
All checks were successful
Pylint / Pylint (push) Successful in 1m13s
This commit is contained in:
parent
0c004ecf48
commit
25ac0a3c0c
1 changed files with 73 additions and 41 deletions
|
@ -22,7 +22,8 @@ class Moderation(commands.Cog):
|
||||||
mysql_database = " ",
|
mysql_database = " ",
|
||||||
mysql_username = " ",
|
mysql_username = " ",
|
||||||
mysql_password = " ",
|
mysql_password = " ",
|
||||||
ignore_other_bots = True
|
ignore_other_bots = True,
|
||||||
|
dm_users = True
|
||||||
)
|
)
|
||||||
disable_dateutil()
|
disable_dateutil()
|
||||||
self.handle_expiry.start() # pylint: disable=no-member
|
self.handle_expiry.start() # pylint: disable=no-member
|
||||||
|
@ -218,29 +219,35 @@ class Moderation(commands.Cog):
|
||||||
raise(TypeError("'type' argument is invalid!"))
|
raise(TypeError("'type' argument is invalid!"))
|
||||||
|
|
||||||
@app_commands.command(name="note")
|
@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."""
|
"""Add a note to a user."""
|
||||||
await interaction.response.send_message(content=f"{target.mention} has recieved a note!\n**Reason** - `{reason}`")
|
await interaction.response.send_message(content=f"{target.mention} has recieved a note!\n**Reason** - `{reason}`")
|
||||||
try:
|
if silent is None:
|
||||||
embed = await self.embed_factory('message', interaction.guild, reason, 'note', await interaction.original_response())
|
silent = not await self.config.dm_users()
|
||||||
await target.send(embed=embed)
|
if silent is False:
|
||||||
except discord.errors.HTTPException:
|
try:
|
||||||
pass
|
embed = await self.embed_factory('message', interaction.guild, reason, 'note', await interaction.original_response())
|
||||||
|
await target.send(embed=embed)
|
||||||
|
except discord.errors.HTTPException:
|
||||||
|
pass
|
||||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'NOTE', target.id, 'NULL', reason)
|
await self.mysql_log(interaction.guild.id, interaction.user.id, 'NOTE', target.id, 'NULL', reason)
|
||||||
|
|
||||||
@app_commands.command(name="warn")
|
@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."""
|
"""Warn a user."""
|
||||||
await interaction.response.send_message(content=f"{target.mention} has been warned!\n**Reason** - `{reason}`")
|
await interaction.response.send_message(content=f"{target.mention} has been warned!\n**Reason** - `{reason}`")
|
||||||
try:
|
if silent is None:
|
||||||
embed = await self.embed_factory('message', interaction.guild, reason, 'warned', await interaction.original_response())
|
silent = not await self.config.dm_users()
|
||||||
await target.send(embed=embed)
|
if silent is False:
|
||||||
except discord.errors.HTTPException:
|
try:
|
||||||
pass
|
embed = await self.embed_factory('message', interaction.guild, reason, 'warned', await interaction.original_response())
|
||||||
|
await target.send(embed=embed)
|
||||||
|
except discord.errors.HTTPException:
|
||||||
|
pass
|
||||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'WARN', target.id, 'NULL', reason)
|
await self.mysql_log(interaction.guild.id, interaction.user.id, 'WARN', target.id, 'NULL', reason)
|
||||||
|
|
||||||
@app_commands.command(name="mute")
|
@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."""
|
"""Mute a user."""
|
||||||
if target.is_timed_out() is True:
|
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)
|
await interaction.response.send_message(f"{target.mention} is already muted!", allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True)
|
||||||
|
@ -255,15 +262,18 @@ class Moderation(commands.Cog):
|
||||||
return
|
return
|
||||||
await target.timeout(parsed_time, reason=f"Muted by {interaction.user.id} for: {reason}")
|
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}`")
|
await interaction.response.send_message(content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}!\n**Reason** - `{reason}`")
|
||||||
try:
|
if silent is None:
|
||||||
embed = await self.embed_factory('message', interaction.guild, reason, 'muted', await interaction.original_response(), parsed_time)
|
silent = not await self.config.dm_users()
|
||||||
await target.send(embed=embed)
|
if silent is False:
|
||||||
except discord.errors.HTTPException:
|
try:
|
||||||
pass
|
embed = await self.embed_factory('message', interaction.guild, reason, 'muted', await interaction.original_response(), parsed_time)
|
||||||
|
await target.send(embed=embed)
|
||||||
|
except discord.errors.HTTPException:
|
||||||
|
pass
|
||||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'MUTE', target.id, parsed_time, reason)
|
await self.mysql_log(interaction.guild.id, interaction.user.id, 'MUTE', target.id, parsed_time, reason)
|
||||||
|
|
||||||
@app_commands.command(name="unmute")
|
@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."""
|
"""Unmute a user."""
|
||||||
if target.is_timed_out() is False:
|
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)
|
await interaction.response.send_message(f"{target.mention} is not muted!", allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True)
|
||||||
|
@ -274,22 +284,28 @@ class Moderation(commands.Cog):
|
||||||
await target.timeout(None, reason=f"Unbanned by {interaction.user.id}")
|
await target.timeout(None, reason=f"Unbanned by {interaction.user.id}")
|
||||||
reason = "No reason given."
|
reason = "No reason given."
|
||||||
await interaction.response.send_message(content=f"{target.mention} has been unmuted!\n**Reason** - `{reason}`")
|
await interaction.response.send_message(content=f"{target.mention} has been unmuted!\n**Reason** - `{reason}`")
|
||||||
try:
|
if silent is None:
|
||||||
embed = await self.embed_factory('message', interaction.guild, reason, 'unmuted', await interaction.original_response())
|
silent = not await self.config.dm_users()
|
||||||
await target.send(embed=embed)
|
if silent is False:
|
||||||
except discord.errors.HTTPException:
|
try:
|
||||||
pass
|
embed = await self.embed_factory('message', interaction.guild, reason, 'unmuted', await interaction.original_response())
|
||||||
|
await target.send(embed=embed)
|
||||||
|
except discord.errors.HTTPException:
|
||||||
|
pass
|
||||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNMUTE', target.id, 'NULL', reason)
|
await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNMUTE', target.id, 'NULL', reason)
|
||||||
|
|
||||||
@app_commands.command(name="kick")
|
@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."""
|
"""Kick a user."""
|
||||||
await interaction.response.send_message(content=f"{target.mention} has been kicked!\n**Reason** - `{reason}`")
|
await interaction.response.send_message(content=f"{target.mention} has been kicked!\n**Reason** - `{reason}`")
|
||||||
try:
|
if silent is None:
|
||||||
embed = await self.embed_factory('message', interaction.guild, reason, 'kicked', await interaction.original_response())
|
silent = not await self.config.dm_users()
|
||||||
await target.send(embed=embed)
|
if silent is False:
|
||||||
except discord.errors.HTTPException:
|
try:
|
||||||
pass
|
embed = await self.embed_factory('message', interaction.guild, reason, 'kicked', await interaction.original_response())
|
||||||
|
await target.send(embed=embed)
|
||||||
|
except discord.errors.HTTPException:
|
||||||
|
pass
|
||||||
await target.kick(f"Kicked by {interaction.user.id} for: {reason}")
|
await target.kick(f"Kicked by {interaction.user.id} for: {reason}")
|
||||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'KICK', target.id, 'NULL', reason)
|
await self.mysql_log(interaction.guild.id, interaction.user.id, 'KICK', target.id, 'NULL', reason)
|
||||||
|
|
||||||
|
@ -326,11 +342,14 @@ class Moderation(commands.Cog):
|
||||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'TEMPBAN', target.id, parsed_time, reason)
|
await self.mysql_log(interaction.guild.id, interaction.user.id, 'TEMPBAN', target.id, parsed_time, reason)
|
||||||
else:
|
else:
|
||||||
await interaction.response.send_message(content=f"{target.mention} has been banned!\n**Reason** - `{reason}`")
|
await interaction.response.send_message(content=f"{target.mention} has been banned!\n**Reason** - `{reason}`")
|
||||||
try:
|
if silent is None:
|
||||||
embed = await self.embed_factory('message', interaction.guild, reason, 'banned', await interaction.original_response())
|
silent = not await self.config.dm_users()
|
||||||
await target.send(embed=embed)
|
if silent is False:
|
||||||
except discord.errors.HTTPException:
|
try:
|
||||||
pass
|
embed = await self.embed_factory('message', interaction.guild, reason, 'banned', await interaction.original_response())
|
||||||
|
await target.send(embed=embed)
|
||||||
|
except discord.errors.HTTPException:
|
||||||
|
pass
|
||||||
await interaction.guild.ban(target, reason=f"Banned by {interaction.user.id} for: {reason}", delete_message_seconds=delete_messages)
|
await interaction.guild.ban(target, reason=f"Banned by {interaction.user.id} for: {reason}", delete_message_seconds=delete_messages)
|
||||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'BAN', target.id, 'NULL', reason)
|
await self.mysql_log(interaction.guild.id, interaction.user.id, 'BAN', target.id, 'NULL', reason)
|
||||||
|
|
||||||
|
@ -348,11 +367,14 @@ class Moderation(commands.Cog):
|
||||||
await interaction.guild.unban(target, reason=f"Unbanned by {interaction.user.id}")
|
await interaction.guild.unban(target, reason=f"Unbanned by {interaction.user.id}")
|
||||||
reason = "No reason given."
|
reason = "No reason given."
|
||||||
await interaction.response.send_message(content=f"{target.mention} has been unbanned!\n**Reason** - `{reason}`")
|
await interaction.response.send_message(content=f"{target.mention} has been unbanned!\n**Reason** - `{reason}`")
|
||||||
try:
|
if silent is None:
|
||||||
embed = await self.embed_factory('message', interaction.guild, reason, 'unbanned', await interaction.original_response())
|
silent = not await self.config.dm_users()
|
||||||
await target.send(embed=embed)
|
if silent is False:
|
||||||
except discord.errors.HTTPException:
|
try:
|
||||||
pass
|
embed = await self.embed_factory('message', interaction.guild, reason, 'unbanned', await interaction.original_response())
|
||||||
|
await target.send(embed=embed)
|
||||||
|
except discord.errors.HTTPException:
|
||||||
|
pass
|
||||||
await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNBAN', target.id, 'NULL', reason)
|
await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNBAN', target.id, 'NULL', reason)
|
||||||
|
|
||||||
@app_commands.command(name="resolve")
|
@app_commands.command(name="resolve")
|
||||||
|
@ -482,9 +504,19 @@ class Moderation(commands.Cog):
|
||||||
@moderationset.command(name="ignorebots")
|
@moderationset.command(name="ignorebots")
|
||||||
@checks.admin()
|
@checks.admin()
|
||||||
async def moderationset_ignorebots(self, ctx: commands.Context):
|
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 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()}")
|
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")
|
@moderationset.command(name="mysql")
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
async def moderationset_mysql(self, ctx: commands.Context):
|
async def moderationset_mysql(self, ctx: commands.Context):
|
||||||
|
|
Loading…
Reference in a new issue