mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
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
This commit is contained in:
@@ -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 extends BotWithCache = BotWithCache>(b
|
||||
members(bot);
|
||||
messages(bot);
|
||||
roles(bot);
|
||||
stickers(bot);
|
||||
webhooks(bot);
|
||||
|
||||
// PLUGINS MUST RETURN THE BOT
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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<B extends Bot>(bot: B): B {
|
||||
members(bot);
|
||||
messages(bot);
|
||||
misc(bot);
|
||||
stickers(bot);
|
||||
webhooks(bot);
|
||||
|
||||
// PLUGINS MUST RETURN THE BOT
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user