Completed
Push — main ( b12314...8ccbcd )
by Yohann
17s queued 14s
created

pincer.objects.button   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 22
dl 0
loc 101
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# MIT License
3
#
4
# Copyright (c) 2021 Pincer
5
#
6
# Permission is hereby granted, free of charge, to any person obtaining
7
# a copy of this software and associated documentation files
8
# (the "Software"), to deal in the Software without restriction,
9
# including without limitation the rights to use, copy, modify, merge,
10
# publish, distribute, sublicense, and/or sell copies of the Software,
11
# and to permit persons to whom the Software is furnished to do so,
12
# subject to the following conditions:
13
#
14
# The above copyright notice and this permission notice shall be
15
# included in all copies or substantial portions of the Software.
16
#
17
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25
from __future__ import annotations
26
from dataclasses import dataclass
27
from enum import Enum
28
29
from pincer.utils.api_object import APIObject
30
from pincer.objects.emoji import Emoji
31
from pincer.utils.constants import MISSING, APINullable
32
33
34
class ButtonStyle(Enum):
35
    """
36
    Buttons come in a variety of styles to convey different types of actions.
37
    These styles also define what fields are valid for a button.
38
39
    Primary:
40
        - color: blurple
41
        - required_field: custom_id
42
    Secondary:
43
        - color: gray
44
        - required_field: custom_id
45
    Success:
46
        - color: green
47
        - required_field: custom_id
48
    Danger:
49
        - color: red
50
        - required_field: custom_id
51
    Link:
52
        - color: gray, navigates to a URL
53
        - required_field: url
54
    """
55
    PRIMARY = 1
56
    SECONDARY = 2
57
    SUCCESS = 3
58
    DANGER = 4
59
    LINK = 5
60
61
62
@dataclass
63
class Button(APIObject):
64
    """
65
    Represents a Discord Button object.
66
    Buttons are interactive components that render on messages.
67
68
    They can be clicked by users,
69
    and send an interaction to your app when clicked.
70
71
    :param type:
72
        `2` for a button
73
74
    :param style:
75
        one of button styles
76
77
    :param label:
78
        text that appears on the button, max 80 characters
79
80
    :param emoji:
81
        `name`, `id`, and `animated`
82
83
    :param custom_id:
84
        a developer-defined identifier for the button,
85
        max 100 characters
86
87
    :param url:
88
        a url for link-style buttons
89
90
    :param disabled:
91
        whether the button is disabled (default `False`)
92
    """
93
    type: int
94
    style: ButtonStyle
95
96
    label: APINullable[str] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
97
    emoji: APINullable[Emoji] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
98
    custom_id: APINullable[str] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
99
    url: APINullable[str] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
100
    disabled: APINullable[bool] = False
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
101