Passed
Push — main ( f2e2cb...8ba93a )
by
unknown
02:33
created

pincer.objects.guild.role.Role.mention()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 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 typing import TYPE_CHECKING
8
9
from ...utils.api_object import APIObject
10
from ...utils.types import MISSING
11
12
if TYPE_CHECKING:
13
    from ...utils import APINullable, Snowflake
14
15
16
@dataclass
17
class RoleTags(APIObject):
18
    """
19
    Special tags/flags which have been defined for a role.
20
21
    :bot_id:
22
        The id of the bot this role belongs to.
23
        (the role got created by adding the bot with this id)
24
25
    :integration_id:
26
        The id of the integration this role belongs to.
27
        (the role got created by adding an integration with this id)
28
29
    :premium_subscriber:
30
        Whether this is the guild's premium subscriber role or not.
31
    """
32
    bot_id: APINullable[Snowflake] = MISSING
0 ignored issues
show
introduced by
The variable APINullable does not seem to be defined in case TYPE_CHECKING on line 12 is False. Are you sure this can never be the case?
Loading history...
introduced by
The variable Snowflake does not seem to be defined in case TYPE_CHECKING on line 12 is False. Are you sure this can never be the case?
Loading history...
33
    integration_id: APINullable[Snowflake] = MISSING
34
    premium_subscriber: APINullable[bool] = MISSING
35
36
37
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (11/7)
Loading history...
38
class Role(APIObject):
39
    """
40
    Represents a Discord guild/server role.
41
42
    :param color:
43
        integer representation of hexadecimal color code
44
45
    :param hoist:
46
        if this role is pinned in the user listing
47
48
    :param id:
49
        role id
50
51
    :param managed:
52
        whether this role is managed by an integration
53
54
    :param mentionable:
55
        whether this role is mentionable
56
57
    :param name:
58
        role name
59
60
    :param permissions:
61
        permission bit set
62
63
    :param position:
64
        position of this role
65
66
    :param tags:
67
        the tags this role has
68
69
    :param mention:
70
        structures a string to mention the role
71
    """
72
73
    color: int
74
    hoist: bool
75
    id: Snowflake
0 ignored issues
show
introduced by
The variable Snowflake does not seem to be defined in case TYPE_CHECKING on line 12 is False. Are you sure this can never be the case?
Loading history...
76
    managed: bool
77
    mentionable: bool
78
    name: str
79
    permissions: str
80
    position: int
81
82
    icon: APINullable[str] = MISSING
0 ignored issues
show
introduced by
The variable APINullable does not seem to be defined in case TYPE_CHECKING on line 12 is False. Are you sure this can never be the case?
Loading history...
83
    unicode_emoji: APINullable[str] = MISSING
84
    tags: APINullable[RoleTags] = MISSING
85
86
    @property
87
    def mention(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
88
        return f"<@&{self.id}>"
89
90
    # TODO: Implement Caching
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
91
    @classmethod
92
    async def from_id(cls, client, guild_id: int, role_id: int) -> Role:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
93
        roles: list = await client.http.get(f"/guilds/{guild_id}/roles")
94
95
        for role in roles:
96
            if int(role['id']) == role_id:
97
                return cls.from_dict(role)
98