[Mod] Default days in [p]ban command are now configurable (#2930)

* Initial Commit

* Added changelog

* Update redbot/cogs/mod/settings.py

Co-Authored-By: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/cogs/mod/settings.py

Co-Authored-By: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/cogs/mod/settings.py

Co-Authored-By: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/cogs/mod/settings.py

Co-Authored-By: jack1142 <6032823+jack1142@users.noreply.github.com>

* Rename 2930.enhance.rst.txt to 2930.enhance.rst

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
Ianardo DiCaprio 2020-01-23 19:37:11 +00:00 committed by jack1142
parent 40c0d8d83b
commit 1755334124
4 changed files with 37 additions and 8 deletions

View File

@ -0,0 +1 @@
Added a defaultdays command to set the amount of days for the ban commands to use for days of messages deleted when days isn't used in the command itself.

View File

@ -218,15 +218,17 @@ class KickBanMixin(MixinMeta):
self, self,
ctx: commands.Context, ctx: commands.Context,
user: discord.Member, user: discord.Member,
days: Optional[int] = 0, days: Optional[int] = None,
*, *,
reason: str = None, reason: str = None,
): ):
"""Ban a user from this server and optionally delete days of messages. """Ban a user from this server and optionally delete days of messages.
If days is not a number, it's treated as the first word of the reason. If days is not a number, it's treated as the first word of the reason.
Minimum 0 days, maximum 7. Defaults to 0.""" Minimum 0 days, maximum 7. If not specified, defaultdays setting will be used instead."""
guild = ctx.guild
if days is None:
days = await self.settings.guild(guild).default_days()
result = await self.ban_user( result = await self.ban_user(
user=user, ctx=ctx, days=days, reason=reason, create_modlog_case=True user=user, ctx=ctx, days=days, reason=reason, create_modlog_case=True
) )

View File

@ -53,6 +53,7 @@ class Mod(
"delete_delay": -1, "delete_delay": -1,
"reinvite_on_unban": False, "reinvite_on_unban": False,
"current_tempbans": [], "current_tempbans": [],
"default_days": 0,
} }
default_channel_settings = {"ignored": False} default_channel_settings = {"ignored": False}

View File

@ -21,11 +21,13 @@ class ModSettings(MixinMeta):
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
guild = ctx.guild guild = ctx.guild
# Display current settings # Display current settings
delete_repeats = await self.settings.guild(guild).delete_repeats() data = await self.settings.guild(guild).all()
ban_mention_spam = await self.settings.guild(guild).ban_mention_spam() delete_repeats = data["delete_repeats"]
respect_hierarchy = await self.settings.guild(guild).respect_hierarchy() ban_mention_spam = data["ban_mention_spam"]
delete_delay = await self.settings.guild(guild).delete_delay() respect_hierarchy = data["respect_hierarchy"]
reinvite_on_unban = await self.settings.guild(guild).reinvite_on_unban() delete_delay = data["delete_delay"]
reinvite_on_unban = data["reinvite_on_unban"]
default_days = data["default_days"]
msg = "" msg = ""
msg += _("Delete repeats: {num_repeats}\n").format( msg += _("Delete repeats: {num_repeats}\n").format(
num_repeats=_("after {num} repeats").format(num=delete_repeats) num_repeats=_("after {num} repeats").format(num=delete_repeats)
@ -48,6 +50,12 @@ class ModSettings(MixinMeta):
msg += _("Reinvite on unban: {yes_or_no}\n").format( msg += _("Reinvite on unban: {yes_or_no}\n").format(
yes_or_no=_("Yes") if reinvite_on_unban else _("No") yes_or_no=_("Yes") if reinvite_on_unban else _("No")
) )
if default_days:
msg += _(
"Default message history delete on ban: Previous {num_days} days\n"
).format(num_days=default_days)
else:
msg += _("Default message history delete on ban: Don't delete any\n")
await ctx.send(box(msg)) await ctx.send(box(msg))
@modset.command() @modset.command()
@ -199,3 +207,20 @@ class ModSettings(MixinMeta):
command=f"{ctx.prefix}unban" command=f"{ctx.prefix}unban"
) )
) )
@modset.command()
@commands.guild_only()
async def defaultdays(self, ctx: commands.Context, days: int = 0):
"""Set the default number of days worth of messages to be deleted when a user is banned.
The number of days must be between 0 and 7.
"""
guild = ctx.guild
if not (0 <= days <= 7):
return await ctx.send(_("Invalid number of days. Must be between 0 and 7."))
await self.settings.guild(guild).default_days.set(days)
await ctx.send(
_("{days} days worth of messages will be deleted when a user is banned.").format(
days=days
)
)