Skip to content

Commit 1251d47

Browse files
feat(structures): add StickerPack structure (#11398)
* feat(structures): update barrel exports * feat(structures): add StickerPack structure * chore(structures): add createdAt and createdTimestamp to Sticker struct * docs(structure): correct usage of links in see/link blocks --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 693fcbc commit 1251d47

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

packages/structures/src/stickers/Sticker.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { DiscordSnowflake } from '@sapphire/snowflake';
12
import type { APISticker } from 'discord-api-types/v10';
23
import { Structure } from '../Structure.js';
34
import { kData } from '../utils/symbols.js';
5+
import { isIdSet } from '../utils/type-guards.js';
46
import type { Partialize } from '../utils/types.js';
57

68
/**
@@ -69,4 +71,19 @@ export class Sticker<Omitted extends keyof APISticker | '' = ''> extends Structu
6971
public get type() {
7072
return this[kData].type;
7173
}
74+
75+
/**
76+
* The timestamp the sticker was created at
77+
*/
78+
public get createdTimestamp() {
79+
return isIdSet(this.id) ? DiscordSnowflake.timestampFrom(this.id) : null;
80+
}
81+
82+
/**
83+
* The time the sticker was created at
84+
*/
85+
public get createdAt() {
86+
const createdTimestamp = this.createdTimestamp;
87+
return createdTimestamp ? new Date(createdTimestamp) : null;
88+
}
7289
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { DiscordSnowflake } from '@sapphire/snowflake';
2+
import type { APIStickerPack } from 'discord-api-types/v10';
3+
import { Structure } from '../Structure.js';
4+
import { kData } from '../utils/symbols.js';
5+
import { isIdSet } from '../utils/type-guards.js';
6+
import type { Partialize } from '../utils/types.js';
7+
8+
/**
9+
* Represents a sticker pack on Discord.
10+
*
11+
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
12+
* @remarks has substructure `Sticker` which needs to be instantiated and stored by an extending class using it
13+
*/
14+
export class StickerPack<Omitted extends keyof APIStickerPack | '' = ''> extends Structure<APIStickerPack, Omitted> {
15+
/**
16+
* The template used for removing data from the raw data stored for each sticker pack
17+
*/
18+
public static override DataTemplate: Partial<APIStickerPack> = {};
19+
20+
/**
21+
* @param data - The raw data received from the API for the sticker pack
22+
*/
23+
public constructor(data: Partialize<APIStickerPack, Omitted>) {
24+
super(data);
25+
}
26+
27+
/**
28+
* The id of the sticker pack
29+
*/
30+
public get id() {
31+
return this[kData].id;
32+
}
33+
34+
/**
35+
* The name of the sticker pack
36+
*/
37+
public get name() {
38+
return this[kData].name;
39+
}
40+
41+
/**
42+
* The id of the pack's SKU
43+
*/
44+
public get skuId() {
45+
return this[kData].sku_id;
46+
}
47+
48+
/**
49+
* The id of a sticker in the pack which is shown as the pack's icon
50+
*/
51+
public get coverStickerId() {
52+
return this[kData].cover_sticker_id;
53+
}
54+
55+
/**
56+
* The description of the sticker pack
57+
*/
58+
public get description() {
59+
return this[kData].description;
60+
}
61+
62+
/**
63+
* The id of the sticker pack's banner image
64+
*
65+
* @see {@link https://discord.com/developers/docs/reference#image-formatting}
66+
*/
67+
public get bannerAssetId() {
68+
return this[kData].banner_asset_id;
69+
}
70+
71+
/**
72+
* The timestamp the sticker pack was created at
73+
*/
74+
public get createdTimestamp() {
75+
return isIdSet(this.id) ? DiscordSnowflake.timestampFrom(this.id) : null;
76+
}
77+
78+
/**
79+
* The time the sticker pack was created at
80+
*/
81+
public get createdAt() {
82+
const createdTimestamp = this.createdTimestamp;
83+
return createdTimestamp ? new Date(createdTimestamp) : null;
84+
}
85+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './Sticker.js';
2+
export * from './StickerPack.js';

0 commit comments

Comments
 (0)