Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

A simple command parser for discord.js - rewrote version of discordjs-cmds

License

Notifications You must be signed in to change notification settings

zekro-archive/discordjs-cmds2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

~ discordjs-cmds2 ~

Command parser framework for discord.js - rewrote version of discordjs-cmds

 


npm i discordjs-cmds2


Features

  • Simply create commands with invoke aliases, permission level, description and help text by creating a class for each command exteding the Command abstract class.
  • Use whatever you want as Database source to manage permissions and guild prefixes by creating your own database driver extending the DatabaseInterface class.
  • Permission system using permission levels.
  • You can also implement your own permission system into discordjs-cmds2 by using the PermissionInterface class.
  • Group your commands together
  • Automatically created command list and help message
  • You can also replace the default help command with your own just by overwriting the help invoke.
  • Promise-Based safety: Every command will be executed in seperate threads which also will catch all exceptions thrown in the commands code.
  • Register your own logger classes based on the LoggerInterface if you want to log into a Database or whatever you want to do with it

Usage

main.js

const discordjs = require('discord.js');
const CmdHandler = require('discordjs-cmds2').CmdHandler;

const DbDriver = require('./dbdriver');

// Create instance of discord.js Client
var client = new discordjs.Client();

// Create new instance of Command Handler
var cmdHandler = new CmdHandler(client, { prefix: 'bot!' })
    .setDatabaseDriver(DbDriver)
    .registerCommand(require('./testcmd'));

client.login('YOURTOKEN');

dbdriver.js

const DatabaseInterface = require('discordjs-cmds2').DatabaseInterface ;

// For this simple example, we just use a JSON file as
// "Database". Of course, you can use a MySql connection
// or something like that for your project.
const database = require('./testdb.json');

module.exports = class DefDbInterface extends DatabaseInterface {
    constructor() {
        super();
    }

    getUserPermissionLevel(userID) {
        return new Promise((resolve, reject) => {
            resolve(database.perms[userID]);
        });
    }

    getGuildPrefix(guildID) {
        return new Promise((resolve, reject) => {
            resolve(database.guildpres[guildID]);
        });
    }
}

testcmd.js

const Command = require('discordjs-cmds2').Command;

module.exports = class TestCommand extends Command {
    constructor() {
        super();
    }

    get invokes() {
        return ['test', 't'];
    }

    get description() {
        return 'Just for testing purposes';
    }

    get help() {
        return '`test` - execute test';
    }

    exec(options) {
        options.channel.send('Test! :ok_hand:');
    }
}

For further examples how to use this package, take a look here.


To-Do

  • Sub-Commands
  • External command list (Markdown, HTML, ...)
  • Guild black (and white) listing
  • User black (and white) listing
  • Extended logging / Custom logging implementation

© 2018 zekro Development
zekro.de | contact[at]zekro.de
MIT Licence

About

A simple command parser for discord.js - rewrote version of discordjs-cmds

Resources

License

Stars

Watchers

Forks

Packages

No packages published