Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

fix: Add delete_message_seconds to ban helpers #629

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions naff/api/http/http_requests/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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(
Expand Down
11 changes: 8 additions & 3 deletions naff/models/discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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]:
"""
Expand Down
13 changes: 10 additions & 3 deletions naff/models/discord/user.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)