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 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 |
|
|
|
|
33
|
|
|
integration_id: APINullable[Snowflake] = MISSING |
34
|
|
|
premium_subscriber: APINullable[bool] = MISSING |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
@dataclass |
|
|
|
|
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 |
|
|
|
|
76
|
|
|
managed: bool |
77
|
|
|
mentionable: bool |
78
|
|
|
name: str |
79
|
|
|
permissions: str |
80
|
|
|
position: int |
81
|
|
|
|
82
|
|
|
icon: APINullable[str] = MISSING |
|
|
|
|
83
|
|
|
unicode_emoji: APINullable[str] = MISSING |
84
|
|
|
tags: APINullable[RoleTags] = MISSING |
85
|
|
|
|
86
|
|
|
@property |
87
|
|
|
def mention(self): |
|
|
|
|
88
|
|
|
return f"<@&{self.id}>" |
89
|
|
|
|
90
|
|
|
# TODO: Implement Caching |
|
|
|
|
91
|
|
|
@classmethod |
92
|
|
|
async def from_id(cls, client, guild_id: int, role_id: int) -> Role: |
|
|
|
|
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
|
|
|
|