feat(GuildMember): new kick() method

This commit is contained in:
grey-cat-1908 2022-05-28 12:19:18 +03:00
parent b70bb6082c
commit 702f7d3129
4 changed files with 137 additions and 52 deletions

View file

@ -5,7 +5,7 @@ from .client import Client, Bot
from .models import * from .models import *
from .exceptions import * from .exceptions import *
from .rest import RESTApp from .rest import RESTApp
from .cache import (CacheManager, AutoCacheModels) from .cache import CacheManager, AutoCacheModels
__package__ = "melisa" __package__ = "melisa"
__title__ = "Melisa" __title__ = "Melisa"

View file

@ -122,8 +122,12 @@ class GuildMember(APIModelBase):
return self return self
async def timeout(self, *, duration: Optional[float] = None, async def timeout(
until: Optional[datetime.datetime] = None): self,
*,
duration: Optional[float] = None,
until: Optional[datetime.datetime] = None,
):
"""|coro| """|coro|
Times out the member from the guild; Times out the member from the guild;
@ -137,23 +141,64 @@ class GuildMember(APIModelBase):
until: Optional[:class:`datetime.datetime`] until: Optional[:class:`datetime.datetime`]
The expiry date/time of the member's timeout. Set to ``None`` to remove the timeout. The expiry date/time of the member's timeout. Set to ``None`` to remove the timeout.
Supports up to 28 days in the future. Supports up to 28 days in the future.
Raises
-------
HTTPException
The request to perform the action failed with other http exception.
ForbiddenError
You do not have proper permissions to do the actions required.
BadRequestError
You provided a wrong type of argument/
Returns
-------
:class:`~melisa.models.guild.member.GuildMember`
This member object.
""" """
if duration is None and until is None: if duration is None and until is None:
await self._client.rest.modify_guild_member( await self._client.rest.modify_guild_member(
self.guild_id, self.guild_id, self.user.id, communication_disabled_until=None
self.user.id,
communication_disabled_until=None
) )
elif duration is not None: elif duration is not None:
await self._client.rest.modify_guild_member( await self._client.rest.modify_guild_member(
self.guild_id, self.guild_id,
self.user.id, self.user.id,
communication_disabled_until=datetime.datetime.utcnow() + datetime.timedelta(seconds=duration) communication_disabled_until=datetime.datetime.utcnow()
+ datetime.timedelta(seconds=duration),
) )
else: else:
await self._client.rest.modify_guild_member( await self._client.rest.modify_guild_member(
self.guild_id, self.guild_id, self.user.id, communication_disabled_until=until
self.user.id, )
communication_disabled_until=until
return self
async def kick(
self,
*,
reason: Optional[str] = None,
):
"""|coro|
Kicks member from a guild.
**Required permissions:** ``KICK_MEMBERS``
Parameters
----------
reason: Optional[:class:`str`]
The reason of the action.
Raises
-------
HTTPException
The request to perform the action failed with other http exception.
ForbiddenError
You do not have proper permissions to do the actions required.
"""
await self._client.rest.remove_guild_member(
self.guild_id, self.user.id, reason=reason
) )

View file

@ -420,7 +420,7 @@ class RESTApp:
**Required permissions:** ``MODERATE_MEMBERS`` **Required permissions:** ``MODERATE_MEMBERS``
reason: Optional[:class:`str`] reason: Optional[:class:`str`]
The reason of the message delete operation. The reason of the action.
Raises Raises
------- -------
@ -446,10 +446,49 @@ class RESTApp:
if voice_channel_id is not UNDEFINED: if voice_channel_id is not UNDEFINED:
data["channel_id"] = voice_channel_id data["channel_id"] = voice_channel_id
if communication_disabled_until is not UNDEFINED: if communication_disabled_until is not UNDEFINED:
data["communication_disabled_until"] = communication_disabled_until.isoformat() data[
"communication_disabled_until"
] = communication_disabled_until.isoformat()
await self._http.patch( await self._http.patch(
f"guilds/{guild_id}/members/{user_id}", f"guilds/{guild_id}/members/{user_id}",
data=data, data=data,
headers={"X-Audit-Log-Reason": reason}, headers={"X-Audit-Log-Reason": reason},
) )
async def remove_guild_member(
self,
guild_id: Union[Snowflake, str, int],
user_id: Union[Snowflake, str, int],
*,
reason: Optional[str] = None,
):
"""|coro|
[**REST API**] Remove a member from a guild.
**Required permissions:** ``KICK_MEMBERS``
Parameters
----------
guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
Id of guild where we will remove member
user_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
Id of user to operate with.
reason: Optional[:class:`str`]
The reason of the action.
Raises
-------
HTTPException
The request to perform the action failed with other http exception.
ForbiddenError
You do not have proper permissions to do the actions required.
BadRequestError
You provided a wrong guild, user or something else.
"""
await self._http.delete(
f"guilds/{guild_id}/members/{user_id}",
headers={"X-Audit-Log-Reason": reason},
)

View file

@ -1,2 +1,3 @@
flake8==4.0.1 flake8==4.0.1
pytest==7.1.2 pytest==7.1.2
black==22.3.0