From 50017c37cd1f9cdce9ff9be4ea48cde77b235c5a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 3 Jan 2023 15:16:26 +0530 Subject: [PATCH] chore: Update JavaScript plugins (#66) chore: update JavaScript plugins Co-authored-by: jacoobes --- JavaScript/requirePermission.js | 47 +++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/JavaScript/requirePermission.js b/JavaScript/requirePermission.js index 623ec93..25686ba 100644 --- a/JavaScript/requirePermission.js +++ b/JavaScript/requirePermission.js @@ -3,7 +3,7 @@ * * @author @Benzo-Fury [<@762918086349029386>] * @author @needhamgary [<@342314924804014081>] - * @version 1.1.0 + * @version 1.2.0 * @example * ```ts * import { requirePermission } from "../plugins/myPermCheck"; @@ -22,6 +22,9 @@ function payload(resp) { return { fetchReply: true, content: resp, + allowedMentions: { + repliedUser: false, + }, }; } @@ -42,32 +45,54 @@ export function requirePermission(target, perm, response) { return controller.stop(); } + const bot = await ctx.guild.members.fetchMe({ + cache: false, + }); + const memm = ctx.member; + switch (target) { + //*********************************************************************************************************************// case "bot": - if ( - !( - await ctx.guild.members.fetchMe({ - cache: false, - }) - ).permissions.has(perm) - ) { + if (!bot.permissions.has(perm)) { if (!response) - response = `I cannot use this command, please give me \`${perm}\` permission.`; + response = `I cannot use this command, please give me \`${perm.join( + ", " + )}\` permission(s).`; await ctx.reply(payload(response)); return controller.stop(); } return controller.next(); + //*********************************************************************************************************************// case "user": - if (!ctx.member.permissions.has(perm)) { + if (!memm.permissions.has(perm)) { if (!response) - response = `You cannot use this command because you are missing \`${perm}\` permission.`; + response = `You cannot use this command because you are missing \`${perm.join( + ", " + )}\` permission(s).`; await ctx.reply(payload(response)); return controller.stop(); } return controller.next(); + //*********************************************************************************************************************// + + case "both": + if ( + !bot.permissions.has(perm) || + !memm.permissions.has(perm) + ) { + if (!response) + response = `Please ensure <@${bot.user.id}> and <@${ + memm.user.id + }> both have \`${perm.join(", ")}\` permission(s).`; + await ctx.reply(payload(response)); + return controller.stop(); + } + + return controller.next(); + //*********************************************************************************************************************// default: console.warn(