ghostdevv / jellycommands

A command handler for Discord.js
https://jellycommands.dev
Other
20 stars 5 forks source link

Client side permission checking #37

Open ghostdevv opened 2 years ago

ghostdevv commented 2 years ago

Describe the feature

Currently in jelly we expose guards which uses the application command permission system, while this permission system is functional it's currently very limited. I want to explore two options:

Examples

1.

export default command({
   guards: {
       validate: ({ interaction }) => {
          return true; // Wants a truthy response to be allowed and falsy to be disallowed
       }
   }
})

2.

export default command({
  guards: {
     mode: 'whitelist',

      local: {
         roleNames: ['support']
      }
  }
})
cainthebest commented 1 year ago

Possible solution

    /**
     * Guards allow you to prevent/allow certain people/groups to your command
     */
    guards?: {
        /**
         * The permissions a member must have to run this command
         *
         * Works in the sense of a whitelist
         */
        permissions?: PermissionResolvable;

        /**
         * Role specific permissions
         *
         * Allows the use of a whitelist or blacklist
         *
         * ? Possible overide for local, if no guildId is provided assume role is a role id.
         * ? if a guild id is not provided and the role is just a role name you could bypass
         * ? guard by just having a role with the same name in another guild
         */
        local?: [{ role: string[]; mode: 'whitelist' | 'blacklist'; guildId?: string }];

        /**
         * A Custom guard function that returns a boolean
         *
         * If the function returns true the command will run
         */
        custom?: (interaction: any) => boolean;
    };

note: would guards have hierarchy (eg: would a local whitelist override a discord perm) or would it be X && Y && Z