Passed
Push — main ( 7f94b7...35cc1f )
by
unknown
05:16 queued 03:28
created

pincer.commands.components.button   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 34
dl 0
loc 111
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
    PRIMARY = 1
41
    SECONDARY = 2
42
    SUCCESS = 3
43
    DANGER = 4
44
    LINK = 5
45
46
47
@dataclass(repr=False)
48
class Button(_Component):
49
    """Represents a Discord Button object.
50
    Buttons are interactive components that render on messages.
51
52
    They can be clicked by users,
53
    and send an interaction to your app when clicked.
54
55
    Attributes
56
    ----------
57
    style: :class:`~pincer.commands.components.button.ButtonStyle`
58
        One of button styles. Use :class:`~pincer.commands.components.button.LinkButton`
59
        if you need the ``LINK`` style.
60
    label: APINullable[:class:`str`]
61
        text that appears on the button, max 80 characters
62
    emoji: APINullable[:class:`~pincer.objects.message.emoji.Emoji`]
63
        ``name``, ``id``, and ``animated``
64
    custom_id: APINullable[:class:`str`]
65
        A developer-defined identifier for the button,
66
        max 100 characters
67
    disabled: APINullable[:class:`bool`]
68
        Whether the button is disabled |default| :data:`False`
69
    """
70
    custom_id: APINullable[str]
71
    label: APINullable[str]
72
    style: ButtonStyle
73
74
    emoji: APINullable[Emoji] = MISSING
75
    disabled: APINullable[bool] = False
76
77
    type: int = 2
78
79
    def __post_init__(self):
80
        self.type = 2
81
82
83
@dataclass(repr=False)
84
class LinkButton(_Component):
85
    """
86
    Represents Button message component with a link.
87
88
    Attributes
89
    ----------
90
    label: APINullable[:class:`str`]
91
        text that appears on the button, max 80 characters
92
    emoji: APINullable[:class:`~pincer.objects.message.emoji.Emoji`]
93
        ``name``, ``id``, and ``animated``
94
    custom_id: APINullable[:class:`str`]
95
        A developer-defined identifier for the button,
96
        max 100 characters
97
    url: APINullable[:class:`str`]
98
        A url for link-style buttons
99
    disabled: APINullable[:class:`bool`]
100
        Whether the button is disabled (default `False`)
101
    """
102
103
    label: str
104
    url: str
105
106
    emoji: APINullable[Emoji] = MISSING
107
    disabled: APINullable[bool] = False
108
109
    type: int = 2
110
    style: ButtonStyle = ButtonStyle.LINK
111