mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Mod] Add default tempban duration setting (#4473)
* Add support for default duration in kickban.py * add setting command and info to settings view * add config key * black * Thx jack Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * adress review * Address review * typo Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
parent
dc817aeeac
commit
f5de382946
@ -473,7 +473,7 @@ class KickBanMixin(MixinMeta):
|
||||
self,
|
||||
ctx: commands.Context,
|
||||
user: discord.Member,
|
||||
duration: UserInputOptional[commands.TimedeltaConverter] = timedelta(days=1),
|
||||
duration: Optional[commands.TimedeltaConverter] = None,
|
||||
days: Optional[int] = None,
|
||||
*,
|
||||
reason: str = None,
|
||||
@ -481,7 +481,6 @@ class KickBanMixin(MixinMeta):
|
||||
"""Temporarily ban a user from this server."""
|
||||
guild = ctx.guild
|
||||
author = ctx.author
|
||||
unban_time = datetime.now(timezone.utc) + duration
|
||||
|
||||
if author == user:
|
||||
await ctx.send(
|
||||
@ -501,6 +500,10 @@ class KickBanMixin(MixinMeta):
|
||||
await ctx.send(_("I cannot do that due to Discord hierarchy rules."))
|
||||
return
|
||||
|
||||
if duration is None:
|
||||
duration = timedelta(seconds=await self.config.guild(guild).default_tempban_duration())
|
||||
unban_time = datetime.now(timezone.utc) + duration
|
||||
|
||||
if days is None:
|
||||
days = await self.config.guild(guild).default_days()
|
||||
|
||||
|
||||
@ -58,6 +58,7 @@ class Mod(
|
||||
"current_tempbans": [],
|
||||
"dm_on_kickban": False,
|
||||
"default_days": 0,
|
||||
"default_tempban_duration": 60 * 60 * 24,
|
||||
}
|
||||
|
||||
default_channel_settings = {"ignored": False}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
from collections import defaultdict, deque
|
||||
from typing import Optional
|
||||
from datetime import timedelta
|
||||
|
||||
from redbot.core import commands, i18n, checks
|
||||
from redbot.core.utils.chat_formatting import box
|
||||
from redbot.core.utils.chat_formatting import box, humanize_timedelta
|
||||
|
||||
from .abc import MixinMeta
|
||||
|
||||
@ -34,6 +36,7 @@ class ModSettings(MixinMeta):
|
||||
reinvite_on_unban = data["reinvite_on_unban"]
|
||||
dm_on_kickban = data["dm_on_kickban"]
|
||||
default_days = data["default_days"]
|
||||
default_tempban_duration = data["default_tempban_duration"]
|
||||
msg = ""
|
||||
msg += _("Delete repeats: {num_repeats}\n").format(
|
||||
num_repeats=_("after {num} repeats").format(num=delete_repeats)
|
||||
@ -80,6 +83,9 @@ class ModSettings(MixinMeta):
|
||||
)
|
||||
else:
|
||||
msg += _("Default message history delete on ban: Don't delete any\n")
|
||||
msg += _("Default tempban duration: {duration}").format(
|
||||
humanize_timedelta(seconds=default_tempban_duration)
|
||||
)
|
||||
await ctx.send(box(msg))
|
||||
|
||||
@modset.command()
|
||||
@ -365,3 +371,19 @@ class ModSettings(MixinMeta):
|
||||
days=days
|
||||
)
|
||||
)
|
||||
|
||||
@modset.command()
|
||||
@commands.guild_only()
|
||||
async def defaultduration(
|
||||
self,
|
||||
ctx: commands.Context,
|
||||
duration: Optional[commands.TimedeltaConverter] = timedelta(days=0),
|
||||
):
|
||||
"""Set the default time to be used when a user is tempbanned."""
|
||||
guild = ctx.guild
|
||||
await self.config.guild(guild).default_tempban_duration.set(duration.total_seconds())
|
||||
await ctx.send(
|
||||
_("The default duration for tempbanning a user is now {duration}.").format(
|
||||
duration=humanize_timedelta(timedelta=duration)
|
||||
)
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user