From ec2be6565956cb19bd4851974fde2a688e0e847a Mon Sep 17 00:00:00 2001 From: Evo <85353424+EvolutionX-10@users.noreply.github.com> Date: Mon, 22 Aug 2022 20:10:09 +0530 Subject: [PATCH] fix: multiple issues with publish plugin (#32) --- TypeScript/publish.ts | 56 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/TypeScript/publish.ts b/TypeScript/publish.ts index 291ae81..452431e 100644 --- a/TypeScript/publish.ts +++ b/TypeScript/publish.ts @@ -3,20 +3,21 @@ * This is publish plugin, it allows you to publish your slash commands with ease. * * @author @EvolutionX-10 [<@697795666373640213>] - * @version 1.2.0 + * @version 1.2.1 * @example * ```ts * import { publish } from "../plugins/publish"; * import { commandModule } from "@sern/handler"; * export default commandModule({ * plugins: [ publish() ], // put an object containing permissions, ids for guild commands, boolean for dmPermission + * // plugins: [ publish({ guildIds: [], dmPermission: true})] * execute: (ctx) => { * //your code here * } * }) * ``` */ -import { + import { CommandPlugin, CommandType, PluginType, @@ -29,17 +30,18 @@ import { } from "discord.js"; export function publish( - options: PublishOptions = { - guildIds: [], - dmPermission: true, - defaultMemberPermissions: null, - } + options?: PublishOptions ): CommandPlugin { return { type: PluginType.Command, description: "Manage Slash Commands", name: "slash-auto-publish", async execute({ client }, { mod: module }, controller) { + const defaultOptions = { + guildIds: [], + dmPermission: true, + }; + options = { ...defaultOptions, ...options }; let { defaultMemberPermissions, dmPermission, guildIds } = options; function c(e: unknown) { console.error("publish command didnt work for", module.name!); @@ -54,17 +56,16 @@ export function publish( defaultMemberPermissions, dmPermission, }; - if (!Array.isArray(guildIds)) guildIds = [guildIds]; + + if (!Array.isArray(guildIds)) guildIds = [guildIds!]; if (!guildIds.length) { - const cmd = ( - await client.application!.commands.fetch() - ).find((c) => c.name === module.name); + const cmd = (await client.application!.commands.fetch()).find( + (c) => c.name === module.name + ); if (cmd) { if (!cmd.equals(commandData, true)) { - console.log( - `Found differences in global command ${module.name}` - ); + console.log(`Found differences in global command ${module.name}`); cmd.edit(commandData).then(() => { console.log( `${module.name} updated with new data successfully!` @@ -73,14 +74,12 @@ export function publish( } return controller.next(); } - client .application!.commands.create(commandData) .then(() => { console.log("Command created", module.name!); }) .catch(c); - return controller.next(); } @@ -92,9 +91,7 @@ export function publish( ); if (guildcmd) { if (!guildcmd.equals(commandData, true)) { - console.log( - `Found differences in command ${module.name}` - ); + console.log(`Found differences in command ${module.name}`); guildcmd .edit(commandData) .then(() => @@ -110,11 +107,7 @@ export function publish( guild.commands .create(commandData) .then(() => - console.log( - "Guild Command created", - module.name!, - guild.name - ) + console.log("Guild Command created", module.name!, guild.name) ) .catch(c); } @@ -141,8 +134,15 @@ export const CommandTypeRaw = { [CommandType.Slash]: ApplicationCommandType.ChatInput, } as const; -interface PublishOptions { - guildIds: string[]; - defaultMemberPermissions: PermissionResolvable | null; - dmPermission: boolean; +interface DefaultPublishOptions { + guildIds?: string | string[]; + defaultMemberPermissions?: PermissionResolvable; + dmPermission?: boolean; } + +type PublishOptions = DefaultPublishOptions & + ( + | Required> + | Required> + | Required> + );