mirror of
https://github.com/SrIzan10/awesome-plugins.git
synced 2026-05-01 10:35:27 +00:00
feat(TS): add dmonly plugin (#13)
This commit is contained in:
34
TypeScript/dmOnly.ts
Normal file
34
TypeScript/dmOnly.ts
Normal 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();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -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();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user