feat(bot): ✨ Make ban durations stack.
This commit is contained in:
+20
-3
@@ -1,6 +1,6 @@
|
||||
from typing import Literal
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
import discord
|
||||
from discord import abc
|
||||
@@ -147,7 +147,7 @@ class Payphone(commands.AutoShardedBot):
|
||||
async def ban(
|
||||
self,
|
||||
user: discord.User | discord.Member | models.User | int,
|
||||
until: datetime | None,
|
||||
duration: timedelta | None,
|
||||
reason: str,
|
||||
moderator: discord.User | discord.Member | models.User | int | None = None,
|
||||
) -> models.Ban:
|
||||
@@ -155,7 +155,7 @@ class Payphone(commands.AutoShardedBot):
|
||||
|
||||
Args:
|
||||
user (discord.User | discord.Member | models.User | int): The user to ban or their ID.
|
||||
until (datetime | None): The expiry date, or None if it does not expire.
|
||||
duration (timedelta | None): The expiry date, or None if it does not expire.
|
||||
reason (str): The reason of the ban.
|
||||
moderator (discord.User | discord.Member | models.User | int | None, optional): The
|
||||
moderator who performed the action.
|
||||
@@ -173,6 +173,23 @@ class Payphone(commands.AutoShardedBot):
|
||||
else moderator
|
||||
)
|
||||
|
||||
until = datetime.now(timezone.utc) + duration if duration is not None else None
|
||||
|
||||
if duration is not None:
|
||||
last_ban = (
|
||||
await models.Ban.filter(user_id=user_id)
|
||||
.order_by("-created_at")
|
||||
.limit(1)
|
||||
.first()
|
||||
)
|
||||
|
||||
if last_ban is not None:
|
||||
until = (
|
||||
duration + last_ban.expires_at
|
||||
if last_ban.expires_at is not None
|
||||
else None
|
||||
)
|
||||
|
||||
row = await models.Ban.create(
|
||||
user_id=user_id,
|
||||
reason=reason,
|
||||
|
||||
Reference in New Issue
Block a user