mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-09-22 19:22:01 +03:00
feat(interactions): add ApplicationCommandOption
This commit is contained in:
parent
3ed9362495
commit
bf6c9181ed
3 changed files with 93 additions and 2 deletions
2
.flake8
2
.flake8
|
@ -2,4 +2,4 @@
|
||||||
ignore = D203, H501, F403, F401, C901, W503
|
ignore = D203, H501, F403, F401, C901, W503
|
||||||
exclude = .git, .idea, __pycache__, docs, build, dev, dist, venv, .history, .github, examples
|
exclude = .git, .idea, __pycache__, docs, build, dev, dist, venv, .history, .github, examples
|
||||||
max-complexity = 10
|
max-complexity = 10
|
||||||
max-line-length = 101
|
max-line-length = 120
|
|
@ -6,6 +6,7 @@ from __future__ import annotations
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from typing import Optional, Dict, Union, Any, List
|
from typing import Optional, Dict, Union, Any, List
|
||||||
|
|
||||||
|
from ..guild.channel import ChannelType
|
||||||
from ...utils.conversion import try_enum
|
from ...utils.conversion import try_enum
|
||||||
from ...utils.api_model import APIModelBase
|
from ...utils.api_model import APIModelBase
|
||||||
|
|
||||||
|
@ -76,6 +77,95 @@ class ApplicationCommandOptionTypes(IntEnum):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
|
|
||||||
|
class ApplicationCommandOption(APIModelBase):
|
||||||
|
"""Application Command Option
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
|
||||||
|
Required ``options`` must be listed before optional options.
|
||||||
|
|
||||||
|
Attributes
|
||||||
|
----------
|
||||||
|
type: :class:`~melisa.models.interactions.commands.ApplicationCommandOptionTypes`
|
||||||
|
Type of option
|
||||||
|
name: str
|
||||||
|
1-32 character name
|
||||||
|
name_localizations: Dict[str, str]
|
||||||
|
Localization dictionary for the ``name`` field.
|
||||||
|
Values follow the same restrictions as ``name``
|
||||||
|
description: str
|
||||||
|
1-100 character description
|
||||||
|
description_localizations: Dict[str, str]
|
||||||
|
Localization dictionary for the ``description`` field.
|
||||||
|
Values follow the same restrictions as ``description``
|
||||||
|
required: Optional[bool]
|
||||||
|
If the parameter is required or optional--default false
|
||||||
|
choices: Optional[List[:class:`~melisa.models.interactions.commands.ApplicationCommandOptionChoice`]]
|
||||||
|
Choices for ``STRING``, ``INTEGER``, and ``NUMBER``
|
||||||
|
types for the user to pick from, max 25
|
||||||
|
options: Optional[List[ApplicationCommandOption]]
|
||||||
|
If the option is a subcommand or subcommand group type,
|
||||||
|
these nested options will be the parameters
|
||||||
|
channel_types: Optional[List[:class:`~melisa.models.guild.channel.ChannelType`]]
|
||||||
|
If the option is a channel type,
|
||||||
|
the channels shown will be restricted to these types
|
||||||
|
min_value: Optional[int, float]
|
||||||
|
If the option is an ``int`` or ``float`` type,
|
||||||
|
the minimum value permitted
|
||||||
|
max_value: Optional[int, float]
|
||||||
|
If the option is an ``int`` or ``float`` type,
|
||||||
|
the maximum value permitted
|
||||||
|
autocomplete: Optional[bool]
|
||||||
|
If autocomplete interactions are enabled for this ``str``,
|
||||||
|
``int``, or ``float`` type option
|
||||||
|
"""
|
||||||
|
|
||||||
|
type: ApplicationCommandOptionTypes = None
|
||||||
|
name: str = None
|
||||||
|
name_localizations: Dict[str, str] = None
|
||||||
|
description: str
|
||||||
|
description_localizations: Dict[str, str] = None
|
||||||
|
required: Optional[bool] = False
|
||||||
|
choices: Optional[List[ApplicationCommandOptionChoice]] = None
|
||||||
|
options: Optional[List[ApplicationCommandOption]] = None
|
||||||
|
channel_types: Optional[List[ChannelType]] = None
|
||||||
|
min_value: Optional[int, float] = None
|
||||||
|
max_value: Optional[int, float] = None
|
||||||
|
autocomplete: Optional[bool] = False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data: Dict[str, Any]):
|
||||||
|
"""Generate a ApplicationCommandOption from the given data.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
data: :class:`dict`
|
||||||
|
The dictionary to convert into a ApplicationCommandOption.
|
||||||
|
"""
|
||||||
|
self: ApplicationCommandOption = super().__new__(cls)
|
||||||
|
|
||||||
|
self.type = try_enum(ApplicationCommandOptionTypes, data.get("type", 0))
|
||||||
|
self.name = data.get("name")
|
||||||
|
self.name_localizations = data.get("name_localizations")
|
||||||
|
self.description = data.get("description")
|
||||||
|
self.description_localizations = data.get("description_localizations")
|
||||||
|
self.required = data.get("required", False)
|
||||||
|
self.choices = [
|
||||||
|
try_enum(ApplicationCommandOptionChoice, x) for x in data.get("choices", [])
|
||||||
|
]
|
||||||
|
self.options = [
|
||||||
|
try_enum(ApplicationCommandOption, x) for x in data.get("options", [])
|
||||||
|
]
|
||||||
|
self.channel_types = [
|
||||||
|
try_enum(ChannelType, x) for x in data.get("channel_types", [])
|
||||||
|
]
|
||||||
|
self.min_value = data.get('min_value')
|
||||||
|
self.max_value = data.get('max_value')
|
||||||
|
self.autocomplete = data.get('autocomplete')
|
||||||
|
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
class ApplicationCommandOptionChoice(APIModelBase):
|
class ApplicationCommandOptionChoice(APIModelBase):
|
||||||
"""Application Command Option Choice
|
"""Application Command Option Choice
|
||||||
|
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -7,7 +7,8 @@ HERE = pathlib.Path(__file__).parent
|
||||||
README = (HERE / "README.md").read_text(encoding="utf8")
|
README = (HERE / "README.md").read_text(encoding="utf8")
|
||||||
|
|
||||||
with open(HERE / "melisa/__init__.py") as file:
|
with open(HERE / "melisa/__init__.py") as file:
|
||||||
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', file.read(), re.MULTILINE).group(1)
|
version = re.search(
|
||||||
|
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', file.read(), re.MULTILINE).group(1)
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='melisa',
|
name='melisa',
|
||||||
|
|
Loading…
Reference in a new issue