|
1
|
|
|
# Copyright Pincer 2021-Present |
|
|
|
|
|
|
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
|
|
|
bot_id: APINullable[Snowflake] = MISSING |
|
34
|
|
|
integration_id: APINullable[Snowflake] = MISSING |
|
35
|
|
|
premium_subscriber: APINullable[bool] = MISSING |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
@dataclass(repr=False) |
|
39
|
|
|
class Role(APIObject): |
|
|
|
|
|
|
40
|
|
|
""" |
|
41
|
|
|
Represents a Discord guild/server role. |
|
42
|
|
|
|
|
43
|
|
|
Attributes |
|
44
|
|
|
---------- |
|
45
|
|
|
color: :class:`~pincer.utils.color.Color` |
|
46
|
|
|
Integer representation of hexadecimal color code |
|
47
|
|
|
hoist: :class:`bool` |
|
48
|
|
|
If this role is pinned in the user listing |
|
49
|
|
|
id: :class:`~pincer.utils.snowflake.Snowflake` |
|
50
|
|
|
Role id |
|
51
|
|
|
managed: :class:`bool` |
|
52
|
|
|
Whether this role is managed by an integration |
|
53
|
|
|
mentionable: :class:`bool` |
|
54
|
|
|
Whether this role is mentionable |
|
55
|
|
|
name: :class:`str` |
|
56
|
|
|
Role name |
|
57
|
|
|
permissions: |
|
58
|
|
|
Permission bit set |
|
59
|
|
|
position: :class:`int` |
|
60
|
|
|
Position of this role |
|
61
|
|
|
icon: APINullable[:class:`str`] |
|
62
|
|
|
The role's icon |
|
63
|
|
|
unicode_emoji: APINullable[:class:`str`] |
|
64
|
|
|
The unicode emoji for this role |
|
65
|
|
|
tags: :class:`~pincer.objects.guild.role.RoleTags` |
|
66
|
|
|
The tags this role has |
|
67
|
|
|
""" |
|
68
|
|
|
color: Color |
|
69
|
|
|
hoist: bool |
|
70
|
|
|
id: Snowflake |
|
71
|
|
|
managed: bool |
|
72
|
|
|
mentionable: bool |
|
73
|
|
|
name: str |
|
74
|
|
|
permissions: str |
|
75
|
|
|
position: int |
|
76
|
|
|
|
|
77
|
|
|
icon: APINullable[str] = MISSING |
|
78
|
|
|
unicode_emoji: APINullable[str] = MISSING |
|
79
|
|
|
tags: APINullable[RoleTags] = MISSING |
|
80
|
|
|
|
|
81
|
|
|
def __repr__(self) -> str: |
|
82
|
|
|
return ( |
|
83
|
|
|
f"Role(id={self.id}, name={self.name}, position={self.position}," |
|
84
|
|
|
f"color={self.color=}, permissions={self.permissions})" |
|
85
|
|
|
) |
|
86
|
|
|
|
|
87
|
|
|
def __str__(self) -> str: |
|
88
|
|
|
return self.name |
|
89
|
|
|
|
|
90
|
|
|
@property |
|
91
|
|
|
def mention(self) -> str: |
|
92
|
|
|
""":class:`str`\\: Returns the mention string for this role.""" |
|
93
|
|
|
return f"<@&{self.id}>" |
|
94
|
|
|
|
|
95
|
|
|
# TODO: Implement Caching @Arthurdw |
|
|
|
|
|
|
96
|
|
|
@classmethod |
|
97
|
|
|
async def from_id(cls, client, guild_id: int, role_id: int) -> Role: |
|
|
|
|
|
|
98
|
|
|
roles: list = await client.http.get(f"/guilds/{guild_id}/roles") |
|
99
|
|
|
|
|
100
|
|
|
for role in roles: |
|
101
|
|
|
if int(role['id']) == role_id: |
|
102
|
|
|
return cls.from_dict(role) |
|
103
|
|
|
|