mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
feat(RESTApp): add get_global_application_commands() method
This commit is contained in:
parent
06d4853a38
commit
eb6a198cab
4 changed files with 56 additions and 26 deletions
|
@ -184,7 +184,12 @@ class HTTPClient:
|
|||
return await self.__send("GET", route, params=params)
|
||||
|
||||
async def post(
|
||||
self, route: str, *, headers: dict = None, data: Optional[Dict] = None
|
||||
self,
|
||||
route: str,
|
||||
*,
|
||||
headers: dict = None,
|
||||
json: Optional[Dict] = None,
|
||||
data=None,
|
||||
) -> Optional[Dict]:
|
||||
"""|coro|
|
||||
Sends a POST request to a Discord REST API endpoint.
|
||||
|
@ -193,7 +198,9 @@ class HTTPClient:
|
|||
----------
|
||||
route : :class:`str`
|
||||
The endpoint to send the request to.
|
||||
data : Dict
|
||||
json : Dict
|
||||
Json data to post
|
||||
data : Any
|
||||
Data to post
|
||||
headers : :class:`dict`
|
||||
Custom request headers
|
||||
|
@ -203,7 +210,7 @@ class HTTPClient:
|
|||
Optional[:class:`Dict`]
|
||||
JSON response from the Discord API.
|
||||
"""
|
||||
return await self.__send("POST", route, json=data, headers=headers)
|
||||
return await self.__send("POST", route, json=json, data=data, headers=headers)
|
||||
|
||||
async def delete(self, route: str, *, headers: dict = None) -> Optional[Dict]:
|
||||
"""|coro|
|
||||
|
|
|
@ -470,7 +470,7 @@ class Guild(APIModelBase):
|
|||
|
||||
for channel in data.get("channels", []):
|
||||
channel = _choose_channel_type(channel)
|
||||
self.channels[Snowflake(int(channel.id))] = channel
|
||||
self.channels[str(channel.id)] = channel
|
||||
|
||||
for role in data.get("roles", []):
|
||||
role["guild_id"] = self.id
|
||||
|
|
|
@ -137,20 +137,3 @@ class Color:
|
|||
def default(cls: typing.Type[CT]) -> CT:
|
||||
"""A factory method that returns a :class:`Colour` with a value of ``0``."""
|
||||
return cls(0)
|
||||
|
||||
@classmethod
|
||||
def random(
|
||||
cls: typing.Type[CT],
|
||||
*,
|
||||
seed: typing.Optional[typing.Union[int, str, float, bytes, bytearray]] = None,
|
||||
) -> CT:
|
||||
"""A factory method that returns a :class:`Colour` with a random hue.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
seed: Optional[Union[:class:`int`, :class:`str`,
|
||||
:class:`float`, :class:`bytes`, :class:`bytearray`]]
|
||||
The seed to initialize the RNG with. If ``None`` is passed the default RNG is used.
|
||||
"""
|
||||
rand = random if seed is None else random.Random(seed)
|
||||
return cls.from_hsv(rand.random(), 1, 1)
|
||||
|
|
|
@ -197,19 +197,22 @@ class RESTApp:
|
|||
# ToDo: add file checks
|
||||
|
||||
if embeds is None:
|
||||
embeds = [embed.to_dict()] if embed is not None else []
|
||||
embeds = [embed] if embed is not None else []
|
||||
if files is None:
|
||||
files = [file] if file is not None else []
|
||||
|
||||
payload = {"content": str(content) if content is not None else None}
|
||||
payload = {
|
||||
"content": str(content) if content is not None else None,
|
||||
"embeds": [],
|
||||
}
|
||||
|
||||
for _embed in embeds:
|
||||
if embed.total_length() > 6000:
|
||||
if _embed.total_length() > 6000:
|
||||
raise EmbedFieldError.characters_from_desc(
|
||||
"Embed", embed.total_length(), 6000
|
||||
)
|
||||
payload["embeds"].append(_embed.to_dict())
|
||||
|
||||
payload["embeds"] = embeds
|
||||
payload["tts"] = tts
|
||||
|
||||
# ToDo: add auto allowed_mentions from client
|
||||
|
@ -663,6 +666,43 @@ class RESTApp:
|
|||
headers={"X-Audit-Log-Reason": reason},
|
||||
)
|
||||
|
||||
async def get_global_application_commands(
|
||||
self,
|
||||
application_id: Union[int, str, Snowflake],
|
||||
*,
|
||||
with_localizations: Optional[bool] = False,
|
||||
):
|
||||
"""|coro|
|
||||
|
||||
[**REST API**] Fetch all of the global commands for your application.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
application_id: :class:`~melisa.utils.snowflake.Snowflake`
|
||||
ID of the parent application
|
||||
with_localizations: Optional[bool]
|
||||
Whether to include full localization dictionaries
|
||||
(``name_localizations`` and ``description_localizations``) in
|
||||
the returned objects, instead of the ``name_localized`
|
||||
and ``description_localized fields``. Default ``False``.
|
||||
|
||||
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 arguments
|
||||
"""
|
||||
|
||||
return [
|
||||
ApplicationCommand.from_dict(x)
|
||||
for x in await self._http.get(
|
||||
f"/applications/{application_id}/commands?with_localizations={with_localizations}"
|
||||
)
|
||||
]
|
||||
|
||||
async def create_global_application_command(
|
||||
self,
|
||||
application_id: Union[int, str, Snowflake],
|
||||
|
@ -747,7 +787,7 @@ class RESTApp:
|
|||
data["default_permission"] = default_permission
|
||||
|
||||
return ApplicationCommand.from_dict(
|
||||
await self._http.post(f"/applications/{application_id}/commands", data=data)
|
||||
await self._http.post(f"/applications/{application_id}/commands", json=data)
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue