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

1
// Let's assume you already have you djs-command-control instanciated
2
// and saved in a variable called `commands`.
3
// Let's also assume you have mongoose instantiated and connected
4
5
// So now we need to fetch the plugin builder
6
const { MongoosePermissions } = require("djs-command-mongo");
7
8
// Now let's get the plugin to import
9
const permissionsPlugin = MongoosePermissions(mongoose, // Passing our mongoose connection
10
{
11
// The ID of the root user, this person can use any
12
// command on any server regardless of their permission level
13
rootAccount: process.env.ROOT_ACCOUNT_ID,
14
// Next is an array of all the custom permissions you want
15
permissions: ["DEV", "ADMIN", "MOD"],
16
// Next is optional mongo options of `MongoClientOptions` Type
17
mongoOptions: {}
18
});
19
20
// Finally we need to add the plugin to the command handler
21
commands.addPlugin(permissionsPlugin);
Copied!

Assuming you do not already have a mongoose instance

1
// Let's assume you already have you djs-command-control instanciated
2
// and saved in a variable called `commands`.
3
// Let's also assume you have your mongoDB URI in a variable called `mongoURI`
4
5
// So now we need to fetch the plugin builder
6
const { MongoosePermissions } = require("djs-command-mongo");
7
8
// Now let's get the plugin to import
9
const permissionsPlugin = MongoosePermissions(mongoURI, // Passing our Mongo URI of type String
10
{
11
// The ID of the root user, this person can use any
12
// command on any server regardless of their permission level
13
rootAccount: process.env.ROOT_ACCOUNT_ID,
14
// Next is an array of all the custom permissions you want
15
permissions: ["DEV", "ADMIN", "MOD"],
16
// Next is optional mongo options of `MongoClientOptions` Type
17
mongoOptions: {}
18
});
19
20
// Finally we need to add the plugin to the command handler
21
commands.addPlugin(permissionsPlugin);
Copied!

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:
1
const Permissions = require("djs-command-mongo/lib/models/Permissions").default
Copied!
Last modified 4mo ago