Permissions Plugin

This plugin is included in the library, and adds a whole custom permission system to the above commands handler. This plugin is called `Mongoose Permissions` since it uses mongoose internally

Requirements

What does this plugin do:

This plugin changes the default method that filters commands by permission and replaces it with a method that also checks a mongoDB collection named djs-cc-permissions which will automatically be created the first time you assign a permission to someone. The plugin also adds a category called permissions to the command handler that contains two commands addperm and removeperm which allows you to give and remove permissions to and from a user by their ID, so they do not need to share a guild with you.

Usage

Setup

Assuming you already have mongoose set up

// Let's assume you already have you djs-command-control instanciated
// and saved in a variable called `commands`.
// Let's also assume you have mongoose instantiated and connected

// So now we need to fetch the plugin builder
const { MongoosePermissions } = require("djs-command-mongo");

// Now let's get the plugin to import
const permissionsPlugin = MongoosePermissions(mongoose, // Passing our mongoose connection
    {
        // The ID of the root user, this person can use any
        // command on any server regardless of their permission level
        rootAccount: process.env.ROOT_ACCOUNT_ID,
        // Next is an array of all the custom permissions you want
        permissions: ["DEV", "ADMIN", "MOD"],
        // Next is optional mongo options of `MongoClientOptions` Type
        mongoOptions: {}
    });
    
// Finally we need to add the plugin to the command handler
commands.addPlugin(permissionsPlugin);

Assuming you do not already have a mongoose instance

// Let's assume you already have you djs-command-control instanciated
// and saved in a variable called `commands`.
// Let's also assume you have your mongoDB URI in a variable called `mongoURI`

// So now we need to fetch the plugin builder
const { MongoosePermissions } = require("djs-command-mongo");

// Now let's get the plugin to import
const permissionsPlugin = MongoosePermissions(mongoURI, // Passing our Mongo URI of type String
    {
        // The ID of the root user, this person can use any
        // command on any server regardless of their permission level
        rootAccount: process.env.ROOT_ACCOUNT_ID,
        // Next is an array of all the custom permissions you want
        permissions: ["DEV", "ADMIN", "MOD"],
        // Next is optional mongo options of `MongoClientOptions` Type
        mongoOptions: {}
    });
    
// Finally we need to add the plugin to the command handler
commands.addPlugin(permissionsPlugin);

Thats it!

Now you should see a category called "Permission Management" in your help command, and you should be able to assign any of the custom permissions you passed to the creater to any person, and any command!

Limitations:

  • This can not work with any other plugin that overwrites client.djsCommandControl.FilterCommands.byPermission

Useful to know

  1. The mongoose model can by required like this:

const Permissions = require("djs-command-mongo/lib/models/Permissions").default

Last updated