pincer.objects.message.component   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 31
dl 0
loc 91
rs 10
c 0
b 0
f 0
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from __future__ import annotations
5
6
from dataclasses import dataclass
7
from enum import IntEnum
8
from typing import TYPE_CHECKING
9
10
from ...utils.api_object import APIObject
11
from ...utils.types import MISSING
12
13
if TYPE_CHECKING:
14
    from typing import List
15
16
    from ...commands.select_menu import SelectOption
0 ignored issues
show
introduced by
Unable to import 'pincer.commands.select_menu'
Loading history...
17
    from ...commands.button import ButtonStyle
0 ignored issues
show
introduced by
Unable to import 'pincer.commands.button'
Loading history...
18
    from ..message.emoji import Emoji
19
    from ...utils.types import APINullable
20
21
22
class ComponentType(IntEnum):
23
    """
24
    Represents a message component type
25
26
    Attributes
27
    ----------
28
    ACTION_ROW : int
29
        A row of buttons or select menus
30
    BUTTON : int
31
        A button that a user can click. Must be inside an action row.
32
    SELECT_MENU : int
33
        A select menu. Must be inside an action row.
34
    """
35
36
    ACTION_ROW = 1
37
    BUTTON = 2
38
    SELECT_MENU = 3
39
40
41
@dataclass(repr=False)
42
class MessageComponent(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (12/7)
Loading history...
43
    """Represents a Discord Message Component object
44
45
    Attributes
46
    ----------
47
    type: :class:`int`
48
        Component type
49
    options: List[:class:`~pincer.objects.app.select_menu.SelectOption`]
50
        The choices in the select, max 25
51
    custom_id: APINullable[:class:`str`]
52
        A developer-defined identifier for the component,
53
        max 100 characters
54
    disabled: APINullable[:class:`bool`]
55
        Whether the component is disabled,
56
        defaults to `False`
57
    style: APINullable[:class:`~pincer.objects.message.button.ButtonStyle`]
58
        One of button styles
59
    label: APINullable[:class:`str`]
60
        Text that appears on the button, max 80 characters
61
    emoji: APINullable[:class:`~pincer.objects.message.emoji.Emoji`]
62
        ``name``, ``id``, and ``animated``
63
    url: APINullable[:class:`str`]
64
        A url for link-style buttons
65
    placeholder: APINullable[:class:`str`]
66
        Custom placeholder text if nothing is selected,
67
        max 100 characters
68
    min_values: APINullable[:class:`int`]
69
        The minimum number of items that must be chosen;
70
        |default| ``1``, min ``0``, max ``25``
71
    max_values: APINullable[:class:`int`]
72
        The maximum number of items that can be chosen;
73
        |default| ``1``, max ``25``
74
    components: APINullable[List[:class:`~pincer.objects.message.component.MessageComponent`]]
75
        A list of child components
76
    """  # noqa: E501
77
78
    type: int
79
80
    options: List[SelectOption] = MISSING
81
    custom_id: APINullable[str] = MISSING
82
    disabled: APINullable[bool] = False
83
    style: APINullable[ButtonStyle] = MISSING
84
    label: APINullable[str] = MISSING
85
    emoji: APINullable[Emoji] = MISSING
86
    url: APINullable[str] = MISSING
87
    placeholder: APINullable[str] = MISSING
88
    min_values: APINullable[int] = 1
89
    max_values: APINullable[int] = 1
90
    components: APINullable[List[MessageComponent]] = MISSING
91