From ae28529722962af9f3d5fff4c58fc35714c6ae59 Mon Sep 17 00:00:00 2001 From: Evo <85353424+EvolutionX-10@users.noreply.github.com> Date: Fri, 19 Aug 2022 23:07:47 +0530 Subject: [PATCH] feat: improve publish (#30) * feat: improve publish * chore: address requested changes * chore: req changes --- TypeScript/publish.ts | 64 +++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/TypeScript/publish.ts b/TypeScript/publish.ts index d39a5da..291ae81 100644 --- a/TypeScript/publish.ts +++ b/TypeScript/publish.ts @@ -3,13 +3,13 @@ * This is publish plugin, it allows you to publish your slash commands with ease. * * @author @EvolutionX-10 [<@697795666373640213>] - * @version 1.1.0 + * @version 1.2.0 * @example * ```ts * import { publish } from "../plugins/publish"; * import { commandModule } from "@sern/handler"; * export default commandModule({ - * plugins: [ publish() ], // put an array of guild ids for guild commands + * plugins: [ publish() ], // put an object containing permissions, ids for guild commands, boolean for dmPermission * execute: (ctx) => { * //your code here * } @@ -22,16 +22,25 @@ import { PluginType, SernOptionsData, } from "@sern/handler"; -import { ApplicationCommandData, ApplicationCommandType } from "discord.js"; +import { + ApplicationCommandData, + ApplicationCommandType, + PermissionResolvable, +} from "discord.js"; export function publish( - guildIds: string | Array = [] + options: PublishOptions = { + guildIds: [], + dmPermission: true, + defaultMemberPermissions: null, + } ): CommandPlugin { return { type: PluginType.Command, description: "Manage Slash Commands", name: "slash-auto-publish", - async execute({ client }, { absPath, mod: module }, controller) { + async execute({ client }, { mod: module }, controller) { + let { defaultMemberPermissions, dmPermission, guildIds } = options; function c(e: unknown) { console.error("publish command didnt work for", module.name!); console.error(e); @@ -42,6 +51,8 @@ export function publish( name: module.name!, description: module.description, options: optionsTransformer(module.options ?? []), + defaultMemberPermissions, + dmPermission, }; if (!Array.isArray(guildIds)) guildIds = [guildIds]; @@ -54,7 +65,7 @@ export function publish( console.log( `Found differences in global command ${module.name}` ); - await cmd.edit(commandData).then((c) => { + cmd.edit(commandData).then(() => { console.log( `${module.name} updated with new data successfully!` ); @@ -63,10 +74,13 @@ export function publish( return controller.next(); } - await client + client .application!.commands.create(commandData) + .then(() => { + console.log("Command created", module.name!); + }) .catch(c); - console.log("Command created", module.name!); + return controller.next(); } @@ -81,20 +95,28 @@ export function publish( console.log( `Found differences in command ${module.name}` ); - await guildcmd.edit(commandData).catch(c); - console.log( - `${module.name} updated with new data successfully!` - ); + guildcmd + .edit(commandData) + .then(() => + console.log( + `${module.name} updated with new data successfully!` + ) + ) + .catch(c); continue; } continue; } - await guild.commands.create(commandData).catch(c); - console.log( - "Guild Command created", - module.name!, - guild.name - ); + guild.commands + .create(commandData) + .then(() => + console.log( + "Guild Command created", + module.name!, + guild.name + ) + ) + .catch(c); } return controller.next(); } catch (e) { @@ -118,3 +140,9 @@ export const CommandTypeRaw = { [CommandType.MenuUser]: ApplicationCommandType.User, [CommandType.Slash]: ApplicationCommandType.ChatInput, } as const; + +interface PublishOptions { + guildIds: string[]; + defaultMemberPermissions: PermissionResolvable | null; + dmPermission: boolean; +}