Skip to content

Commit

Permalink
Added Functionality to Require Mod Reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin1015wang committed Nov 21, 2024
1 parent 30058c0 commit 166fa15
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/cog_guides/mod.rst
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,28 @@ and reason as to why they were kicked/banned.

.. _mod-command-modset-hierarchy:

"""""""""
modset reason
"""""""""

**Syntax**

.. code-block:: none
[p]modset reason [enabled]
**Description**

Toggle whether a reason is required for mod actions.

If this is enabled, the bot will require a reason to be provided for all mod actions.

**Arguments**

* ``[enabled]``: Whether a reason should be required when performing mod actions. |bool-input|

.. _mod-command-modset-hierarchy:

""""""""""""""""
modset hierarchy
""""""""""""""""
Expand Down
44 changes: 44 additions & 0 deletions redbot/cogs/mod/kickban.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ async def ban_user(

removed_temp = False

if await self.config.guild(guild).mod_reason():
if reason is None:
return False, _("You must provide a reason for the ban.")

if not (0 <= days <= 7):
return False, _("Invalid days. Must be between 0 and 7.")

Expand Down Expand Up @@ -303,6 +307,11 @@ async def kick(self, ctx: commands.Context, member: discord.Member, *, reason: s
author = ctx.author
guild = ctx.guild

if await self.config.guild(guild).mod_reason():
if reason is None:
await ctx.send(_("You must provide a reason for the kick."))
return

if author == member:
await ctx.send(
_("I cannot let you do that. Self-harm is bad {emoji}").format(
Expand Down Expand Up @@ -428,6 +437,11 @@ async def massban(
errors = {}
upgrades = []

if await self.config.guild(ctx.guild).mod_reason():
if reason is None:
await ctx.send(_("You must provide a reason for the massban."))
return

async def show_results():
text = _("Banned {num} users from the server.").format(
num=humanize_number(len(banned))
Expand Down Expand Up @@ -605,6 +619,11 @@ async def tempban(
guild = ctx.guild
author = ctx.author

if await self.config.guild(guild).mod_reason():
if reason is None:
await ctx.send(_("You must provide a reason for the tempban."))
return

if author == member:
await ctx.send(
_("I cannot let you do that. Self-harm is bad {}").format("\N{PENSIVE FACE}")
Expand Down Expand Up @@ -684,6 +703,11 @@ async def softban(self, ctx: commands.Context, member: discord.Member, *, reason
guild = ctx.guild
author = ctx.author

if await self.config.guild(guild).mod_reason():
if reason is None:
await ctx.send(_("You must provide a reason for the softban."))
return

if author == member:
await ctx.send(
_("I cannot let you do that. Self-harm is bad {emoji}").format(
Expand Down Expand Up @@ -771,6 +795,11 @@ async def voicekick(
self, ctx: commands.Context, member: discord.Member, *, reason: str = None
):
"""Kick a member from a voice channel."""
if await self.config.guild(ctx.guild).mod_reason():
if reason is None:
await ctx.send(_("You must provide a reason for the voicekick."))
return

author = ctx.author
guild = ctx.guild
user_voice_state: discord.VoiceState = member.voice
Expand Down Expand Up @@ -818,6 +847,11 @@ async def voiceunban(
self, ctx: commands.Context, member: discord.Member, *, reason: str = None
):
"""Unban a user from speaking and listening in the server's voice channels."""
if await self.config.guild(ctx.guild).mod_reason():
if reason is None:
await ctx.send(_("You must provide a reason for the voiceunban."))
return

user_voice_state = member.voice
if (
await self._voice_perm_check(
Expand Down Expand Up @@ -859,6 +893,11 @@ async def voiceunban(
@commands.admin_or_permissions(mute_members=True, deafen_members=True)
async def voiceban(self, ctx: commands.Context, member: discord.Member, *, reason: str = None):
"""Ban a user from speaking and listening in the server's voice channels."""
if await self.config.guild(ctx.guild).mod_reason():
if reason is None:
await ctx.send(_("You must provide a reason for the voiceban."))
return

user_voice_state: discord.VoiceState = member.voice
if (
await self._voice_perm_check(
Expand Down Expand Up @@ -908,6 +947,11 @@ async def unban(
1. Copy it from the mod log case (if one was created), or
2. Enable Developer Mode, go to Bans in this server's settings, right-click the user and select 'Copy ID'.
"""
if await self.config.guild(ctx.guild).mod_reason():
if reason is None:
await ctx.send(_("You must provide a reason for the unban."))
return

guild = ctx.guild
author = ctx.author
audit_reason = get_audit_reason(ctx.author, reason, shorten=True)
Expand Down
1 change: 1 addition & 0 deletions redbot/cogs/mod/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Mod(
"reinvite_on_unban": False,
"current_tempbans": [],
"dm_on_kickban": False,
"mod_reason": False,
"default_days": 0,
"default_tempban_duration": 60 * 60 * 24,
"track_nicknames": True,
Expand Down
24 changes: 24 additions & 0 deletions redbot/cogs/mod/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,30 @@ async def dm(self, ctx: commands.Context, enabled: bool = None):
_("Bot will no longer attempt to send a DM to user before kick and ban.")
)

@modset.command()
@commands.guild_only()
# add command for setting reason requirement for mod actions
async def reason(self, ctx: commands.Context, enabled: bool = None):
"""
Toggle whether a reason is required for mod actions.
If this is enabled, the bot will require a reason to be provided for all mod actions.
"""
guild = ctx.guild
if enabled is None:
setting = await self.config.guild(guild).mod_reason()
await ctx.send(
_("Mod action reason requirement is currently set to: {setting}").format(
setting=setting
)
)
return
await self.config.guild(guild).mod_reason.set(enabled)
if enabled:
await ctx.send(_("Bot will now require a reason for all mod actions."))
else:
await ctx.send(_("Bot will no longer require a reason for all mod actions."))

@modset.command()
@commands.guild_only()
async def defaultdays(self, ctx: commands.Context, days: int = 0):
Expand Down

0 comments on commit 166fa15

Please sign in to comment.