mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-09-22 19:22:01 +03:00
feat(GuildMember): new timeout() method
This commit is contained in:
parent
ab9a1c03ee
commit
096efba914
3 changed files with 51 additions and 12 deletions
|
@ -3,13 +3,14 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import datetime
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import List, Dict, Optional, Union
|
from typing import List, Dict, Optional, Union
|
||||||
|
|
||||||
from melisa.utils.timestamp import Timestamp
|
from melisa.utils.timestamp import Timestamp
|
||||||
from melisa.utils.snowflake import Snowflake
|
from melisa.utils.snowflake import Snowflake
|
||||||
from melisa.models.user.user import User
|
from melisa.models.user.user import User
|
||||||
from melisa.utils.types import APINullable
|
from melisa.utils.types import APINullable, UNDEFINED
|
||||||
from melisa.utils.api_model import APIModelBase
|
from melisa.utils.api_model import APIModelBase
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,12 +60,12 @@ class GuildMember(APIModelBase):
|
||||||
guild_avatar: APINullable[str] = None
|
guild_avatar: APINullable[str] = None
|
||||||
role_ids: List[Snowflake] = None
|
role_ids: List[Snowflake] = None
|
||||||
joined_at: APINullable[Timestamp] = None
|
joined_at: APINullable[Timestamp] = None
|
||||||
premium_since: APINullable[Timestamp] = None
|
premium_since: APINullable[datetime.datetime] = None
|
||||||
is_deaf: bool = None
|
is_deaf: bool = None
|
||||||
is_mute: bool = None
|
is_mute: bool = None
|
||||||
is_pending: APINullable[bool] = None
|
is_pending: APINullable[bool] = None
|
||||||
permissions: APINullable[str] = None
|
permissions: APINullable[str] = None
|
||||||
communication_disabled_until: APINullable[Timestamp] = None
|
communication_disabled_until: APINullable[datetime.datetime] = None
|
||||||
guild_id: APINullable[Snowflake] = None
|
guild_id: APINullable[Snowflake] = None
|
||||||
|
|
||||||
def make_guild_avatar_url(self, size: int = 1024) -> str:
|
def make_guild_avatar_url(self, size: int = 1024) -> str:
|
||||||
|
@ -122,7 +123,37 @@ class GuildMember(APIModelBase):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
async def timeout(self, *, duration: Optional[float] = None,
|
async def timeout(self, *, duration: Optional[float] = None,
|
||||||
until: Optional[Timestamp] = None):
|
until: Optional[datetime.datetime] = None):
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
Times out the member from the guild;
|
||||||
|
until then, the member will not be able to interact with the guild.
|
||||||
|
|
||||||
|
**Required permissions:** ``MODERATE_MEMBERS``
|
||||||
|
|
||||||
|
duration: Optional[class:`float`]
|
||||||
|
The duration (seconds) of the member's timeout. Set to ``None`` to remove the timeout.
|
||||||
|
Supports up to 28 days in the future.
|
||||||
|
until: Optional[:class:`datetime.datetime`]
|
||||||
|
The expiry date/time of the member's timeout. Set to ``None`` to remove the timeout.
|
||||||
|
Supports up to 28 days in the future.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
if duration is None and until is None:
|
||||||
|
await self._client.rest.modify_guild_member(
|
||||||
|
self.guild_id,
|
||||||
|
self.user.id,
|
||||||
|
communication_disabled_until=None
|
||||||
|
)
|
||||||
|
elif duration is not None:
|
||||||
|
await self._client.rest.modify_guild_member(
|
||||||
|
self.guild_id,
|
||||||
|
self.user.id,
|
||||||
|
communication_disabled_until=datetime.datetime.utcnow() + datetime.timedelta(seconds=duration)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await self._client.rest.modify_guild_member(
|
||||||
|
self.guild_id,
|
||||||
|
self.user.id,
|
||||||
|
communication_disabled_until=until
|
||||||
|
)
|
||||||
|
|
|
@ -291,15 +291,20 @@ class Message(APIModelBase):
|
||||||
"""
|
"""
|
||||||
self: Message = super().__new__(cls)
|
self: Message = super().__new__(cls)
|
||||||
|
|
||||||
_member = data.get("member")
|
|
||||||
|
|
||||||
_member.update({"user": data.get("author")})
|
|
||||||
|
|
||||||
self.id = data["id"]
|
self.id = data["id"]
|
||||||
self.channel_id = Snowflake(data["channel_id"])
|
self.channel_id = Snowflake(data["channel_id"])
|
||||||
self.guild_id = (
|
self.guild_id = (
|
||||||
Snowflake(data["guild_id"]) if data.get("guild_id") is not None else None
|
Snowflake(data["guild_id"]) if data.get("guild_id") is not None else None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_member = data.get("member")
|
||||||
|
|
||||||
|
if _member is None:
|
||||||
|
_member = {}
|
||||||
|
|
||||||
|
_member.update({"user": data.get("author")})
|
||||||
|
_member.update({"guild_id": self.guild_id})
|
||||||
|
|
||||||
self.author = GuildMember.from_dict(_member)
|
self.author = GuildMember.from_dict(_member)
|
||||||
self.content = data.get("content", "")
|
self.content = data.get("content", "")
|
||||||
self.timestamp = Timestamp.parse(data["timestamp"])
|
self.timestamp = Timestamp.parse(data["timestamp"])
|
||||||
|
|
|
@ -51,7 +51,8 @@ class RESTApp:
|
||||||
self._http: HTTPClient = HTTPClient(token)
|
self._http: HTTPClient = HTTPClient(token)
|
||||||
|
|
||||||
async def fetch_user(self, user_id: Union[Snowflake, int, str]) -> User:
|
async def fetch_user(self, user_id: Union[Snowflake, int, str]) -> User:
|
||||||
"""
|
"""|coro|
|
||||||
|
|
||||||
[**REST API**] Fetch User from the Discord API (by id).
|
[**REST API**] Fetch User from the Discord API (by id).
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
@ -65,7 +66,8 @@ class RESTApp:
|
||||||
return User.from_dict(data)
|
return User.from_dict(data)
|
||||||
|
|
||||||
async def fetch_guild(self, guild_id: Union[Snowflake, int, str]) -> Guild:
|
async def fetch_guild(self, guild_id: Union[Snowflake, int, str]) -> Guild:
|
||||||
"""
|
"""|coro|
|
||||||
|
|
||||||
[**REST API**] Fetch Guild from the Discord API (by id).
|
[**REST API**] Fetch Guild from the Discord API (by id).
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
@ -79,7 +81,8 @@ class RESTApp:
|
||||||
return Guild.from_dict(data)
|
return Guild.from_dict(data)
|
||||||
|
|
||||||
async def fetch_channel(self, channel_id: Union[Snowflake, str, int]) -> Channel:
|
async def fetch_channel(self, channel_id: Union[Snowflake, str, int]) -> Channel:
|
||||||
"""
|
"""|coro|
|
||||||
|
|
||||||
[**REST API**] Fetch Channel from the Discord API (by id).
|
[**REST API**] Fetch Channel from the Discord API (by id).
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
Loading…
Reference in a new issue