1
|
|
|
# Copyright Pincer 2021-Present |
|
|
|
|
2
|
|
|
# Full MIT License can be found in `LICENSE` at the project root. |
3
|
|
|
|
4
|
|
|
from __future__ import annotations |
5
|
|
|
|
6
|
|
|
from copy import copy |
7
|
|
|
from dataclasses import dataclass |
8
|
|
|
from typing import TYPE_CHECKING, Optional |
9
|
|
|
|
10
|
|
|
from ._component import _Component |
11
|
|
|
from ...utils.api_object import APIObject |
12
|
|
|
from ...utils.types import MISSING |
13
|
|
|
|
14
|
|
|
if TYPE_CHECKING: |
15
|
|
|
from typing import List |
16
|
|
|
|
17
|
|
|
from ...objects.message.emoji import Emoji |
18
|
|
|
from ...utils.types import APINullable |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
@dataclass(repr=False) |
22
|
|
|
class SelectOption(APIObject): |
23
|
|
|
"""Represents a Discord Select Option |
24
|
|
|
|
25
|
|
|
Attributes |
26
|
|
|
---------- |
27
|
|
|
label: :class:`str` |
28
|
|
|
The user-facing name of the option, max 100 characters |
29
|
|
|
value: :class:`str` |
30
|
|
|
The def-defined value of the option, max 100 characters |
31
|
|
|
description: APINullable[:class:`str`] |
32
|
|
|
An additional description of the option, max 100 characters |
33
|
|
|
emoji: APINullable[:class:`~pincer.objects.message.emoji.Emoji`] |
34
|
|
|
``id``, ``name``, and ``animated`` |
35
|
|
|
default: APINullable[:class:`bool`] |
36
|
|
|
Will render this option as selected by default |
37
|
|
|
""" |
38
|
|
|
label: str |
39
|
|
|
value: APINullable[str] = MISSING |
40
|
|
|
description: APINullable[str] = MISSING |
41
|
|
|
emoji: APINullable[Emoji] = MISSING |
42
|
|
|
default: APINullable[bool] = MISSING |
43
|
|
|
|
44
|
|
|
def __post_init__(self): |
45
|
|
|
super().__post_init__() |
46
|
|
|
|
47
|
|
|
if self.value is MISSING: |
48
|
|
|
self.value = self.label |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
@dataclass(repr=False) |
52
|
|
|
class SelectMenu(_Component): |
53
|
|
|
"""Represents a Discord Select Menu |
54
|
|
|
|
55
|
|
|
Attributes |
56
|
|
|
---------- |
57
|
|
|
custom_id: :class:`str` |
58
|
|
|
A developer-defined identifier for the button, |
59
|
|
|
max 100 characters |
60
|
|
|
options: List[:class:`~pincer.commands.components.select_menu.SelectOption`] |
61
|
|
|
The choices in the select, max ``25`` |
62
|
|
|
placeholder: APINullable[:class:`str`] |
63
|
|
|
Custom placeholder text if nothing is selected, |
64
|
|
|
max 100 characters |
65
|
|
|
min_values: APINullable[:class:`int`] |
66
|
|
|
The minimum number of items that must be chosen; min ``0``, max ``25`` |
67
|
|
|
|default| ``1`` |
68
|
|
|
max_values: APINullable[:class:`int`] |
69
|
|
|
The maximum number of items that can be chosen; max 25 |
70
|
|
|
|default| ``1`` |
71
|
|
|
disabled: APINullable[:class:`bool`] |
72
|
|
|
Disable the selects |
73
|
|
|
|default| False |
74
|
|
|
""" |
75
|
|
|
custom_id: str |
76
|
|
|
options: Optional[List[SelectOption]] = None |
77
|
|
|
|
78
|
|
|
placeholder: APINullable[str] = MISSING |
79
|
|
|
min_values: APINullable[int] = 1 |
80
|
|
|
max_values: APINullable[int] = 1 |
81
|
|
|
disabled: APINullable[bool] = False |
82
|
|
|
|
83
|
|
|
type: int = 3 |
84
|
|
|
|
85
|
|
|
def __post_init__(self): |
86
|
|
|
self.type = 3 |
87
|
|
|
|
88
|
|
|
def with_options(self, *options: SelectOption) -> SelectMenu: |
89
|
|
|
""" |
90
|
|
|
Sets the ``options`` parameter to \\*options and returns a new |
91
|
|
|
:class:`~pincer.commands.components.select_menu.SelectMenu`. |
92
|
|
|
|
93
|
|
|
\\*options : SelectOption |
94
|
|
|
List of options to set |
95
|
|
|
""" |
96
|
|
|
copied_obj = copy(self) |
97
|
|
|
copied_obj.options = options |
98
|
|
|
return copied_obj |
99
|
|
|
|
100
|
|
|
def with_appended_options(self, *options: SelectOption) -> SelectMenu: |
101
|
|
|
""" |
102
|
|
|
Append \\*options to the ``options`` parameter and returns a new |
103
|
|
|
:class:`~pincer.commands.components.select_menu.SelectMenu`. |
104
|
|
|
|
105
|
|
|
\\*options : SelectOption |
106
|
|
|
List of options to append |
107
|
|
|
""" |
108
|
|
|
copied_obj = copy(self) |
109
|
|
|
copied_obj.options += options |
110
|
|
|
return copied_obj |
111
|
|
|
|