Completed
Push — main ( 873c6e...b147bc )
by
unknown
28s queued 12s
created

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

Complexity

Conditions 3

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 3
nop 4
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
70
    color: int
71
    hoist: bool
72
    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...
73
    managed: bool
74
    mentionable: bool
75
    name: str
76
    permissions: str
77
    position: int
78
79
    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...
80
    unicode_emoji: APINullable[str] = MISSING
81
    tags: APINullable[RoleTags] = MISSING
82
83
    # TODO: Implement Caching
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
84
    @classmethod
85
    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...
86
        roles: list = await client.http.get(f"/guilds/{guild_id}/roles")
87
88
        for role in roles:
89
            if int(role['id']) == role_id:
90
                return cls.from_dict(role)
91