1.3.2 • Published 6 years ago

lw-arger v1.3.2

Weekly downloads
4
License
wtfpl
Repository
github
Last release
6 years ago

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)
1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago