Repository: Cog-Creators/Red-DiscordBot

Issue:
Default tempban duration should be configurable
# Feature request

#### Select the type of feature you are requesting:

- [ ] Cog
- [x] Command
- [ ] API functionality

#### Describe your requested feature

Similarly to default number of days worth of messages to be deleted when a user is banned `[p]modset defaultdays`, I think default tempban duration should be configurable as well.



Discussion:

Resolving patch:
diff --git a/redbot/cogs/mod/kickban.py b/redbot/cogs/mod/kickban.py
--- a/redbot/cogs/mod/kickban.py
+++ b/redbot/cogs/mod/kickban.py
@@ -430,7 +430,7 @@ async def tempban(
         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,
@@ -438,7 +438,6 @@ async def tempban(
         """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(
@@ -458,6 +457,10 @@ async def tempban(
             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()
 
diff --git a/redbot/cogs/mod/mod.py b/redbot/cogs/mod/mod.py
--- a/redbot/cogs/mod/mod.py
+++ b/redbot/cogs/mod/mod.py
@@ -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}
diff --git a/redbot/cogs/mod/settings.py b/redbot/cogs/mod/settings.py
--- a/redbot/cogs/mod/settings.py
+++ b/redbot/cogs/mod/settings.py
@@ -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 @@ async def modset_showsettings(self, ctx: commands.Context):
         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 @@ async def modset_showsettings(self, ctx: commands.Context):
             )
         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 @@ async def defaultdays(self, ctx: commands.Context, days: int = 0):
                 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)
+            )
+        )


Test patch: