From 17132aaf615058aebc83ac87878aaef07a1bff95 Mon Sep 17 00:00:00 2001 From: LTS20050703 Date: Thu, 22 Sep 2022 22:31:41 +0700 Subject: [PATCH] feat(helpers): add stickers helpers (#2466) * helpers: add stickers helpers * deno fmt * undo move getNitroStickerPack to stickers * helpers/stickers: fix jsdocs * plugins/permissions: check stickers permissions * plugins/validations: validate stickers stuff * tests: stickers unit tests * helpers/stickers: add support for reason * plugins/permissions: MANAGE_EMOJIS -> MANAGE_EMOJIS_AND_STICKERS * tests/stickers: delete sticker after test createGuildSticker: add send sticker test getGuildStickers: create another sticker then test > 1 stickers --- helpers/misc/getNitroStickerPacks.ts | 9 +++- helpers/mod.ts | 1 + helpers/stickers/createGuildSticker.ts | 44 +++++++++++++++++++ helpers/stickers/deleteGuildSticker.ts | 26 +++++++++++ helpers/stickers/editGuildSticker.ts | 41 +++++++++++++++++ helpers/stickers/getGuildSticker.ts | 18 ++++++++ helpers/stickers/getGuildStickers.ts | 29 ++++++++++++ helpers/stickers/getSticker.ts | 18 ++++++++ helpers/stickers/mod.ts | 6 +++ plugins/permissions/mod.ts | 2 + .../src/stickers/createGuildSticker.ts | 10 +++++ .../src/stickers/deleteGuildSticker.ts | 10 +++++ .../src/stickers/editGuildSticker.ts | 10 +++++ plugins/permissions/src/stickers/mod.ts | 10 +++++ plugins/validations/mod.ts | 2 + .../src/stickers/createGuildSticker.ts | 20 +++++++++ .../src/stickers/editGuildSticker.ts | 23 ++++++++++ plugins/validations/src/stickers/mod.ts | 8 ++++ tests/stickers/createGuildSticker.test.ts | 27 ++++++++++++ tests/stickers/deleteGuildSticker.test.ts | 15 +++++++ tests/stickers/editGuildSticker.test.ts | 23 ++++++++++ tests/stickers/getGuildSticker.test.ts | 19 ++++++++ tests/stickers/getGuildStickers.test.ts | 23 ++++++++++ tests/stickers/getSticker.test.ts | 8 ++++ util/routes.ts | 13 +++++- 25 files changed, 412 insertions(+), 3 deletions(-) create mode 100644 helpers/stickers/createGuildSticker.ts create mode 100644 helpers/stickers/deleteGuildSticker.ts create mode 100644 helpers/stickers/editGuildSticker.ts create mode 100644 helpers/stickers/getGuildSticker.ts create mode 100644 helpers/stickers/getGuildStickers.ts create mode 100644 helpers/stickers/getSticker.ts create mode 100644 helpers/stickers/mod.ts create mode 100644 plugins/permissions/src/stickers/createGuildSticker.ts create mode 100644 plugins/permissions/src/stickers/deleteGuildSticker.ts create mode 100644 plugins/permissions/src/stickers/editGuildSticker.ts create mode 100644 plugins/permissions/src/stickers/mod.ts create mode 100644 plugins/validations/src/stickers/createGuildSticker.ts create mode 100644 plugins/validations/src/stickers/editGuildSticker.ts create mode 100644 plugins/validations/src/stickers/mod.ts create mode 100644 tests/stickers/createGuildSticker.test.ts create mode 100644 tests/stickers/deleteGuildSticker.test.ts create mode 100644 tests/stickers/editGuildSticker.test.ts create mode 100644 tests/stickers/getGuildSticker.test.ts create mode 100644 tests/stickers/getGuildStickers.test.ts create mode 100644 tests/stickers/getSticker.test.ts diff --git a/helpers/misc/getNitroStickerPacks.ts b/helpers/misc/getNitroStickerPacks.ts index ab905be26..4645eb8f8 100644 --- a/helpers/misc/getNitroStickerPacks.ts +++ b/helpers/misc/getNitroStickerPacks.ts @@ -3,7 +3,14 @@ import { StickerPack } from "../../transformers/sticker.ts"; import { DiscordStickerPack } from "../../types/discord.ts"; import { Collection } from "../../util/collection.ts"; -/** Returns the list of sticker packs available to Nitro subscribers. */ +/** + * Returns the list of sticker packs available to Nitro subscribers. + * + * @param bot The bot instance to use to make the request. + * @returns A collection of {@link StickerPack} objects assorted by sticker ID. + * + * @see {@link https://discord.com/developers/docs/resources/sticker#list-nitro-sticker-packs} + */ export async function getNitroStickerPacks(bot: Bot): Promise> { const results = await bot.rest.runMethod( bot.rest, diff --git a/helpers/mod.ts b/helpers/mod.ts index a7c92b836..8b8199b54 100644 --- a/helpers/mod.ts +++ b/helpers/mod.ts @@ -6,5 +6,6 @@ export * from "./members/mod.ts"; export * from "./messages/mod.ts"; export * from "./misc/mod.ts"; export * from "./roles/mod.ts"; +export * from "./stickers/mod.ts"; export * from "./templates/mod.ts"; export * from "./webhooks/mod.ts"; diff --git a/helpers/stickers/createGuildSticker.ts b/helpers/stickers/createGuildSticker.ts new file mode 100644 index 000000000..2e2322bcd --- /dev/null +++ b/helpers/stickers/createGuildSticker.ts @@ -0,0 +1,44 @@ +import { Bot } from "../../bot.ts"; +import { Sticker } from "../../transformers/sticker.ts"; +import { FileContent, WithReason } from "../../types/discordeno.ts"; + +/** + * Create a new sticker for the guild. + * + * @param bot The bot instance to use to make the request. + * @param guildId The ID of the guild to get + * @return A {@link Sticker} + * + * @remarks + * Requires the `MANAGE_EMOJIS_AND_STICKERS` permission. + * Fires a Guild Stickers Update Gateway event. + * Every guilds has five free sticker slots by default, and each Boost level will grant access to more slots. + * Lottie stickers can only be uploaded on guilds that have either the `VERIFIED` and/or the `PARTNERED` guild feature. + * + * @see {@link https://discord.com/developers/docs/resources/sticker#create-guild-sticker} + */ +export async function createGuildSticker( + bot: Bot, + guildId: bigint, + options: CreateGuildStickerOptions, +): Promise { + const result = await bot.rest.runMethod(bot.rest, "POST", bot.constants.routes.GUILD_STICKERS(guildId), { + name: options.name, + description: options.description, + tags: options.tags, + file: options.file, + reason: options.reason, + }); + return bot.transformers.sticker(bot, result); +} + +export interface CreateGuildStickerOptions extends WithReason { + /** Name of the sticker (2-30 characters) */ + name: string; + /** Description of the sticker (empty or 2-100 characters) */ + description: string; + /** Autocomplete/suggestion tags for the sticker (max 200 characters) */ + tags: string; + /** The sticker file to upload, must be a PNG, APNG, or Lottie JSON file, max 500 KB */ + file: FileContent; +} diff --git a/helpers/stickers/deleteGuildSticker.ts b/helpers/stickers/deleteGuildSticker.ts new file mode 100644 index 000000000..92cf37e36 --- /dev/null +++ b/helpers/stickers/deleteGuildSticker.ts @@ -0,0 +1,26 @@ +import { Bot } from "../../bot.ts"; +import { Sticker } from "../../transformers/sticker.ts"; + +/** + * Delete a new sticker for the guild. + * + * @param bot The bot instance to use to make the request. + * @param guildId The ID of the guild to get + * @return A {@link Sticker} + * + * @remarks + * Requires the `MANAGE_EMOJIS_AND_STICKERS` permission. + * Fires a Guild Stickers Update Gateway event. + * Every guilds has five free sticker slots by default, and each Boost level will grant access to more slots. + * Lottie stickers can only be uploaded on guilds that have either the `VERIFIED` and/or the `PARTNERED` guild feature. + * + * @see {@link https://discord.com/developers/docs/resources/sticker#delete-guild-sticker} + */ +export async function deleteGuildSticker(bot: Bot, guildId: bigint, stickerId: bigint, reason?: string): Promise { + return await bot.rest.runMethod( + bot.rest, + "DELETE", + bot.constants.routes.GUILD_STICKER(guildId, stickerId), + reason ? { reason } : undefined, + ); +} diff --git a/helpers/stickers/editGuildSticker.ts b/helpers/stickers/editGuildSticker.ts new file mode 100644 index 000000000..d1fc38475 --- /dev/null +++ b/helpers/stickers/editGuildSticker.ts @@ -0,0 +1,41 @@ +import { Bot } from "../../bot.ts"; +import { Sticker } from "../../transformers/sticker.ts"; +import { WithReason } from "../../types/discordeno.ts"; +import { AtLeastOne } from "../../types/shared.ts"; + +/** + * Edit the given sticker. + * + * @param bot The bot instance to use to make the request. + * @param guildId The ID of the guild to get + * @return A {@link Sticker} + * + * @remarks + * Requires the `MANAGE_EMOJIS_AND_STICKERS` permission. + * Fires a Guild Stickers Update Gateway event. + * + * @see {@link https://discord.com/developers/docs/resources/sticker#modify-guild-sticker} + */ +export async function editGuildSticker( + bot: Bot, + guildId: bigint, + stickerId: bigint, + options: AtLeastOne, +): Promise { + const result = await bot.rest.runMethod(bot.rest, "PATCH", bot.constants.routes.GUILD_STICKER(guildId, stickerId), { + name: options.name, + description: options.description, + tags: options.tags, + reason: options.reason, + }); + return bot.transformers.sticker(bot, result); +} + +export interface EditGuildStickerOptions extends WithReason { + /** Name of the sticker (2-30 characters) */ + name?: string; + /** Description of the sticker (empty or 2-100 characters) */ + description?: string | null; + /** Autocomplete/suggestion tags for the sticker (max 200 characters) */ + tags?: string; +} diff --git a/helpers/stickers/getGuildSticker.ts b/helpers/stickers/getGuildSticker.ts new file mode 100644 index 000000000..da650316e --- /dev/null +++ b/helpers/stickers/getGuildSticker.ts @@ -0,0 +1,18 @@ +import { Bot, Sticker } from "../../mod.ts"; + +/** + * Returns a sticker object for the given guild and sticker IDs. + * + * @param bot The bot instance to use to make the request. + * @param guildId The ID of the guild to get + * @param stickerId The ID of the sticker to get + * @return A {@link Sticker} + * + * @remarks Includes the user field if the bot has the `MANAGE_EMOJIS_AND_STICKERS` permission. + * + * @see {@link https://discord.com/developers/docs/resources/sticker#get-guild-sticker} + */ +export async function getGuildSticker(bot: Bot, guildId: bigint, stickerId: bigint): Promise { + const result = await bot.rest.runMethod(bot.rest, "GET", bot.constants.routes.GUILD_STICKER(guildId, stickerId)); + return bot.transformers.sticker(bot, result); +} diff --git a/helpers/stickers/getGuildStickers.ts b/helpers/stickers/getGuildStickers.ts new file mode 100644 index 000000000..19a05a147 --- /dev/null +++ b/helpers/stickers/getGuildStickers.ts @@ -0,0 +1,29 @@ +import { Bot } from "../../bot.ts"; +import { Collection, Sticker } from "../../mod.ts"; +import { DiscordSticker } from "../../types/discord.ts"; + +/** + * Returns an array of sticker objects for the given guild. + * + * @param bot The bot instance to use to make the request. + * @param guildId The ID of the guild to get + * @returns A collection of {@link Sticker} objects assorted by sticker ID. + * + * @remarks Includes user fields if the bot has the `MANAGE_EMOJIS_AND_STICKERS` permission. + * + * @see {@link https://discord.com/developers/docs/resources/sticker#list-guild-stickers} + */ +export async function getGuildStickers(bot: Bot, guildId: bigint): Promise> { + const results = await bot.rest.runMethod( + bot.rest, + "GET", + bot.constants.routes.GUILD_STICKERS(guildId), + ); + + return new Collection( + results.map((result) => { + const pack = bot.transformers.sticker(bot, result); + return [pack.id, pack]; + }), + ); +} diff --git a/helpers/stickers/getSticker.ts b/helpers/stickers/getSticker.ts new file mode 100644 index 000000000..e1c6391a1 --- /dev/null +++ b/helpers/stickers/getSticker.ts @@ -0,0 +1,18 @@ +import { Bot } from "../../bot.ts"; +import { Sticker } from "../../mod.ts"; +import { DiscordSticker } from "../../types/discord.ts"; + +/** + * Returns a sticker object for the given sticker ID. + * + * @param bot The bot instance to use to make the request. + * @param stickerId The ID of the sticker to get + * @returns A {@link Sticker} + * + * @see {@link https://discord.com/developers/docs/resources/sticker#get-sticker} + */ +export async function getSticker(bot: Bot, stickerId: bigint): Promise { + const result = await bot.rest.runMethod(bot.rest, "GET", bot.constants.routes.STICKER(stickerId)); + + return bot.transformers.sticker(bot, result); +} diff --git a/helpers/stickers/mod.ts b/helpers/stickers/mod.ts new file mode 100644 index 000000000..941579b7e --- /dev/null +++ b/helpers/stickers/mod.ts @@ -0,0 +1,6 @@ +export * from "./createGuildSticker.ts"; +export * from "./deleteGuildSticker.ts"; +export * from "./editGuildSticker.ts"; +export * from "./getGuildSticker.ts"; +export * from "./getGuildStickers.ts"; +export * from "./getSticker.ts"; diff --git a/plugins/permissions/mod.ts b/plugins/permissions/mod.ts index c373adc88..0bfe03d41 100644 --- a/plugins/permissions/mod.ts +++ b/plugins/permissions/mod.ts @@ -6,6 +6,7 @@ import { integrations } from "./src/integrations/mod.ts"; import { members } from "./src/members/mod.ts"; import { messages } from "./src/messages/mod.ts"; import { roles } from "./src/roles/mod.ts"; +import { stickers } from "./src/stickers/mod.ts"; import { webhooks } from "./src/webhooks/mod.ts"; // PLUGINS MUST TAKE A BOT ARGUMENT WHICH WILL BE MODIFIED @@ -24,6 +25,7 @@ export function enablePermissionsPlugin(b members(bot); messages(bot); roles(bot); + stickers(bot); webhooks(bot); // PLUGINS MUST RETURN THE BOT diff --git a/plugins/permissions/src/stickers/createGuildSticker.ts b/plugins/permissions/src/stickers/createGuildSticker.ts new file mode 100644 index 000000000..bce760420 --- /dev/null +++ b/plugins/permissions/src/stickers/createGuildSticker.ts @@ -0,0 +1,10 @@ +import { BotWithCache } from "../../deps.ts"; +import { requireBotGuildPermissions } from "../permissions.ts"; + +export async function createGuildSticker(bot: BotWithCache) { + const createGuildSticker = bot.helpers.createGuildSticker; + bot.helpers.createGuildSticker = (guildId, options) => { + requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS_AND_STICKERS"]); + return createGuildSticker(guildId, options); + }; +} diff --git a/plugins/permissions/src/stickers/deleteGuildSticker.ts b/plugins/permissions/src/stickers/deleteGuildSticker.ts new file mode 100644 index 000000000..4218c2a45 --- /dev/null +++ b/plugins/permissions/src/stickers/deleteGuildSticker.ts @@ -0,0 +1,10 @@ +import { BotWithCache } from "../../deps.ts"; +import { requireBotGuildPermissions } from "../permissions.ts"; + +export async function deleteGuildSticker(bot: BotWithCache) { + const deleteGuildSticker = bot.helpers.deleteGuildSticker; + bot.helpers.deleteGuildSticker = (guildId, stickerId, reason) => { + requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS_AND_STICKERS"]); + return deleteGuildSticker(guildId, stickerId, reason); + }; +} diff --git a/plugins/permissions/src/stickers/editGuildSticker.ts b/plugins/permissions/src/stickers/editGuildSticker.ts new file mode 100644 index 000000000..6420704b9 --- /dev/null +++ b/plugins/permissions/src/stickers/editGuildSticker.ts @@ -0,0 +1,10 @@ +import { BotWithCache } from "../../deps.ts"; +import { requireBotGuildPermissions } from "../permissions.ts"; + +export async function editGuildSticker(bot: BotWithCache) { + const editGuildSticker = bot.helpers.editGuildSticker; + bot.helpers.editGuildSticker = (guildId, stickerId, options) => { + requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS_AND_STICKERS"]); + return editGuildSticker(guildId, stickerId, options); + }; +} diff --git a/plugins/permissions/src/stickers/mod.ts b/plugins/permissions/src/stickers/mod.ts new file mode 100644 index 000000000..0d6a83e8a --- /dev/null +++ b/plugins/permissions/src/stickers/mod.ts @@ -0,0 +1,10 @@ +import { BotWithCache } from "../../deps.ts"; +import { createGuildSticker } from "./createGuildSticker.ts"; +import { deleteGuildSticker } from "./deleteGuildSticker.ts"; +import { editGuildSticker } from "./editGuildSticker.ts"; + +export function stickers(bot: BotWithCache) { + createGuildSticker(bot); + deleteGuildSticker(bot); + editGuildSticker(bot); +} diff --git a/plugins/validations/mod.ts b/plugins/validations/mod.ts index e0a61b416..dd06ea9ba 100644 --- a/plugins/validations/mod.ts +++ b/plugins/validations/mod.ts @@ -6,6 +6,7 @@ import { invites } from "./src/invites/mod.ts"; import { members } from "./src/members/mod.ts"; import { messages } from "./src/messages/mod.ts"; import { misc } from "./src/misc/mod.ts"; +import { stickers } from "./src/stickers/mod.ts"; import { webhooks } from "./src/webhooks/mod.ts"; // PLUGINS MUST TAKE A BOT ARGUMENT WHICH WILL BE MODIFIED @@ -21,6 +22,7 @@ export function enableValidationsPlugin(bot: B): B { members(bot); messages(bot); misc(bot); + stickers(bot); webhooks(bot); // PLUGINS MUST RETURN THE BOT diff --git a/plugins/validations/src/stickers/createGuildSticker.ts b/plugins/validations/src/stickers/createGuildSticker.ts new file mode 100644 index 000000000..4ccf8c554 --- /dev/null +++ b/plugins/validations/src/stickers/createGuildSticker.ts @@ -0,0 +1,20 @@ +import { Bot } from "../../../../bot.ts"; + +export function createGuildSticker(bot: Bot) { + const createGuildSticker = bot.helpers.createGuildSticker; + bot.helpers.createGuildSticker = (guildId, options) => { + if (!bot.utils.validateLength(options.name, { min: 2, max: 30 })) { + throw new Error("Sticker name length must be between 2 and 30 characters"); + } + // description of the sticker (empty or 2-100 characters) + if (options.description !== "" && !bot.utils.validateLength(options.description, { min: 2, max: 100 })) { + throw new Error( + "Sticker description must be empty or sticker description length must be between 2 and 100 characters", + ); + } + if (!bot.utils.validateLength(options.tags, { max: 200 })) { + throw new Error("Sticker tags length must be less than 200 characters"); + } + return createGuildSticker(guildId, options); + }; +} diff --git a/plugins/validations/src/stickers/editGuildSticker.ts b/plugins/validations/src/stickers/editGuildSticker.ts new file mode 100644 index 000000000..777f5e443 --- /dev/null +++ b/plugins/validations/src/stickers/editGuildSticker.ts @@ -0,0 +1,23 @@ +import { Bot } from "../../../../bot.ts"; + +export function editGuildSticker(bot: Bot) { + const editGuildSticker = bot.helpers.editGuildSticker; + bot.helpers.editGuildSticker = (guildId, stickerId, options) => { + if (options.name && !bot.utils.validateLength(options.name, { min: 2, max: 30 })) { + throw new Error("Sticker name length must be between 2 and 30 characters"); + } + // description of the sticker (empty or 2-100 characters) + if ( + options.description && options.description !== "" && + !bot.utils.validateLength(options.description, { min: 2, max: 100 }) + ) { + throw new Error( + "Sticker description must be empty or sticker description length must be between 2 and 100 characters", + ); + } + if (options.tags && !bot.utils.validateLength(options.tags, { max: 200 })) { + throw new Error("Sticker tags length must be less than 200 characters"); + } + return editGuildSticker(guildId, stickerId, options); + }; +} diff --git a/plugins/validations/src/stickers/mod.ts b/plugins/validations/src/stickers/mod.ts new file mode 100644 index 000000000..ecd55a59c --- /dev/null +++ b/plugins/validations/src/stickers/mod.ts @@ -0,0 +1,8 @@ +import { Bot } from "../../../../bot.ts"; +import { createGuildSticker } from "./createGuildSticker.ts"; +import { editGuildSticker } from "./editGuildSticker.ts"; + +export function stickers(bot: Bot) { + createGuildSticker(bot); + editGuildSticker(bot); +} diff --git a/tests/stickers/createGuildSticker.test.ts b/tests/stickers/createGuildSticker.test.ts new file mode 100644 index 000000000..60b92e6f4 --- /dev/null +++ b/tests/stickers/createGuildSticker.test.ts @@ -0,0 +1,27 @@ +import { StickerFormatTypes } from "../../mod.ts"; +import { assertEquals } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; + +Deno.test("[stickers] Create guild sticker", async () => { + const bot = loadBot(); + const sticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, { + name: "sticker name", + description: "sticker description", + tags: "sticker tags", + file: { blob: new Blob(), name: "test.png" }, + }); + + assertEquals(sticker.name, "sticker name"); + assertEquals(sticker.description, "sticker description"); + assertEquals(sticker.tags, "sticker tags"); + + const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID); + const message = await bot.helpers.sendMessage(channel.id, { stickerIds: [sticker.id] }); + + assertEquals(message.stickerItems?.[0].formatType, StickerFormatTypes.Png); + assertEquals(message.stickerItems?.[0].id, sticker.id); + assertEquals(message.stickerItems?.[0].name, sticker.name); + + await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id); +}); diff --git a/tests/stickers/deleteGuildSticker.test.ts b/tests/stickers/deleteGuildSticker.test.ts new file mode 100644 index 000000000..de0cac831 --- /dev/null +++ b/tests/stickers/deleteGuildSticker.test.ts @@ -0,0 +1,15 @@ +import { assertRejects } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; + +Deno.test("[stickers] Delete guild sticker", async () => { + const bot = loadBot(); + const sticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, { + name: "sticker name", + description: "sticker description", + tags: "sticker tags", + file: { blob: new Blob(), name: "sticker file name" }, + }); + await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id); + await assertRejects(() => bot.helpers.getGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker.id)); +}); diff --git a/tests/stickers/editGuildSticker.test.ts b/tests/stickers/editGuildSticker.test.ts new file mode 100644 index 000000000..7556e6891 --- /dev/null +++ b/tests/stickers/editGuildSticker.test.ts @@ -0,0 +1,23 @@ +import { assertEquals } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; + +Deno.test("[stickers] Edit guild sticker", async () => { + const bot = loadBot(); + const createSticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, { + name: "test", + description: "test", + tags: "test", + file: { blob: new Blob(), name: "test.png" }, + }); + const editSticker = await bot.helpers.editGuildSticker(CACHED_COMMUNITY_GUILD_ID, createSticker.id, { + name: "sticker name", + description: "sticker description", + tags: "sticker tags", + }); + assertEquals(editSticker.name, "sticker name"); + assertEquals(editSticker.description, "sticker description"); + assertEquals(editSticker.tags, "sticker tags"); + + await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, editSticker.id); +}); diff --git a/tests/stickers/getGuildSticker.test.ts b/tests/stickers/getGuildSticker.test.ts new file mode 100644 index 000000000..236606567 --- /dev/null +++ b/tests/stickers/getGuildSticker.test.ts @@ -0,0 +1,19 @@ +import { assertEquals } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; + +Deno.test("[stickers] Get guild sticker", async () => { + const bot = loadBot(); + const createSticker = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, { + name: "sticker name", + description: "sticker description", + tags: "sticker tags", + file: { blob: new Blob(), name: "sticker file name" }, + }); + const getSticker = await bot.helpers.getGuildSticker(CACHED_COMMUNITY_GUILD_ID, createSticker.id); + assertEquals(getSticker.name, "sticker name"); + assertEquals(getSticker.description, "sticker description"); + assertEquals(getSticker.tags, "sticker tags"); + + await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, getSticker.id); +}); diff --git a/tests/stickers/getGuildStickers.test.ts b/tests/stickers/getGuildStickers.test.ts new file mode 100644 index 000000000..ea8c936c5 --- /dev/null +++ b/tests/stickers/getGuildStickers.test.ts @@ -0,0 +1,23 @@ +import { assertEquals } from "../deps.ts"; +import { loadBot } from "../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts"; + +Deno.test("[stickers] Get guild stickers", async () => { + const bot = loadBot(); + const sticker1 = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, { + name: "sticker 1", + description: "sticker 1", + tags: "sticker tags 1", + file: { blob: new Blob(), name: "test1.png" }, + }); + const sticker2 = await bot.helpers.createGuildSticker(CACHED_COMMUNITY_GUILD_ID, { + name: "sticker 2", + description: "sticker 2", + tags: "sticker tags 2", + file: { blob: new Blob(), name: "test2.png" }, + }); + const stickers = await bot.helpers.getGuildStickers(CACHED_COMMUNITY_GUILD_ID); + assertEquals(stickers.size > 1, true); + await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker1.id); + await bot.helpers.deleteGuildSticker(CACHED_COMMUNITY_GUILD_ID, sticker2.id); +}); diff --git a/tests/stickers/getSticker.test.ts b/tests/stickers/getSticker.test.ts new file mode 100644 index 000000000..a171b7dc1 --- /dev/null +++ b/tests/stickers/getSticker.test.ts @@ -0,0 +1,8 @@ +import { assertEquals } from "../deps.ts"; +import { loadBot } from "../mod.ts"; + +Deno.test("[stickers] Get sticker", async () => { + const bot = loadBot(); + const sticker = await bot.helpers.getSticker(749054660769218631n); + assertEquals(sticker.name, "Wave"); +}); diff --git a/util/routes.ts b/util/routes.ts index 1e308f761..2d88833cd 100644 --- a/util/routes.ts +++ b/util/routes.ts @@ -508,8 +508,17 @@ export const routes = { return `/stage-instances/${channelId}`; }, - // Misc Endpoints + // Stickers Endpoints NITRO_STICKER_PACKS: () => { - return `/sticker-packs`; + return "/sticker-packs"; + }, + STICKER: (stickerId: bigint) => { + return `/stickers/${stickerId}`; + }, + GUILD_STICKERS: (guildId: bigint) => { + return `/guilds/${guildId}/stickers`; + }, + GUILD_STICKER: (guildId: bigint, stickerId: bigint) => { + return `/guilds/${guildId}/stickers/${stickerId}`; }, };