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 enum import IntEnum |
8
|
|
|
from typing import TYPE_CHECKING |
9
|
|
|
|
10
|
|
|
from ...utils.api_object import APIObject |
11
|
|
|
from ...utils.conversion import remove_none |
12
|
|
|
from ...utils.types import MISSING |
13
|
|
|
|
14
|
|
|
if TYPE_CHECKING: |
15
|
|
|
from typing import List, Optional |
16
|
|
|
|
17
|
|
|
from ..user import User |
18
|
|
|
from ...utils import APINullable, Snowflake |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
class StickerType(IntEnum): |
22
|
|
|
"""Displays from where the sticker comes from. |
23
|
|
|
|
24
|
|
|
Attributes |
25
|
|
|
---------- |
26
|
|
|
STANDARD: |
27
|
|
|
Sticker is included in the default Discord sticker pack. |
28
|
|
|
GUILD: |
29
|
|
|
Sticker is a custom sticker from a discord server. |
30
|
|
|
""" |
31
|
|
|
STANDARD = 1 |
32
|
|
|
GUILD = 2 |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
class StickerFormatType(IntEnum): |
36
|
|
|
"""The type of the sticker. |
37
|
|
|
|
38
|
|
|
Attributes |
39
|
|
|
---------- |
40
|
|
|
PNG: |
41
|
|
|
Sticker is of PNG format. |
42
|
|
|
APNG: |
43
|
|
|
Sticker is animated with APNG format. |
44
|
|
|
LOTTIE: |
45
|
|
|
Sticker is animated with with LOTTIE format. (vector based) |
46
|
|
|
""" |
47
|
|
|
PNG = 1 |
48
|
|
|
APNG = 2 |
49
|
|
|
LOTTIE = 3 |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
@dataclass(repr=False) |
53
|
|
|
class Sticker(APIObject): |
|
|
|
|
54
|
|
|
"""Represents a Discord sticker. |
55
|
|
|
|
56
|
|
|
Attributes |
57
|
|
|
---------- |
58
|
|
|
description: Optional[:class:`str`] |
59
|
|
|
description of the sticker |
60
|
|
|
format_type: :class:`~pincer.objects.message.sticker.StickerFormatType` |
61
|
|
|
type of sticker format |
62
|
|
|
id: :class:`~pincer.utils.snowflake.Snowflake` |
63
|
|
|
id of the sticker |
64
|
|
|
name: :class:`str` |
65
|
|
|
name of the sticker |
66
|
|
|
tags: :class:`str` |
67
|
|
|
for guild stickers, the Discord name of a unicode emoji |
68
|
|
|
representing the sticker's expression. For standard stickers, |
69
|
|
|
a comma-separated list of related expressions. |
70
|
|
|
type: :class:`~pincer.objects.message.sticker.StickerType` |
71
|
|
|
type of sticker |
72
|
|
|
available: APINullable[:class:`bool`] |
73
|
|
|
whether this guild sticker can be used, |
74
|
|
|
may be false due to loss of Server Boosts |
75
|
|
|
guild_id: APINullable[:class:`~pincer.utils.snowflake.Snowflake`] |
76
|
|
|
id of the guild that owns this sticker |
77
|
|
|
pack_id: APINullable[:class:`~pincer.utils.snowflake.Snowflake`] |
78
|
|
|
for standard stickers, id of the pack the sticker is from |
79
|
|
|
sort_value: APINullable[:class:`int`] |
80
|
|
|
the standard sticker's sort order within its pack |
81
|
|
|
user: APINullable[:class:`~pincer.objects.user.user.User`] |
82
|
|
|
the user that uploaded the guild sticker |
83
|
|
|
""" |
84
|
|
|
|
85
|
|
|
description: Optional[str] |
86
|
|
|
format_type: StickerFormatType |
87
|
|
|
id: Snowflake |
88
|
|
|
name: str |
89
|
|
|
tags: str |
90
|
|
|
type: StickerType |
91
|
|
|
|
92
|
|
|
available: APINullable[bool] = MISSING |
93
|
|
|
guild_id: APINullable[Snowflake] = MISSING |
94
|
|
|
pack_id: APINullable[Snowflake] = MISSING |
95
|
|
|
sort_value: APINullable[int] = MISSING |
96
|
|
|
user: APINullable[User] = MISSING |
97
|
|
|
|
98
|
|
|
@classmethod |
99
|
|
|
async def from_id(cls, _id: Snowflake) -> Sticker: |
100
|
|
|
"""|coro| |
101
|
|
|
Returns a sticker object for the given sticker ID. |
102
|
|
|
|
103
|
|
|
Parameters |
104
|
|
|
---------- |
105
|
|
|
_id : Snowflake |
106
|
|
|
id of the sticker |
107
|
|
|
|
108
|
|
|
Returns |
109
|
|
|
------- |
110
|
|
|
:class:`~pincer.objects.message.sticker.Sticker` |
111
|
|
|
sticker object of the given ID |
112
|
|
|
""" |
113
|
|
|
sticker = await cls._http.get(f"stickers/{_id}") |
|
|
|
|
114
|
|
|
return cls.from_dict(sticker) |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
async def modify( |
118
|
|
|
self, |
119
|
|
|
name: Optional[str] = None, |
120
|
|
|
description: Optional[str] = None, |
121
|
|
|
tags: Optional[str] = None, |
122
|
|
|
reason: Optional[str] = None |
123
|
|
|
) -> Sticker: |
124
|
|
|
"""|coro| |
125
|
|
|
Modify the given sticker. |
126
|
|
|
Requires the ``MANAGE_EMOJIS_AND_STICKERS permission.`` |
127
|
|
|
|
128
|
|
|
Parameters |
129
|
|
|
---------- |
130
|
|
|
name : Optional[:class:`str`] |default| :data:`None` |
131
|
|
|
name of the sticker (2-30 characters) |
132
|
|
|
description : Optional[:class:`str`] |default| :data:`None` |
133
|
|
|
description of the sticker (2-100 characters) |
134
|
|
|
tags : Optional[:class:`str`] |default| :data:`None` |
135
|
|
|
autocomplete/suggestion tags for the sticker (max 200 characters) |
136
|
|
|
reason : Optional[:class:`str`] |
137
|
|
|
reason for modifying the sticker |
138
|
|
|
|
139
|
|
|
Returns |
140
|
|
|
------- |
141
|
|
|
:class:`~pincer.objects.message.sticker.Sticker` |
142
|
|
|
the modified sticker |
143
|
|
|
""" |
144
|
|
|
sticker = self._http.patch( |
145
|
|
|
f"guilds/{self.guild_id}/stickers/{self.id}", |
146
|
|
|
data=remove_none( |
147
|
|
|
{"name": name, "description": description, "tags": tags} |
148
|
|
|
), |
149
|
|
|
headers=remove_none({"X-Audit-Log-Reason": reason}) |
150
|
|
|
) |
151
|
|
|
|
152
|
|
|
return Sticker.from_dict(sticker) |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
|
156
|
|
|
|
157
|
|
|
@dataclass(repr=False) |
158
|
|
|
class StickerItem(APIObject): |
159
|
|
|
"""Represents the smallest amount of data required to render a sticker. |
160
|
|
|
A partial sticker object. |
161
|
|
|
|
162
|
|
|
Attributes |
163
|
|
|
---------- |
164
|
|
|
id: :class:`~pincer.utils.snowflake.Snowflake` |
165
|
|
|
Id of the sticker |
166
|
|
|
name: :class:`str` |
167
|
|
|
Name of the sticker |
168
|
|
|
format_type: :class:`~pincer.objects.message.sticker.StickerFormatType` |
169
|
|
|
Type of sticker format |
170
|
|
|
""" |
171
|
|
|
|
172
|
|
|
id: Snowflake |
173
|
|
|
name: str |
174
|
|
|
format_type: StickerFormatType |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
@dataclass(repr=False) |
178
|
|
|
class StickerPack(APIObject): |
179
|
|
|
"""Represents a pack of standard stickers. |
180
|
|
|
|
181
|
|
|
Attributes |
182
|
|
|
---------- |
183
|
|
|
id: :class:`~pincer.utils.snowflake.Snowflake` |
184
|
|
|
Id of the sticker pack |
185
|
|
|
stickers: List[:class:`~pincer.objects.message.sticker.Sticker`] |
186
|
|
|
The stickers in the pack |
187
|
|
|
name: :class:`str` |
188
|
|
|
Name of the sticker pack |
189
|
|
|
sku_id: :class:`~pincer.utils.snowflake.Snowflake` |
190
|
|
|
Id of the pack's SKU |
191
|
|
|
description: :class:`str` |
192
|
|
|
Description of the sticker pack |
193
|
|
|
cover_sticker_id: APINullable[:class:`~pincer.utils.snowflake.Snowflake`] |
194
|
|
|
Id of a sticker in the pack which is shown as the pack's icon |
195
|
|
|
banner_asset_id: APINullable[:class:`~pincer.utils.snowflake.Snowflake`] |
196
|
|
|
Id of the sticker pack's banner image |
197
|
|
|
""" |
198
|
|
|
|
199
|
|
|
id: Snowflake |
200
|
|
|
stickers: List[Sticker] |
201
|
|
|
name: str |
202
|
|
|
sku_id: Snowflake |
203
|
|
|
description: str |
204
|
|
|
|
205
|
|
|
cover_sticker_id: APINullable[Snowflake] = MISSING |
206
|
|
|
banner_asset_id: APINullable[Snowflake] = MISSING |
207
|
|
|
|