From e3526750d249b796a3a4bcd1114e518fb21407ad Mon Sep 17 00:00:00 2001 From: George Needham <34216187+D3ord3NidAm@users.noreply.github.com> Date: Sat, 24 Sep 2022 12:53:16 -0500 Subject: [PATCH] feat: add TS devOnlyServer plugin (#42) * feat: add TS devOnlyServer plugin This plugin will send an error message when the command is ran outside of the specified guild id(s). If there is no `perFail` message provided, the code will provide an error. * feat: edit devServerOnly plugin EDIT: Checks if the fail message exists. * refactor: changed name of plugin Changed name of plugin devOnlyServer.ts to serverOnly.ts * refactor: changed name of plugin on sample command Forgot to change name of plugin on the sample command during previous refactor. * refactor: update default failMessage parameter. Correct default fail message. --- TypeScript/serverOnly.ts | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 TypeScript/serverOnly.ts diff --git a/TypeScript/serverOnly.ts b/TypeScript/serverOnly.ts new file mode 100644 index 0000000..ac383fc --- /dev/null +++ b/TypeScript/serverOnly.ts @@ -0,0 +1,43 @@ +// @ts-nocheck +/** + * Checks if a command is available in a specific server. + * + * @author @D3ord3NidAm [<@1017182455926624316>] + * @version 1.0.0 + * @example + * ```ts + * import { commandModule, CommandType } from "@sern/handler"; + * import { serverOnly } from "../plugins/serverOnly"; + * export default commandModule({ + * type: CommandType.Both, + * plugins: [serverOnly(["guildId"], failMessage)], // fail message is the message you will see when the command is ran in the wrong server. + * description: "command description", + * execute: async (ctx, args) => { + * // your code here + * }, + * }); + * ``` + */ + +import { CommandType, EventPlugin, PluginType } from "@sern/handler"; + +export function serverOnly( + guildId: string[], + failMessage = "I am unable to comply with your command." +): EventPlugin { + return { + type: PluginType.Event, + description: "Checks if a command is available in a specific server.", + async execute([ctx, args], controller) { + if (!guildId.includes(ctx.guildId)) { + await ctx.reply(failMessage).then(async (m) => { + setTimeout(async () => { + await m.delete(); + }, 3000); + }); + return controller.stop(); + } + return controller.next(); + }, + }; +}