mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
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>
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
|
import { DiscordSnowflake } from '@sapphire/snowflake';
|
||||||
import type { APISticker } from 'discord-api-types/v10';
|
import type { APISticker } from 'discord-api-types/v10';
|
||||||
import { Structure } from '../Structure.js';
|
import { Structure } from '../Structure.js';
|
||||||
import { kData } from '../utils/symbols.js';
|
import { kData } from '../utils/symbols.js';
|
||||||
|
import { isIdSet } from '../utils/type-guards.js';
|
||||||
import type { Partialize } from '../utils/types.js';
|
import type { Partialize } from '../utils/types.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,4 +71,19 @@ export class Sticker<Omitted extends keyof APISticker | '' = ''> extends Structu
|
|||||||
public get type() {
|
public get type() {
|
||||||
return this[kData].type;
|
return this[kData].type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timestamp the sticker was created at
|
||||||
|
*/
|
||||||
|
public get createdTimestamp() {
|
||||||
|
return isIdSet(this.id) ? DiscordSnowflake.timestampFrom(this.id) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time the sticker was created at
|
||||||
|
*/
|
||||||
|
public get createdAt() {
|
||||||
|
const createdTimestamp = this.createdTimestamp;
|
||||||
|
return createdTimestamp ? new Date(createdTimestamp) : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
85
packages/structures/src/stickers/StickerPack.ts
Normal file
85
packages/structures/src/stickers/StickerPack.ts
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import { DiscordSnowflake } from '@sapphire/snowflake';
|
||||||
|
import type { APIStickerPack } from 'discord-api-types/v10';
|
||||||
|
import { Structure } from '../Structure.js';
|
||||||
|
import { kData } from '../utils/symbols.js';
|
||||||
|
import { isIdSet } from '../utils/type-guards.js';
|
||||||
|
import type { Partialize } from '../utils/types.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a sticker pack on Discord.
|
||||||
|
*
|
||||||
|
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
|
||||||
|
* @remarks has substructure `Sticker` which needs to be instantiated and stored by an extending class using it
|
||||||
|
*/
|
||||||
|
export class StickerPack<Omitted extends keyof APIStickerPack | '' = ''> extends Structure<APIStickerPack, Omitted> {
|
||||||
|
/**
|
||||||
|
* The template used for removing data from the raw data stored for each sticker pack
|
||||||
|
*/
|
||||||
|
public static override DataTemplate: Partial<APIStickerPack> = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param data - The raw data received from the API for the sticker pack
|
||||||
|
*/
|
||||||
|
public constructor(data: Partialize<APIStickerPack, Omitted>) {
|
||||||
|
super(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the sticker pack
|
||||||
|
*/
|
||||||
|
public get id() {
|
||||||
|
return this[kData].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the sticker pack
|
||||||
|
*/
|
||||||
|
public get name() {
|
||||||
|
return this[kData].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the pack's SKU
|
||||||
|
*/
|
||||||
|
public get skuId() {
|
||||||
|
return this[kData].sku_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of a sticker in the pack which is shown as the pack's icon
|
||||||
|
*/
|
||||||
|
public get coverStickerId() {
|
||||||
|
return this[kData].cover_sticker_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The description of the sticker pack
|
||||||
|
*/
|
||||||
|
public get description() {
|
||||||
|
return this[kData].description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the sticker pack's banner image
|
||||||
|
*
|
||||||
|
* @see {@link https://discord.com/developers/docs/reference#image-formatting}
|
||||||
|
*/
|
||||||
|
public get bannerAssetId() {
|
||||||
|
return this[kData].banner_asset_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timestamp the sticker pack was created at
|
||||||
|
*/
|
||||||
|
public get createdTimestamp() {
|
||||||
|
return isIdSet(this.id) ? DiscordSnowflake.timestampFrom(this.id) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time the sticker pack was created at
|
||||||
|
*/
|
||||||
|
public get createdAt() {
|
||||||
|
const createdTimestamp = this.createdTimestamp;
|
||||||
|
return createdTimestamp ? new Date(createdTimestamp) : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
export * from './Sticker.js';
|
export * from './Sticker.js';
|
||||||
|
export * from './StickerPack.js';
|
||||||
|
|||||||
Reference in New Issue
Block a user