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