lw-arger

1.3.2 • Public • Published

Larger

The Lightweight Argument Parser for discord.js (pronounced Lager)

Installation

npm

npm i lw-arger

yarn

yarn add lw-arger

Usage

Examples given are as "library agnostic" as possible.

Simplest example:

const larger = require('lw-arger')

const content = '?kick user "bad behaviour"'
const prefix = '?'

const {command, args} = larger(content, prefix)

switch(command) {
    case 'kick':
        const userToKick = args[0]
        const reason = args[1]

        kickUser(userToKick, reason) //Implementation varies
        break;
}

Handler

It's possible to run Larger with a handler, which can handle commands in a functional way.

const larger = require('lw-arger')

const prefix = '?'

larger.handler({
    kick: (user, reason) => {
        console.log(`kicking ${user} for reason: ${reason}`)
    }
})

function messageReceived(content) {
    larger(content, prefix)
}

Passthroughs

You can also pass through objects from your library that may be needed (discord.js example)

const larger = require('lw-arger')

const prefix = '?'

larger.handler({
    kick: (message, user, reason) => {
        message.reply(`${user} was kicked`)
        //kick user
    }
})

//Called from discord.js message event
function messageReceived(message) {
    larger(message, message.content, prefix)
}

Fallbacks

The handler also has support for fallback methods, which will be called if the command doesn't exist.

const larger = require('lw-arger')

const prefix = '?'
const content = '?kick user reason'

larger.handler({
    fallback: () => {
        console.log('command not found...')
    }
})

const {command, args} = larger(content, prefix)

Arg Joining

If there is only parameter on a handler then all of the arguments will be concatenated together which removes the need for quotes.

const larger = require('lw-arger')

const prefix = '?'
const content = '?say hello this is a long message'

larger.handler({
    say: (message) => {
        //message will be 'hello this is a long message'
    }
})

const {command, args} = larger(content, prefix)

/lw-arger/

    Package Sidebar

    Install

    npm i lw-arger

    Weekly Downloads

    0

    Version

    1.3.2

    License

    wtfpl

    Unpacked Size

    11.2 kB

    Total Files

    9

    Last publish

    Collaborators

    • shaunwild97