From 61c1605af20596777ca4ce32c1bdf604522060ba Mon Sep 17 00:00:00 2001 From: SrIzan10 <66965250+SrIzan10@users.noreply.github.com> Date: Fri, 3 Feb 2023 21:23:34 +0100 Subject: [PATCH] feat: update sern and bonzify --- commands/fun/makesweet.ts | 1 + commands/handlers/bonzify.ts | 27 ++++ index.ts | 3 +- package-lock.json | 52 +++---- package.json | 2 +- plugins/acceptingBirthday.ts | 134 +++++++++--------- plugins/ownerOnly.ts | 42 +++--- plugins/publish.ts | 256 ++++++++++++++++------------------- plugins/srIzanOnly.ts | 42 +++--- 9 files changed, 282 insertions(+), 277 deletions(-) create mode 100644 commands/handlers/bonzify.ts diff --git a/commands/fun/makesweet.ts b/commands/fun/makesweet.ts index 9df01e4..9c73869 100644 --- a/commands/fun/makesweet.ts +++ b/commands/fun/makesweet.ts @@ -18,6 +18,7 @@ export default commandModule({ type: CommandType.Slash, plugins: [publish()], //alias : [], + description: 'no one will read this (i hope)', options: [ { name: 'heartlocket', diff --git a/commands/handlers/bonzify.ts b/commands/handlers/bonzify.ts new file mode 100644 index 0000000..0431d2b --- /dev/null +++ b/commands/handlers/bonzify.ts @@ -0,0 +1,27 @@ +import { commandModule, CommandType } from '@sern/handler'; +import axios from 'axios'; +import { AttachmentBuilder, BufferResolvable } from 'discord.js'; +import { publish } from '../../plugins/publish.js'; +import { Readable } from 'node:stream' + +export default commandModule({ + type: CommandType.CtxMsg, + plugins: [publish()], + execute: async (ctx) => { + await ctx.deferReply() + + const text = ctx.targetMessage.content; + const encodedText = encodeURIComponent(text); + const url = `https://www.tetyys.com/SAPI4/SAPI4?text=${encodedText}&voice=Adult%20Male%20%232%2C%20American%20English%20(TruVoice)&pitch=140&speed=157`; + + const request = await fetch(url).then(res => res.arrayBuffer()) + const stream = new Readable(); + stream._read = () => {}; + stream.push(Buffer.from(new Uint8Array(request))); + stream.push(null) + + const attachment = new AttachmentBuilder(stream, { name: 'bonzied.wav' }) + + await ctx.editReply({ files: [attachment] }) + }, +}); \ No newline at end of file diff --git a/index.ts b/index.ts index a64aee7..6846f90 100644 --- a/index.ts +++ b/index.ts @@ -41,10 +41,11 @@ interface MyDependencies extends Dependencies { '@sern/client' : Singleton; '@sern/logger' : Singleton } + export const useContainer = Sern.makeDependencies({ build: root => root .add({ '@sern/client': single(client) }) - .add({ '@sern/logger': single(new DefaultLogging()) }) + .upsert({ '@sern/logger': single(new DefaultLogging()) }) }); Sern.init({ commands: 'dist/commands', diff --git a/package-lock.json b/package-lock.json index d3cda42..1c9cd38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@discordjs/opus": "^0.9.0", "@discordjs/voice": "^0.14.0", "@napi-rs/canvas": "^0.1.30", - "@sern/handler": "^2.1.1", + "@sern/handler": "^2.5.0", "axios": "^1.1.3", "country-flag-emoji": "^1.0.3", "dayjs": "^1.11.6", @@ -494,13 +494,13 @@ } }, "node_modules/@sern/handler": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@sern/handler/-/handler-2.1.1.tgz", - "integrity": "sha512-yPWOgUvi+9et6fC2BxLyIes5zvOLgorXdpLmI84cN7K7NVpYA/kRj2Y0aqriYb2fOdlPeakptODJwabwDSBfZw==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@sern/handler/-/handler-2.5.0.tgz", + "integrity": "sha512-EU80KPWgAaX3xCId3qUlwDKxLJnTH4abCHBqPVkq04IL1xqPFO91HeU+vhQ6/HJxS+MOqqli1NO6T3lTcOESXQ==", "dependencies": { - "iti": "^0.5.0", + "iti": "^0.6.0", "rxjs": "^7.5.6", - "ts-pattern": "^4.0.2", + "ts-pattern": "^4.0.6", "ts-results-es": "^3.5.0" } }, @@ -1790,8 +1790,9 @@ } }, "node_modules/http-cache-semantics": { - "version": "4.1.0", - "license": "BSD-2-Clause" + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", + "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==" }, "node_modules/http-errors": { "version": "2.0.0", @@ -1921,9 +1922,9 @@ "dev": true }, "node_modules/iti": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/iti/-/iti-0.5.0.tgz", - "integrity": "sha512-ZiwdEIhXAxyb6/+j2didONRa3q73y9h8oHMRXAIkXv7k851cm8H7fyZZyszr514TdzgoVQl7Z6hvsdTogjgc0w==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/iti/-/iti-0.6.0.tgz", + "integrity": "sha512-JqujcnAIF3pmzitjbT3acc0LkordU6oHBDvWeT6a25wvEVBddFX3DFx/p6YBwGX1TTFsyLgVZtwhGOknthC96A==", "dependencies": { "utility-types": "^3.10.0" }, @@ -3190,8 +3191,9 @@ "dev": true }, "node_modules/ts-pattern": { - "version": "4.0.5", - "license": "MIT" + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-4.1.3.tgz", + "integrity": "sha512-8beXMWTGEv1JfDjSxfNhe4uT5jKYdhmEUKzt4gZW9dmHlquq3b+IbEyA7vX9LjBfzHmvKnM4HiomAUCyaW2Pew==" }, "node_modules/ts-results-es": { "version": "3.5.0", @@ -3696,13 +3698,13 @@ "integrity": "sha512-zZxymtVO6zeXVMPds+6d7gv/OfnCc25M1Z+7ZLB0oPmeMTPeRWVPQSS16oDJy5ZsyCOLj7M6mbZml5gWXcVRNw==" }, "@sern/handler": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@sern/handler/-/handler-2.1.1.tgz", - "integrity": "sha512-yPWOgUvi+9et6fC2BxLyIes5zvOLgorXdpLmI84cN7K7NVpYA/kRj2Y0aqriYb2fOdlPeakptODJwabwDSBfZw==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@sern/handler/-/handler-2.5.0.tgz", + "integrity": "sha512-EU80KPWgAaX3xCId3qUlwDKxLJnTH4abCHBqPVkq04IL1xqPFO91HeU+vhQ6/HJxS+MOqqli1NO6T3lTcOESXQ==", "requires": { - "iti": "^0.5.0", + "iti": "^0.6.0", "rxjs": "^7.5.6", - "ts-pattern": "^4.0.2", + "ts-pattern": "^4.0.6", "ts-results-es": "^3.5.0" } }, @@ -4632,7 +4634,9 @@ } }, "http-cache-semantics": { - "version": "4.1.0" + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", + "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==" }, "http-errors": { "version": "2.0.0", @@ -4715,9 +4719,9 @@ "dev": true }, "iti": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/iti/-/iti-0.5.0.tgz", - "integrity": "sha512-ZiwdEIhXAxyb6/+j2didONRa3q73y9h8oHMRXAIkXv7k851cm8H7fyZZyszr514TdzgoVQl7Z6hvsdTogjgc0w==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/iti/-/iti-0.6.0.tgz", + "integrity": "sha512-JqujcnAIF3pmzitjbT3acc0LkordU6oHBDvWeT6a25wvEVBddFX3DFx/p6YBwGX1TTFsyLgVZtwhGOknthC96A==", "requires": { "utility-types": "^3.10.0" } @@ -5549,7 +5553,9 @@ } }, "ts-pattern": { - "version": "4.0.5" + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-4.1.3.tgz", + "integrity": "sha512-8beXMWTGEv1JfDjSxfNhe4uT5jKYdhmEUKzt4gZW9dmHlquq3b+IbEyA7vX9LjBfzHmvKnM4HiomAUCyaW2Pew==" }, "ts-results-es": { "version": "3.5.0" diff --git a/package.json b/package.json index c5c6990..828e097 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@discordjs/opus": "^0.9.0", "@discordjs/voice": "^0.14.0", "@napi-rs/canvas": "^0.1.30", - "@sern/handler": "^2.1.1", + "@sern/handler": "^2.5.0", "axios": "^1.1.3", "country-flag-emoji": "^1.0.3", "dayjs": "^1.11.6", diff --git a/plugins/acceptingBirthday.ts b/plugins/acceptingBirthday.ts index a2a1bd2..59b0a74 100644 --- a/plugins/acceptingBirthday.ts +++ b/plugins/acceptingBirthday.ts @@ -1,4 +1,4 @@ -// @ts-nocheck +//@ts-nocheck /** * This is buttonConfirmation plugin, it runs confirmation prompt in the form of buttons. * Note that you need to use edit/editReply in the command itself because we are already replying in the plugin! @@ -19,7 +19,7 @@ * ``` */ -import { CommandType, EventPlugin, PluginType } from "@sern/handler"; +import { CommandControlPlugin, CommandType, controller } from "@sern/handler"; import { ActionRowBuilder, ButtonBuilder, @@ -27,81 +27,75 @@ import { ComponentType, } from "discord.js"; -export function acceptingBirthday( - options?: Partial -): EventPlugin { - return { - type: PluginType.Event, - description: "Confirms", - async execute([ctx], controller) { - options = { - content: "Se va a guardar tu cumpleaños en la base de datos de Vinci.\nAceptas?", - denialMessage: "Ok pues...", - labels: ["No", "Sí"], - time: 60_000, - wrongUserResponse: "Esto no es para tí!", - ...options, - }; +export function acceptingBirthday(options?: Partial) { + return CommandControlPlugin(async (ctx, args) => { + options = { + content: "Se va a guardar tu cumpleaños en la base de datos de Vinci.\nAceptas?", + denialMessage: "Ok pues...", + labels: ["No", "Sí"], + time: 60_000, + wrongUserResponse: "Esto no es para tí!", + ...options, + }; - const buttons = options.labels!.map((l, i) => { - return new ButtonBuilder() - .setCustomId(l) - .setLabel(l) - .setStyle( - i === 0 ? ButtonStyle.Danger : ButtonStyle.Success - ); - }); - const sent = await ctx.reply({ - content: options.content, - components: [ - new ActionRowBuilder().setComponents( - buttons - ), - ], - ephemeral: true - }); + const buttons = options.labels!.map((l, i) => { + return new ButtonBuilder() + .setCustomId(l) + .setLabel(l) + .setStyle( + i === 0 ? ButtonStyle.Danger : ButtonStyle.Success + ); + }); + const sent = await ctx.reply({ + content: options.content, + components: [ + new ActionRowBuilder().setComponents( + buttons + ), + ], + ephemeral: true + }); - const collector = sent.createMessageComponentCollector({ - componentType: ComponentType.Button, - filter: (i) => i.user.id === ctx.user.id, - time: options.time, - }); + const collector = sent.createMessageComponentCollector({ + componentType: ComponentType.Button, + filter: (i) => i.user.id === ctx.user.id, + time: options.time, + }); - return new Promise((resolve) => { - collector.on("collect", async (i) => { - await i.update({ components: [] }); - collector.stop(); - if (i.customId === options!.labels![1]) { - resolve(controller.next()); - return; - } - await i.editReply({ - content: options?.denialMessage, - }); - resolve(controller.stop()); + return new Promise((resolve) => { + collector.on("collect", async (i) => { + await i.update({ components: [] }); + collector.stop(); + if (i.customId === options!.labels![1]) { + resolve(controller.next()); + return; + } + await i.editReply({ + content: options?.denialMessage, }); + resolve(controller.stop()); + }); - collector.on("end", async (c) => { - if (c.size) return; - buttons.forEach((b) => b.setDisabled()); - await sent.edit({ - components: [ - new ActionRowBuilder().setComponents( - buttons - ), - ], - }); - }); - - collector.on("ignore", async (i) => { - await i.reply({ - content: options?.wrongUserResponse, - ephemeral: true, - }); + collector.on("end", async (c) => { + if (c.size) return; + buttons.forEach((b) => b.setDisabled()); + await sent.edit({ + components: [ + new ActionRowBuilder().setComponents( + buttons + ), + ], }); }); - }, - }; + + collector.on("ignore", async (i) => { + await i.reply({ + content: options?.wrongUserResponse, + ephemeral: true, + }); + }); + }); + }); } interface ConfirmationOptions { diff --git a/plugins/ownerOnly.ts b/plugins/ownerOnly.ts index 5ff6ce3..a8b6809 100644 --- a/plugins/ownerOnly.ts +++ b/plugins/ownerOnly.ts @@ -1,31 +1,29 @@ // @ts-nocheck /** - * @author: @EvolutionX-10 - * @version: 1.0.0 - * @description: This is OwnerOnly plugin, it allows only bot owners to run the command, like eval. - * @license: MIT - * @example: + * This is OwnerOnly plugin, it allows only bot owners to run the command, like eval. + * + * @author @EvolutionX-10 [<@697795666373640213>] + * @version 1.0.0 + * @example * ```ts - * import { OwnerOnly } from "../path/to/your/plugin/folder"; - * import { sernModule, CommandType } from "@sern/handler"; - * export default sernModule([OwnerOnly()], { - * // your code + * import { ownerOnly } from "../plugins/ownerOnly"; + * import { commandModule } from "@sern/handler"; + * export default commandModule({ + * plugins: [ ownerOnly() ], + * execute: (ctx) => { + * //your code here + * } * }) * ``` */ -import { CommandType, EventPlugin, PluginType } from "@sern/handler"; +import { CommandType, CommandControlPlugin, controller } from "@sern/handler"; const ownerIDs = ["464397024247152640", "703974042700611634", '252679156465139722', '370918560446545922', '375984365181599744', '785836117630910485', '368107342140801025']; //! Fill your ID -export function ownerOnly(): EventPlugin { - return { - type: PluginType.Event, - description: "Allows only bot owner to run command", - async execute(event, controller) { - const [ctx] = event; - if (ownerIDs.includes(ctx.user.id)) return controller.next(); - //* If you want to reply when the command fails due to user not being owner, you can use following - await ctx.reply("**ERROR**: Sólo los administradores pueden correr este comando."); - return controller.stop(); //! Important: It stops the execution of command! - }, - }; +export function ownerOnly() { + return CommandControlPlugin((ctx, args) => { + if (ownerIDs.includes(ctx.user.id)) return controller.next(); + //* If you want to reply when the command fails due to user not being owner, you can use following + ctx.reply("**ERROR**: Sólo los administradores pueden correr este comando."); + return controller.stop(); //! Important: It stops the execution of command! + }); } diff --git a/plugins/publish.ts b/plugins/publish.ts index 95a4a97..295898a 100644 --- a/plugins/publish.ts +++ b/plugins/publish.ts @@ -18,9 +18,9 @@ * ``` */ import { - CommandPlugin, + CommandInitPlugin, CommandType, - PluginType, + controller, SernOptionsData, SlashCommand, } from "@sern/handler"; @@ -29,148 +29,133 @@ import { ApplicationCommandType, PermissionResolvable, } from "discord.js"; -/** - * This is the dependency getter that is created from Sern.makeDependencies. - * import it here so that this plugin has access to your bot's dependencies - */ import { useContainer } from "../index.js"; -export function publish( - options?: PublishOptions -): CommandPlugin< - | CommandType.Slash - | CommandType.Both - | CommandType.CtxUser - | CommandType.CtxMsg -> { - return { - type: PluginType.Command, - description: "Manage Application Commands", - name: "slash-auto-publish", - async execute({ mod: module }, controller) { - // Users need to provide their own useContainer function. - const [client] = useContainer("@sern/client"); - const defaultOptions = { - guildIds: [], - dmPermission: undefined, - defaultMemberPermissions: null, - }; +export const CommandTypeRaw = { + [CommandType.Both]: ApplicationCommandType.ChatInput, + [CommandType.CtxUser]: ApplicationCommandType.User, + [CommandType.CtxMsg]: ApplicationCommandType.Message, + [CommandType.Slash]: ApplicationCommandType.ChatInput, +} as const; - options = { ...defaultOptions, ...options } as PublishOptions & - ValidPublishOptions; - let { defaultMemberPermissions, dmPermission, guildIds } = - options as unknown as ValidPublishOptions; +export function publish< + T extends + | CommandType.Both + | CommandType.Slash + | CommandType.CtxMsg + | CommandType.CtxUser +>(options?: PublishOptions) { + return CommandInitPlugin(async ({ module }) => { + // Users need to provide their own useContainer function. + const [client] = useContainer("@sern/client"); + const defaultOptions = { + guildIds: [], + dmPermission: undefined, + defaultMemberPermissions: null, + }; - function c(e: unknown) { - console.error("publish command didnt work for", module.name); - console.error(e); + options = { ...defaultOptions, ...options } as PublishOptions & + ValidPublishOptions; + let { defaultMemberPermissions, dmPermission, guildIds } = + options as unknown as ValidPublishOptions; + + function c(e: unknown) { + console.error("publish command didnt work for", module.name); + console.error(e); + } + + const log = + (...message: any[]) => + () => + console.log(...message); + const logged = (...message: any[]) => log(message); + /** + * a local function that returns either one value or the other, + * depending on {t}'s CommandType. If the commandtype of + * this module is CommandType.Both or CommandType.Text or CommandType.Slash, + * return 'is', else return 'els' + * @param t + * @returns S | T + */ + const appCmd = (t: V) => { + return (is: S, els: T) => ((t & CommandType.Both) !== 0 ? is : els); + }; + const curAppType = CommandTypeRaw[module.type]; + const createCommandData = () => { + const cmd = appCmd(module.type); + return { + name: module.name, + type: curAppType, + description: cmd(module.description, ""), + options: cmd( + optionsTransformer((module as SlashCommand).options ?? []), + [] + ), + defaultMemberPermissions, + dmPermission, + } as ApplicationCommandData; + }; + + try { + const commandData = createCommandData(); + + if (!guildIds.length) { + const cmd = (await client.application!.commands.fetch()).find( + (c) => c.name === module.name && c.type === curAppType + ); + if (cmd) { + if (!cmd.equals(commandData, true)) { + logged( + `Found differences in global command ${module.name}` + ); + cmd.edit(commandData).then( + log( + `${module.name} updated with new data successfully!` + ) + ); + } + return controller.next(); + } + client + .application!.commands.create(commandData) + .then(log("Command created", module.name)) + .catch(c); + return controller.next(); } - const log = - (...message: any[]) => - () => - console.log(...message); - const logged = (...message: any[]) => log(message); - /** - * a local function that returns either one value or the other, - * depending on {t}'s CommandType. If the commandtype of - * this module is CommandType.Both or CommandType.Text or CommandType.Slash, - * return 'is', else return 'els' - * @param t - * @returns S | T - */ - const appCmd = (t: V) => { - return (is: S, els: T) => - (t & CommandType.Both) !== 0 ? is : els; - }; - const curAppType = CommandTypeRaw[module.type]; - const createCommandData = () => { - const cmd = appCmd(module.type); - return { - name: module.name, - type: curAppType, - description: cmd(module.description, ""), - options: cmd( - optionsTransformer( - (module as SlashCommand).options ?? [] - ), - [] - ), - defaultMemberPermissions, - dmPermission, - } as ApplicationCommandData; - }; - try { - const commandData = createCommandData(); - - if (!guildIds.length) { - const cmd = ( - await client.application!.commands.fetch() - ).find( - (c) => c.name === module.name && c.type === curAppType - ); - if (cmd) { - if (!cmd.equals(commandData, true)) { - logged( - `Found differences in global command ${module.name}` - ); - cmd.edit(commandData).then( + for (const id of guildIds) { + const guild = await client.guilds.fetch(id).catch(c); + if (!guild) continue; + const guildCmd = (await guild.commands.fetch()).find( + (c) => c.name === module.name && c.type === curAppType + ); + if (guildCmd) { + if (!guildCmd.equals(commandData, true)) { + logged(`Found differences in command ${module.name}`); + guildCmd + .edit(commandData) + .then( log( `${module.name} updated with new data successfully!` ) - ); - } - return controller.next(); - } - client - .application!.commands.create(commandData) - .then(log("Command created", module.name)) - .catch(c); - return controller.next(); - } - - for (const id of guildIds) { - const guild = await client.guilds.fetch(id).catch(c); - if (!guild) continue; - const guildCmd = (await guild.commands.fetch()).find( - (c) => c.name === module.name && c.type === curAppType - ); - if (guildCmd) { - if (!guildCmd.equals(commandData, true)) { - logged( - `Found differences in command ${module.name}` - ); - guildCmd - .edit(commandData) - .then( - log( - `${module.name} updated with new data successfully!` - ) - ) - .catch(c); - continue; - } + ) + .catch(c); continue; } - guild.commands - .create(commandData) - .then( - log( - "Guild Command created", - module.name, - guild.name - ) - ) - .catch(c); + continue; } - return controller.next(); - } catch (e) { - logged("Command did not register" + module.name); - logged(e); - return controller.stop(); + guild.commands + .create(commandData) + .then(log("Guild Command created", module.name, guild.name)) + .catch(c); } - }, - }; + return controller.next(); + } catch (e) { + logged("Command did not register" + module.name); + logged(e); + return controller.stop(); + } + }); } export function optionsTransformer(ops: Array) { @@ -179,13 +164,6 @@ export function optionsTransformer(ops: Array) { ); } -export const CommandTypeRaw = { - [CommandType.Both]: ApplicationCommandType.ChatInput, - [CommandType.CtxUser]: ApplicationCommandType.Message, - [CommandType.CtxMsg]: ApplicationCommandType.User, - [CommandType.Slash]: ApplicationCommandType.ChatInput, -} as const; - export type NonEmptyArray = [T, ...T[]]; export interface ValidPublishOptions { @@ -193,11 +171,13 @@ export interface ValidPublishOptions { dmPermission: boolean; defaultMemberPermissions: PermissionResolvable; } + interface GuildPublishOptions { guildIds?: NonEmptyArray; defaultMemberPermissions?: PermissionResolvable; dmPermission?: never; } + interface GlobalPublishOptions { defaultMemberPermissions?: PermissionResolvable; dmPermission?: false; diff --git a/plugins/srIzanOnly.ts b/plugins/srIzanOnly.ts index d6d296f..e3ee7f9 100644 --- a/plugins/srIzanOnly.ts +++ b/plugins/srIzanOnly.ts @@ -1,31 +1,29 @@ // @ts-nocheck /** - * @author: @EvolutionX-10 - * @version: 1.0.0 - * @description: This is OwnerOnly plugin, it allows only bot owners to run the command, like eval. - * @license: MIT - * @example: + * This is OwnerOnly plugin, it allows only bot owners to run the command, like eval. + * + * @author @EvolutionX-10 [<@697795666373640213>] + * @version 1.0.0 + * @example * ```ts - * import { OwnerOnly } from "../path/to/your/plugin/folder"; - * import { sernModule, CommandType } from "@sern/handler"; - * export default sernModule([OwnerOnly()], { - * // your code + * import { ownerOnly } from "../plugins/ownerOnly"; + * import { commandModule } from "@sern/handler"; + * export default commandModule({ + * plugins: [ ownerOnly() ], + * execute: (ctx) => { + * //your code here + * } * }) * ``` */ -import { CommandType, EventPlugin, PluginType } from "@sern/handler"; +import { CommandType, CommandControlPlugin, controller } from "@sern/handler"; const ownerIDs = ['703974042700611634']; //! Fill your ID -export function srIzanOnly(): EventPlugin { - return { - type: PluginType.Event, - description: "Allows only bot owner to run command", - async execute(event, controller) { - const [ctx] = event; - if (ownerIDs.includes(ctx.user.id)) return controller.next(); - //* If you want to reply when the command fails due to user not being owner, you can use following - await ctx.reply("**ERROR**: Sólo Sr Izan puede correr este comando."); - return controller.stop(); //! Important: It stops the execution of command! - }, - }; +export function srIzanOnly() { + return CommandControlPlugin((ctx, args) => { + if (ownerIDs.includes(ctx.user.id)) return controller.next(); + //* If you want to reply when the command fails due to user not being owner, you can use following + ctx.reply("**ERROR**: Sólo Sr Izan puede correr este comando."); + return controller.stop(); //! Important: It stops the execution of command! + }); }