haft

1.2.1 • Public • Published

Haft

Haft is a simple command framework for Eris Discord library. It allows you to handle commands easily with ability to type-check their arguments.

Usage

The main data class you should be working with is Haft.FrameworkBot:

const Haft = require('haft');

const bot = new Haft.FrameworkBot('BOT_TOKEN', { prefix: '~' });

You can register commands, cooldown buckets and command groups using methods on this data class:

// Define a bucket which we can use later to limit command usage.
// This one allows all commands that use it to be called only 5 times every 30 seconds, with 2 second delay.
bot.bucket('stuff', new Haft.Ratelimit(2, 30, 5));

bot.command('args', { arg1: Number, arg2: String }, (m, args) => {
  m.respond(`Arguments: ${Object.values(args)}`); // Will respond if someone says ~args
}, { bucket: 'stuff' }); // We use the bucket here.

bot.commandGroup('Emojis', 'emoji', register => {
  register('cat', {}, (m) => {
    m.respond(':cat:'); // Will respond if someone says ~emoji cat
  });
  register('dog', {}, (m) => {
    m.respond(':dog:'); // Will respond if someone says ~emoji dog
  });
});

Configuration

Command

  • maxArgs - maximum allowed amount of arguments
  • minArgs - minimum required amount of arguments
  • allowDM - if false won't allow a command to be used in DM
  • onlyDM - if true won't allow a command to be used in guilds
  • onlyOwners - only allows bot owners to call this command
  • alias - an alias that allows a command to be used under a different name
  • aliases - similar to alias but accepts an array
  • bucket - allows to use a ratelimiting bucket
  • checks - an array of functions that stop execution if falsy value is returned
  • requiredPermissions - permission names a person that executes the command should have. Doesn't work in DM.

FrameworkBot

  • blockedUsers, blockedGuilds - limits bot usage
  • listenToMentions, allowWhitespace, prefix - configures prefix
  • accountType - allows to change what kind of accounts should bot ignore
  • owners - allows to specify owners for onlyOwners commands

Readme

Keywords

none

Package Sidebar

Install

npm i haft

Weekly Downloads

4

Version

1.2.1

License

MPL-2.0

Last publish

Collaborators

  • taavi