diff --git a/TypeScript/dmOnly.ts b/TypeScript/dmOnly.ts new file mode 100644 index 0000000..934b937 --- /dev/null +++ b/TypeScript/dmOnly.ts @@ -0,0 +1,34 @@ +// @ts-nocheck +/** + * @author: @EvolutionX-10 + * @version: 1.1.0-beta + * @description: This is dmOnly plugin, it allows commands to be run only in DMs. + * @requires `partials: [Partials.Channel], intents: [GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent] + * @license: MIT + * @example: + * ```ts + * import { dmOnly } from "../path/to/your/plugin/folder"; + * import { commandModule } from "@sern/handler"; + * export default commandModule({ + * plugins: [dmOnly()], + * execute: // your code + * }) + * ``` + */ +import { CommandType, EventPlugin, PluginType } from "@sern/handler"; +export function dmOnly( + content?: string, + ephemeral?: boolean +): EventPlugin { + return { + type: PluginType.Event, + description: "Allows commands to be run in DM only", + async execute(event, controller) { + const [ctx] = event; + if (ctx.channel?.isDMBased()) return controller.next(); + + if (content) await ctx.reply({ content, ephemeral }); // Change this if you want or remove it for silent deny + return controller.stop(); + }, + }; +} diff --git a/TypeScript/permCheck.ts b/TypeScript/permCheck.ts index 93dd0a8..374af15 100644 --- a/TypeScript/permCheck.ts +++ b/TypeScript/permCheck.ts @@ -1,45 +1,50 @@ -// @ts-nocheck -/** - * @author: @NeoYaBoi - * @version: 1.0.0 - * @description: This is perm check, it allows users to parse the permission you want and let the plugin do the rest. (check user for that perm). - * @license: Null - * @example: - * ```ts - * import { permCheck } from "../plugins/permCheck"; //(change if need be) - * import { sernModule, CommandType } from "@sern/handler"; - * export default commandModule({ - * plugins: [ permCheck('permission', 'Response Here') ], - * execute: (ctx) => { - * //your code here - * } - * }) - * ``` - */ - -import { PermissionResolvable, type GuildMember } from "discord.js"; -import { CommandType, EventPlugin, PluginType } from "@sern/handler"; -export function permCheck(perm: PermissionResolvable, response: string): EventPlugin { - return { - type: PluginType.Event, - description: "Checks for specified perm", - async execute(event, controller) { - const [ctx] = event; - if(ctx.guild == null) { - ctx.reply('This command cannot be used here') - console.warn('A command stopped because we couldn\'t check there permissions (was used in dms)') //delete this line if you dont was to be notified when a command is used outside of a guild/server - return controller.stop() - } - if(!(ctx.member! as GuildMember).permissions.has(perm)) { - try { - await ctx.reply(response) - return controller.stop() - } catch { - ctx.reply("You do not have the required permissions") - return controller.stop() - } - } - return controller.next() - }, - }; -} +// @ts-nocheck +/** + * @author: @NeoYaBoi + * @version: 1.0.0 + * @description: This is perm check, it allows users to parse the permission you want and let the plugin do the rest. (check user for that perm). + * @license: Null + * @example: + * ```ts + * import { permCheck } from "../plugins/permCheck"; //(change if need be) + * import { sernModule, CommandType } from "@sern/handler"; + * export default commandModule({ + * plugins: [ permCheck('permission', 'Response Here') ], + * execute: (ctx) => { + * //your code here + * } + * }) + * ``` + */ + +import { PermissionResolvable, type GuildMember } from "discord.js"; +import { CommandType, EventPlugin, PluginType } from "@sern/handler"; +export function permCheck( + perm: PermissionResolvable, + response: string +): EventPlugin { + return { + type: PluginType.Event, + description: "Checks for specified perm", + async execute(event, controller) { + const [ctx] = event; + if (ctx.guild == null) { + ctx.reply("This command cannot be used here"); + console.warn( + "A command stopped because we couldn't check there permissions (was used in dms)" + ); //delete this line if you dont was to be notified when a command is used outside of a guild/server + return controller.stop(); + } + if (!(ctx.member! as GuildMember).permissions.has(perm)) { + try { + await ctx.reply(response); + return controller.stop(); + } catch { + ctx.reply("You do not have the required permissions"); + return controller.stop(); + } + } + return controller.next(); + }, + }; +} diff --git a/TypeScript/publish.ts b/TypeScript/publish.ts index 0c24dd5..078eb4a 100644 --- a/TypeScript/publish.ts +++ b/TypeScript/publish.ts @@ -28,7 +28,7 @@ export function publish( type: PluginType.Command, description: "Manage Slash Commands", name: "slash-auto-publish", - async execute({ client }, { absPath , mod: module }, controller) { + async execute({ client }, { absPath, mod: module }, controller) { function c(e: unknown) { console.error("publish command didnt work for", module.name!); console.error(e);