From eb6d14d49c96b0a20c0dff47425547a709e903c3 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Thu, 8 Sep 2022 12:55:56 -0600 Subject: [PATCH] fix: Add delete_message_seconds to ban helpers, deprecation warning on delete_message_days --- naff/api/http/http_requests/guild.py | 6 +++--- naff/models/discord/guild.py | 11 ++++++++--- naff/models/discord/user.py | 13 ++++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/naff/api/http/http_requests/guild.py b/naff/api/http/http_requests/guild.py index 2e69e69d3..9a8e43cbf 100644 --- a/naff/api/http/http_requests/guild.py +++ b/naff/api/http/http_requests/guild.py @@ -253,7 +253,7 @@ async def create_guild_ban( self, guild_id: "Snowflake_Type", user_id: "Snowflake_Type", - delete_message_days: int = 0, + delete_message_seconds: int = 0, reason: str | None = None, ) -> None: """ @@ -262,11 +262,11 @@ async def create_guild_ban( Args: guild_id: The ID of the guild to create the ban in user_id: The ID of the user to ban - delete_message_days: number of days to delete messages for (0-7) + delete_message_seconds: number of seconds to delete messages for (0-604800) reason: The reason for this action """ - payload = {"delete_message_days": delete_message_days} + payload = {"delete_message_seconds": delete_message_seconds} await self.request(Route("PUT", f"/guilds/{int(guild_id)}/bans/{int(user_id)}"), payload=payload, reason=reason) async def remove_guild_ban( diff --git a/naff/models/discord/guild.py b/naff/models/discord/guild.py index d3600ea72..9e6f2bbda 100644 --- a/naff/models/discord/guild.py +++ b/naff/models/discord/guild.py @@ -1594,7 +1594,8 @@ async def kick( async def ban( self, user: Union["models.User", "models.Member", Snowflake_Type], - delete_message_days: int = 0, + delete_message_days: Absent[int] = MISSING, + delete_message_seconds: int = 0, reason: Absent[str] = MISSING, ) -> None: """ @@ -1605,11 +1606,15 @@ async def ban( Args: user: The user to ban - delete_message_days: How many days worth of messages to remove + delete_message_days: (deprecated) How many days worth of messages to remove + delete_message_seconds: How many seconds worth of messages to remove reason: The reason for the ban """ - await self._client.http.create_guild_ban(self.id, to_snowflake(user), delete_message_days, reason=reason) + if delete_message_days is not MISSING: + warn("delete_message_days is deprecated and will be removed in a future update", DeprecationWarning) + delete_message_seconds = delete_message_days * 3600 + await self._client.http.create_guild_ban(self.id, to_snowflake(user), delete_message_seconds, reason=reason) async def fetch_ban(self, user: Union["models.User", "models.Member", Snowflake_Type]) -> Optional[GuildBan]: """ diff --git a/naff/models/discord/user.py b/naff/models/discord/user.py index a6ecb08a2..bb4d7c260 100644 --- a/naff/models/discord/user.py +++ b/naff/models/discord/user.py @@ -1,5 +1,6 @@ from datetime import datetime from typing import TYPE_CHECKING, Any, Iterable, Set, Dict, List, Optional, Union +from warnings import warn from naff.client.const import MISSING, logger, Absent from naff.client.errors import HTTPException, TooManyChanges @@ -599,13 +600,19 @@ async def kick(self, reason: Absent[str] = MISSING) -> None: """ await self._client.http.remove_guild_member(self._guild_id, self.id, reason=reason) - async def ban(self, delete_message_days: int = 0, reason: Absent[str] = MISSING) -> None: + async def ban( + self, delete_message_days: Absent[int] = MISSING, delete_message_seconds: int = 0, reason: Absent[str] = MISSING + ) -> None: """ Ban a member from the guild. Args: - delete_message_days: The number of days of messages to delete + delete_message_days: (deprecated) The number of days of messages to delete + delete_message_seconds: The number of seconds of messages to delete reason: The reason for this ban """ - await self._client.http.create_guild_ban(self._guild_id, self.id, delete_message_days, reason=reason) + if delete_message_days is not MISSING: + warn("delete_message_days is deprecated and will be removed in a future update", DeprecationWarning) + delete_message_seconds = delete_message_days * 3600 + await self._client.http.create_guild_ban(self._guild_id, self.id, delete_message_seconds, reason=reason)