-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Expand file tree
/
Copy pathSticker.ts
More file actions
96 lines (85 loc) · 2.24 KB
/
Sticker.ts
File metadata and controls
96 lines (85 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import {
CDNRoutes,
ImageFormat,
RouteBases,
StickerFormatType,
type APISticker,
type StickerFormat,
} from 'discord-api-types/v10';
import { Structure } from '../Structure.js';
import { kData } from '../utils/symbols.js';
import { isFieldSet, isIdSet } from '../utils/type-guards.js';
import type { Partialize } from '../utils/types.js';
const StickerFormatExtensionMap = {
[StickerFormatType.PNG]: ImageFormat.PNG,
[StickerFormatType.APNG]: ImageFormat.PNG,
[StickerFormatType.Lottie]: ImageFormat.Lottie,
[StickerFormatType.GIF]: ImageFormat.GIF,
} satisfies Record<StickerFormatType, StickerFormat>;
/**
* Represents a sticker on Discord.
*
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
*/
export class Sticker<Omitted extends keyof APISticker | '' = ''> extends Structure<APISticker, Omitted> {
/**
* The template used for removing data from the raw data stored for each SitckerItem.
*/
public static override DataTemplate: Partial<APISticker> = {};
/**
* @param data - The raw data received from the API for the sticker item
*/
public constructor(data: Partialize<APISticker, Omitted>) {
super(data);
}
/**
* The id of the sticker
*/
public get id() {
return this[kData].id;
}
/**
* The name of the sticker
*/
public get name() {
return this[kData].name;
}
/**
* The format type of the sticker
*/
public get formatType() {
return this[kData].format_type;
}
/**
* Whether this guild sticker can be used, may be false due to loss of Server Boosts
*/
public get available() {
return this[kData].available;
}
/**
* The description of the sticker
*/
public get description() {
return this[kData].description;
}
/**
* The autocomplete/suggestion tags for the sticker
*/
public get tags() {
return this[kData].tags;
}
/**
* The type of this sticker
*/
public get type() {
return this[kData].type;
}
/**
* Get the URL to the sticker
*/
public get url() {
return isIdSet(this[kData].id) && isFieldSet(this[kData], 'format_type', 'number')
? `${RouteBases.cdn}${CDNRoutes.sticker(this[kData].id.toString(), StickerFormatExtensionMap[this[kData].format_type] as StickerFormat)}`
: null;
}
}