mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
feat(rest): modify_guild_member method
This commit is contained in:
parent
53fee10d8c
commit
ab9a1c03ee
4 changed files with 126 additions and 32 deletions
|
@ -4,7 +4,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Dict
|
||||
from typing import List, Dict, Optional, Union
|
||||
|
||||
from melisa.utils.timestamp import Timestamp
|
||||
from melisa.utils.snowflake import Snowflake
|
||||
|
@ -120,3 +120,9 @@ class GuildMember(APIModelBase):
|
|||
self.guild_id = data.get("guild_id")
|
||||
|
||||
return self
|
||||
|
||||
async def timeout(self, *, duration: Optional[float] = None,
|
||||
until: Optional[Timestamp] = None):
|
||||
"""
|
||||
|
||||
"""
|
||||
|
|
|
@ -360,7 +360,7 @@ class Embed(APIModelBase):
|
|||
|
||||
return self
|
||||
|
||||
def set_timestamp(self, time: Union[Timestamp, datetime]) -> Embed:
|
||||
def set_timestamp(self, time: datetime) -> Embed:
|
||||
"""Sets timestamp in the supported by discord format.
|
||||
|
||||
Parameters
|
||||
|
|
|
@ -300,7 +300,7 @@ class Message(APIModelBase):
|
|||
self.guild_id = (
|
||||
Snowflake(data["guild_id"]) if data.get("guild_id") is not None else None
|
||||
)
|
||||
self.author = _member
|
||||
self.author = GuildMember.from_dict(_member)
|
||||
self.content = data.get("content", "")
|
||||
self.timestamp = Timestamp.parse(data["timestamp"])
|
||||
self.edited_timestamp = (
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Copyright MelisaDev 2022 - Present
|
||||
# Full MIT License can be found in `LICENSE.txt` at the project root.
|
||||
|
||||
import datetime
|
||||
from typing import Union, Optional, List, Dict, Any, AsyncIterator
|
||||
|
||||
from aiohttp import FormData
|
||||
|
@ -8,7 +9,7 @@ from aiohttp import FormData
|
|||
from .models.message import Embed, File, AllowedMentions, Message
|
||||
from .exceptions import EmbedFieldError
|
||||
from .core.http import HTTPClient
|
||||
from .utils import json
|
||||
from .utils import json, UNDEFINED
|
||||
from .utils.snowflake import Snowflake
|
||||
from .models.guild.guild import Guild
|
||||
from .models.user.user import User
|
||||
|
@ -362,3 +363,90 @@ class RESTApp:
|
|||
|
||||
for message in messages:
|
||||
yield Message.from_dict(message)
|
||||
|
||||
async def modify_guild_member(
|
||||
self,
|
||||
guild_id: Union[Snowflake, str, int],
|
||||
user_id: Union[Snowflake, str, int],
|
||||
*,
|
||||
nick: Optional[str] = UNDEFINED,
|
||||
roles: Optional[List[Snowflake]] = UNDEFINED,
|
||||
is_mute: Optional[bool] = UNDEFINED,
|
||||
is_deaf: Optional[bool] = UNDEFINED,
|
||||
voice_channel_id: Optional[Snowflake] = UNDEFINED,
|
||||
communication_disabled_until: Optional[datetime.datetime] = UNDEFINED,
|
||||
reason: Optional[str] = None,
|
||||
):
|
||||
"""|coro|
|
||||
|
||||
[**REST API**] Modify attributes of a guild member.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
|
||||
Id of guild where we will modify member
|
||||
user_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
|
||||
Id of user to operate with.
|
||||
nick: Optional[:class:`str`]
|
||||
Value to set user's nickname to.
|
||||
|
||||
**Required permissions:** ``MANAGE_NICKNAMES``
|
||||
roles: Optional[List[:class:`~.melisa.utils.snowflake.Snowflake`]]
|
||||
List of role ids the member is assigned
|
||||
|
||||
**Required permissions:** ``MANAGE_ROLES``
|
||||
is_mute
|
||||
Whether the user is muted in voice channels.
|
||||
|
||||
**Required permissions:** ``MUTE_MEMBERS``
|
||||
is_deaf
|
||||
Whether the user is deafened in voice channels.
|
||||
|
||||
**Required permissions:** ``DEAFEN_MEMBERS``
|
||||
voice_channel_id: Optional[:class:`~.melisa.utils.snowflake.Snowflake`]
|
||||
Id of channel to move user to (if they are connected to voice)
|
||||
|
||||
**Required permissions:** ``MOVE_MEMBERS``
|
||||
communication_disabled_until: Optional[:class:`~melisa.utils.timestamp.Timestamp`]
|
||||
When the user's timeout will expire and the user will be able to communicate
|
||||
in the guild again (up to 28 days in the future),
|
||||
set to ``None`` to remove timeout.
|
||||
|
||||
Will throw a 403 error if the user has the ``ADMINISTRATOR`` permission
|
||||
or is the owner of the guild
|
||||
|
||||
**Required permissions:** ``MODERATE_MEMBERS``
|
||||
reason: Optional[:class:`str`]
|
||||
The reason of the message delete operation.
|
||||
|
||||
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, or you set ``is_deaf``,
|
||||
``is_mute`` when user is not in the channel
|
||||
"""
|
||||
|
||||
data = {}
|
||||
|
||||
if nick is not UNDEFINED:
|
||||
data["nick"] = nick
|
||||
if roles is not UNDEFINED:
|
||||
data["roles"] = roles
|
||||
if is_mute is not UNDEFINED:
|
||||
data["mute"] = is_mute
|
||||
if is_deaf is not UNDEFINED:
|
||||
data["deaf"] = is_deaf
|
||||
if voice_channel_id is not UNDEFINED:
|
||||
data["channel_id"] = voice_channel_id
|
||||
if communication_disabled_until is not UNDEFINED:
|
||||
data["communication_disabled_until"] = communication_disabled_until.isoformat()
|
||||
|
||||
await self._http.patch(
|
||||
f"guilds/{guild_id}/members/{user_id}",
|
||||
data=data,
|
||||
headers={"X-Audit-Log-Reason": reason},
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue