mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-14 12:27:28 +03:00
feat(RESTApi): add create_global_application_command()
This commit is contained in:
parent
53acd07401
commit
06d4853a38
4 changed files with 120 additions and 28 deletions
|
@ -85,9 +85,7 @@ class Gateway:
|
||||||
"intents": self.intents,
|
"intents": self.intents,
|
||||||
"properties": {
|
"properties": {
|
||||||
"$os": sys.platform,
|
"$os": sys.platform,
|
||||||
"$browser": "Discord iOS"
|
"$browser": "Discord iOS" if kwargs.get("mobile") is True else "melisa",
|
||||||
if kwargs.get("mobile") is True
|
|
||||||
else "melisa",
|
|
||||||
"$device": "melisa",
|
"$device": "melisa",
|
||||||
},
|
},
|
||||||
"compress": True,
|
"compress": True,
|
||||||
|
|
|
@ -203,7 +203,7 @@ class HTTPClient:
|
||||||
Optional[:class:`Dict`]
|
Optional[:class:`Dict`]
|
||||||
JSON response from the Discord API.
|
JSON response from the Discord API.
|
||||||
"""
|
"""
|
||||||
return await self.__send("POST", route, data=data, headers=headers)
|
return await self.__send("POST", route, json=data, headers=headers)
|
||||||
|
|
||||||
async def delete(self, route: str, *, headers: dict = None) -> Optional[Dict]:
|
async def delete(self, route: str, *, headers: dict = None) -> Optional[Dict]:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
|
@ -88,7 +88,7 @@ class ApplicationCommand(APIModelBase):
|
||||||
type: Optional[:class:`~melisa.interactions.commands.ApplicationCommandTypes`]
|
type: Optional[:class:`~melisa.interactions.commands.ApplicationCommandTypes`]
|
||||||
Type of command, defaults to ``1``
|
Type of command, defaults to ``1``
|
||||||
application_id: :class:`~melisa.utils.snowflake.Snowflake`
|
application_id: :class:`~melisa.utils.snowflake.Snowflake`
|
||||||
ID of the parent application
|
ID of the parent application
|
||||||
guild_id: Optional[:class:`~melisa.utils.snowflake.Snowflake`]
|
guild_id: Optional[:class:`~melisa.utils.snowflake.Snowflake`]
|
||||||
guild id of the command, if not global
|
guild id of the command, if not global
|
||||||
name: str
|
name: str
|
||||||
|
@ -97,14 +97,14 @@ class ApplicationCommand(APIModelBase):
|
||||||
Localization dictionary for ``name`` field.
|
Localization dictionary for ``name`` field.
|
||||||
Values follow the same restrictions as ``name``
|
Values follow the same restrictions as ``name``
|
||||||
description: str
|
description: str
|
||||||
Description for ``CHAT_INPUT`` commands, 1-100 characters.
|
Description for ``CHAT_INPUT`` commands, 1-100 characters.
|
||||||
Empty string for ``USER`` and ``MESSAGE`` commands
|
Empty string for ``USER`` and ``MESSAGE`` commands
|
||||||
description_localizations: Optional[Dict[str, str]]
|
description_localizations: Optional[Dict[str, str]]
|
||||||
Localization dictionary for ``description`` field.
|
Localization dictionary for ``description`` field.
|
||||||
Values follow the same restrictions as ``description``
|
Values follow the same restrictions as ``description``
|
||||||
options: Optional[List[:class:`~melisa.models.interactions.commands.ApplicationCommandOption`]]
|
options: Optional[List[:class:`~melisa.models.interactions.commands.ApplicationCommandOption`]]
|
||||||
Parameters for the command, max of 25.
|
Parameters for the command, max of 25.
|
||||||
Only available for ``CHAT_INPUT`` command type.
|
Only available for ``CHAT_INPUT`` command type.
|
||||||
default_member_permissions: Optional[str]
|
default_member_permissions: Optional[str]
|
||||||
Set of permissions represented as a bit set
|
Set of permissions represented as a bit set
|
||||||
dm_permission: Optional[bool]
|
dm_permission: Optional[bool]
|
||||||
|
@ -112,12 +112,13 @@ class ApplicationCommand(APIModelBase):
|
||||||
in DMs with the app, only for globally-scoped commands.
|
in DMs with the app, only for globally-scoped commands.
|
||||||
By default, commands are visible.
|
By default, commands are visible.
|
||||||
default_permission: Optional[bool]
|
default_permission: Optional[bool]
|
||||||
Not recommended for use as field will soon be deprecated.
|
Not recommended for use as field will soon be deprecated.
|
||||||
Indicates whether the command is enabled by default
|
Indicates whether the command is enabled by default
|
||||||
when the app is added to a guild, defaults to true
|
when the app is added to a guild, defaults to true
|
||||||
version: :class:`~melisa.utils.snowflake.Snowflake`
|
version: :class:`~melisa.utils.snowflake.Snowflake`
|
||||||
Autoincrementing version identifier updated during substantial record changes
|
Autoincrementing version identifier updated during substantial record changes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# ToDo: Better Permissions
|
# ToDo: Better Permissions
|
||||||
|
|
||||||
id: Snowflake = None
|
id: Snowflake = None
|
||||||
|
@ -145,19 +146,23 @@ class ApplicationCommand(APIModelBase):
|
||||||
"""
|
"""
|
||||||
self: ApplicationCommand = super().__new__(cls)
|
self: ApplicationCommand = super().__new__(cls)
|
||||||
|
|
||||||
self.id = Snowflake(data.get('id', 0))
|
self.id = Snowflake(data.get("id", 0))
|
||||||
self.type = data.get('type', 1)
|
self.type = data.get("type", 1)
|
||||||
self.application_id = Snowflake(data.get('application_id'))
|
self.application_id = Snowflake(data.get("application_id"))
|
||||||
self.guild_id = Snowflake(data['guild_id']) if data.get('guild_id') is not None else None
|
self.guild_id = (
|
||||||
self.name = data.get('name')
|
Snowflake(data["guild_id"]) if data.get("guild_id") is not None else None
|
||||||
self.name_localizations = data.get('name_localizations')
|
)
|
||||||
self.description = data.get('description')
|
self.name = data.get("name")
|
||||||
self.description_localizations = data.get('description_localizations')
|
self.name_localizations = data.get("name_localizations")
|
||||||
self.options = [ApplicationCommandOption.from_dict(x) for x in data.get('options')]
|
self.description = data.get("description")
|
||||||
self.default_member_permissions = data.get('default_member_permissions')
|
self.description_localizations = data.get("description_localizations")
|
||||||
self.dm_permission = data.get('dm_permission', True)
|
self.options = [
|
||||||
self.default_permission = data.get('default_permission', True)
|
ApplicationCommandOption.from_dict(x) for x in data.get("options", [])
|
||||||
self.version = Snowflake(data.get('version', 0))
|
]
|
||||||
|
self.default_member_permissions = data.get("default_member_permissions")
|
||||||
|
self.dm_permission = data.get("dm_permission", True)
|
||||||
|
self.default_permission = data.get("default_permission", True)
|
||||||
|
self.version = Snowflake(data.get("version", 0))
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@ -244,9 +249,9 @@ class ApplicationCommandOption(APIModelBase):
|
||||||
self.channel_types = [
|
self.channel_types = [
|
||||||
try_enum(ChannelType, x) for x in data.get("channel_types", [])
|
try_enum(ChannelType, x) for x in data.get("channel_types", [])
|
||||||
]
|
]
|
||||||
self.min_value = data.get('min_value')
|
self.min_value = data.get("min_value")
|
||||||
self.max_value = data.get('max_value')
|
self.max_value = data.get("max_value")
|
||||||
self.autocomplete = data.get('autocomplete')
|
self.autocomplete = data.get("autocomplete")
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ from typing import Union, Optional, List, Dict, Any, AsyncIterator
|
||||||
|
|
||||||
from aiohttp import FormData
|
from aiohttp import FormData
|
||||||
|
|
||||||
|
from .models.interactions import ApplicationCommandTypes
|
||||||
|
from .models.interactions.commands import ApplicationCommandOption, ApplicationCommand
|
||||||
from .models.message import Embed, File, AllowedMentions, Message
|
from .models.message import Embed, File, AllowedMentions, Message
|
||||||
from .exceptions import EmbedFieldError
|
from .exceptions import EmbedFieldError
|
||||||
from .core.http import HTTPClient
|
from .core.http import HTTPClient
|
||||||
|
@ -661,6 +663,93 @@ class RESTApp:
|
||||||
headers={"X-Audit-Log-Reason": reason},
|
headers={"X-Audit-Log-Reason": reason},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def create_global_application_command(
|
||||||
|
self,
|
||||||
|
application_id: Union[int, str, Snowflake],
|
||||||
|
command_type: ApplicationCommandTypes,
|
||||||
|
name: str,
|
||||||
|
description: str = None,
|
||||||
|
*,
|
||||||
|
name_localizations: Optional[Dict[str, str]] = None,
|
||||||
|
description_localizations: Optional[Dict[str, str]] = None,
|
||||||
|
options: Optional[List[ApplicationCommandOption]] = None,
|
||||||
|
default_member_permissions: Optional[str] = None,
|
||||||
|
dm_permission: Optional[bool] = None,
|
||||||
|
default_permission: Optional[bool] = None,
|
||||||
|
):
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
[**REST API**] Create a new global command.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
application_id: :class:`~melisa.utils.snowflake.Snowflake`
|
||||||
|
ID of the parent application
|
||||||
|
command_type: Optional[:class:`~melisa.interactions.commands.ApplicationCommandTypes`]
|
||||||
|
Type of command, defaults to ``1``
|
||||||
|
name: str
|
||||||
|
Name of command, 1-32 characters
|
||||||
|
description: str
|
||||||
|
Description for ``CHAT_INPUT`` commands, 1-100 characters.
|
||||||
|
Empty string for ``USER`` and ``MESSAGE`` commands
|
||||||
|
name_localizations: Optional[Dict[str, str]]
|
||||||
|
Localization dictionary for ``name`` field.
|
||||||
|
Values follow the same restrictions as ``name``
|
||||||
|
description_localizations: Optional[Dict[str, str]]
|
||||||
|
Localization dictionary for ``description`` field.
|
||||||
|
Values follow the same restrictions as ``description``
|
||||||
|
options: Optional[List[:class:`~melisa.models.interactions.commands.ApplicationCommandOption`]]
|
||||||
|
Parameters for the command, max of 25.
|
||||||
|
Only available for ``CHAT_INPUT`` command type.
|
||||||
|
default_member_permissions: Optional[str]
|
||||||
|
Set of permissions represented as a bit set
|
||||||
|
dm_permission: Optional[bool]
|
||||||
|
Indicates whether the command is available
|
||||||
|
in DMs with the app, only for globally-scoped commands.
|
||||||
|
By default, commands are visible.
|
||||||
|
default_permission: Optional[bool]
|
||||||
|
Not recommended for use as field will soon be deprecated.
|
||||||
|
Indicates whether the command is enabled by default
|
||||||
|
when the app is added to a guild, defaults to true
|
||||||
|
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"name": name,
|
||||||
|
"description": description,
|
||||||
|
"type": int(command_type),
|
||||||
|
}
|
||||||
|
|
||||||
|
if name_localizations is not None:
|
||||||
|
data["name_localizations"] = name_localizations
|
||||||
|
|
||||||
|
if description_localizations is not None:
|
||||||
|
data["description_localizations"] = description_localizations
|
||||||
|
|
||||||
|
if default_member_permissions is not None:
|
||||||
|
data["default_member_permissions"] = default_member_permissions
|
||||||
|
|
||||||
|
if options is not None:
|
||||||
|
data["options"] = [x.to_dict() for x in options]
|
||||||
|
|
||||||
|
if dm_permission is not None:
|
||||||
|
data["dm_permission"] = dm_permission
|
||||||
|
|
||||||
|
if default_permission is not None:
|
||||||
|
data["default_permission"] = default_permission
|
||||||
|
|
||||||
|
return ApplicationCommand.from_dict(
|
||||||
|
await self._http.post(f"/applications/{application_id}/commands", data=data)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CDNBuilder:
|
class CDNBuilder:
|
||||||
"""Can be used to build images
|
"""Can be used to build images
|
||||||
|
|
Loading…
Reference in a new issue