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

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 4
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.color import Color
14
    from ...utils.types import APINullable
15
    from ...utils.snowflake import Snowflake
16
17
18
@dataclass(repr=False)
19
class RoleTags(APIObject):
20
    """Special tags/flags which have been defined for a role.
21
22
    Attributes
23
    ----------
24
    bot_id: APINullable[:class:`~pincer.utils.snowflake.Snowflake`]
25
        The id of the bot this role belongs to.
26
        (the role got created by adding the bot with this id)
27
    integration_id: APINullable[:class:`~pincer.utils.snowflake.Snowflake`]
28
        The id of the integration this role belongs to.
29
        (the role got created by adding an integration with this id)
30
    premium_subscriber: APINullable[:class:`bool`]
31
        Whether this is the guild's premium subscriber role or not.
32
    """
33
34
    bot_id: APINullable[Snowflake] = MISSING
35
    integration_id: APINullable[Snowflake] = MISSING
36
    premium_subscriber: APINullable[bool] = MISSING
37
38
39
@dataclass(repr=False)
40
class Role(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (11/7)
Loading history...
41
    """
42
    Represents a Discord guild/server role.
43
44
    Attributes
45
    ----------
46
    color: :class:`~pincer.utils.color.Color`
47
        Integer representation of hexadecimal color code
48
    hoist: :class:`bool`
49
        If this role is pinned in the user listing
50
    id: :class:`~pincer.utils.snowflake.Snowflake`
51
        Role id
52
    managed: :class:`bool`
53
        Whether this role is managed by an integration
54
    mentionable: :class:`bool`
55
        Whether this role is mentionable
56
    name: :class:`str`
57
        Role name
58
    permissions:
59
        Permission bit set
60
    position: :class:`int`
61
        Position of this role
62
    icon: APINullable[:class:`str`]
63
        The role's icon
64
    unicode_emoji: APINullable[:class:`str`]
65
        The unicode emoji for this role
66
    tags: :class:`~pincer.objects.guild.role.RoleTags`
67
        The tags this role has
68
    """
69
70
    color: Color
71
    hoist: bool
72
    id: Snowflake
73
    managed: bool
74
    mentionable: bool
75
    name: str
76
    permissions: str
77
    position: int
78
79
    icon: APINullable[str] = MISSING
80
    unicode_emoji: APINullable[str] = MISSING
81
    tags: APINullable[RoleTags] = MISSING
82
83
    def __repr__(self) -> str:
84
        return (
85
            f"Role(id={self.id}, name={self.name}, position={self.position},"
86
            f"color={self.color=}, permissions={self.permissions})"
87
        )
88
89
    def __str__(self) -> str:
90
        return self.name
91
92
    @property
93
    def mention(self) -> str:
94
        """:class:`str`\\: Returns the mention string for this role."""
95
        return f"<@&{self.id}>"
96
97
    # TODO: Implement Caching @Arthurdw
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
98
    @classmethod
99
    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...
100
        roles: list = await client.http.get(f"/guilds/{guild_id}/roles")
101
102
        for role in roles:
103
            if int(role["id"]) == role_id:
104
                return cls.from_dict(role)
105