From a15f8bee5e505cd4e75a5cbd8ff5e80d045964c2 Mon Sep 17 00:00:00 2001 From: socram03 Date: Wed, 13 Jul 2022 13:47:28 -0400 Subject: [PATCH] feat(Structures): Stickers --- packages/biscuit/Routes.ts | 13 +++++ packages/biscuit/structures/Sticker.ts | 68 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 packages/biscuit/structures/Sticker.ts diff --git a/packages/biscuit/Routes.ts b/packages/biscuit/Routes.ts index f1cb492..c1e6ecd 100644 --- a/packages/biscuit/Routes.ts +++ b/packages/biscuit/Routes.ts @@ -376,3 +376,16 @@ export function GUILD_APPLICATION_COMMANDS_LOCALIZATIONS( return url; } + +export function STICKER(id: Snowflake) { + return `stickers/${id}`; +} + +export function STICKER_PACKS() { + return `stickers-packs`; +} + +export function GUILD_STICKERS(guildId: Snowflake, stickerId?: Snowflake) { + if (stickerId) return `/guilds/${guildId}/stickers/${stickerId}`; + return `/guilds/${guildId}/stickers`; +} diff --git a/packages/biscuit/structures/Sticker.ts b/packages/biscuit/structures/Sticker.ts new file mode 100644 index 0000000..9321255 --- /dev/null +++ b/packages/biscuit/structures/Sticker.ts @@ -0,0 +1,68 @@ +import type { DiscordSticker, DiscordStickerPack, StickerFormatTypes, StickerTypes } from "../../discordeno/mod.ts"; +import { Model } from "./Base.ts"; +import type { Snowflake } from "../Snowflake.ts"; +import type { Session } from "../Session.ts"; +import { User } from "./User.ts"; +import * as Routes from "../Routes.ts"; + +export interface StickerItem { + id: Snowflake; + name: string; + formatType: StickerFormatTypes; +} + +export interface StickerPack { + id: Snowflake; + stickers: Sticker[]; + name: string; + skuId: Snowflake; + coverStickerId?: Snowflake; + description: string; + bannerAssetId?: Snowflake; +} + +export class Sticker implements Model { + constructor(session: Session, data: DiscordSticker) { + this.session = session; + this.id = data.id; + this.packId = data.pack_id; + this.name = data.name; + this.description = data.description; + this.tags = data.tags.split(","); + this.type = data.type; + this.formatType = data.format_type; + this.available = !!data.available; + this.guildId = data.guild_id; + this.user = data.user ? new User(this.session, data.user) : undefined; + this.sortValue = data.sort_value; + } + session: Session; + id: Snowflake; + packId?: Snowflake; + name: string; + description?: string; + tags: string[]; + type: StickerTypes; + formatType: StickerFormatTypes; + available?: boolean; + guildId?: Snowflake; + user?: User; + sortValue?: number; + + async fetchPremiumPack(): Promise { + const data = await this.session.rest.runMethod( + this.session.rest, + "GET", + Routes.STICKER_PACKS(), + ); + return { + id: data.id, + stickers: data.stickers.map((st) => new Sticker(this.session, st)), + name: data.name, + skuId: data.sku_id, + coverStickerId: data.cover_sticker_id, + description: data.description, + bannerAssetId: data.banner_asset_id, + }; + } +}