feat(TS): add dmonly plugin (#13)

This commit is contained in:
Evo
2022-07-28 13:02:41 +05:30
committed by GitHub
parent d292919905
commit 8c426a3f06
3 changed files with 85 additions and 46 deletions

34
TypeScript/dmOnly.ts Normal file
View File

@@ -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<CommandType.Both> {
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();
},
};
}

View File

@@ -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<CommandType.Both> {
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<CommandType.Both> {
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();
},
};
}

View File

@@ -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);