pincer.commands.components.button   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 34
dl 0
loc 113
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Button.__post_init__() 0 2 1
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 ._component import _Component
11
from ...utils.types import MISSING
12
13
if TYPE_CHECKING:
14
    from ...utils.types import APINullable
15
    from ...objects.message.emoji import Emoji
16
17
18
class ButtonStyle(IntEnum):
19
    """Buttons come in a variety of styles to convey different types of actions.
20
    These styles also define what fields are valid for a button.
21
22
    Attributes
23
    ----------
24
    Primary:
25
        - color: blurple
26
        - required_field: custom_id
27
    Secondary:
28
        - color: gray
29
        - required_field: custom_id
30
    Success:
31
        - color: green
32
        - required_field: custom_id
33
    Danger:
34
        - color: red
35
        - required_field: custom_id
36
    Link:
37
        - color: gray, navigates to a URL
38
        - required_field: url
39
    """
40
41
    PRIMARY = 1
42
    SECONDARY = 2
43
    SUCCESS = 3
44
    DANGER = 4
45
    LINK = 5
46
47
48
@dataclass(repr=False)
49
class Button(_Component):
50
    """Represents a Discord Button object.
51
    Buttons are interactive components that render on messages.
52
53
    They can be clicked by users,
54
    and send an interaction to your app when clicked.
55
56
    Attributes
57
    ----------
58
    style: :class:`~pincer.commands.components.button.ButtonStyle`
59
        One of button styles. Use :class:`~pincer.commands.components.button.LinkButton`
60
        if you need the ``LINK`` style.
61
    label: APINullable[:class:`str`]
62
        text that appears on the button, max 80 characters
63
    emoji: APINullable[:class:`~pincer.objects.message.emoji.Emoji`]
64
        ``name``, ``id``, and ``animated``
65
    custom_id: APINullable[:class:`str`]
66
        A developer-defined identifier for the button,
67
        max 100 characters
68
    disabled: APINullable[:class:`bool`]
69
        Whether the button is disabled |default| :data:`False`
70
    """
71
72
    custom_id: APINullable[str]
73
    label: APINullable[str]
74
    style: ButtonStyle
75
76
    emoji: APINullable[Emoji] = MISSING
77
    disabled: APINullable[bool] = False
78
79
    type: int = 2
80
81
    def __post_init__(self):
82
        self.type = 2
83
84
85
@dataclass(repr=False)
86
class LinkButton(_Component):
87
    """
88
    Represents Button message component with a link.
89
90
    Attributes
91
    ----------
92
    label: APINullable[:class:`str`]
93
        text that appears on the button, max 80 characters
94
    emoji: APINullable[:class:`~pincer.objects.message.emoji.Emoji`]
95
        ``name``, ``id``, and ``animated``
96
    custom_id: APINullable[:class:`str`]
97
        A developer-defined identifier for the button,
98
        max 100 characters
99
    url: APINullable[:class:`str`]
100
        A url for link-style buttons
101
    disabled: APINullable[:class:`bool`]
102
        Whether the button is disabled (default `False`)
103
    """
104
105
    label: str
106
    url: str
107
108
    emoji: APINullable[Emoji] = MISSING
109
    disabled: APINullable[bool] = False
110
111
    type: int = 2
112
    style: ButtonStyle = ButtonStyle.LINK
113