mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 14:13:02 -04:00
- properly handle permissions for user commands
- add central permission group constant
This commit is contained in:
parent
dcb823a0a1
commit
d2aeecf70d
100 changed files with 245 additions and 942 deletions
|
@ -1,18 +1,31 @@
|
|||
const { MessageFlags, InteractionCallbackTypes } = require("detritus-client/lib/constants")
|
||||
|
||||
const { Context } = require("detritus-client/lib/command")
|
||||
const { InteractionContext } = require("detritus-client/lib/interaction")
|
||||
const { InteractionContext } = require("detritus-client/lib/interaction");
|
||||
const { PERMISSION_GROUPS, INCOGNITO_REASONS } = require("#constants");
|
||||
|
||||
/**
|
||||
* Acknowledges a command or interaction.
|
||||
* @param { InteractionContext|Context } context Command/interaction context
|
||||
* @param { boolean } incognito Specifies if the interaction should run privately (only applicable for interactions)
|
||||
* @param { Array } permissions Array of permissions that are required to execute this command
|
||||
*/
|
||||
module.exports.acknowledge = async function(context, incognito = false){
|
||||
module.exports.acknowledge = async function(context, incognito = false, permissions = [...PERMISSION_GROUPS.baseline_slash]){
|
||||
// Interaction flow
|
||||
if(context.editOrRespond){
|
||||
if(!context._meta) context._meta = {};
|
||||
|
||||
// Handle permissions for user commands in a guild context
|
||||
if(context.member && permissions.length >= 1){
|
||||
for(const p of permissions){
|
||||
if(!context.member.can(p)){
|
||||
incognito = true;
|
||||
context._meta.incognitoReason = INCOGNITO_REASONS.permissions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(incognito){
|
||||
if(!context._meta) context._meta = {};
|
||||
context._meta.isIncognito = true;
|
||||
return await context.respond({data: { flags: MessageFlags.EPHEMERAL }, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue