0.3.0 • Published 2 years ago

@sooomucheffort/fox v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

fox

fox is a command parser library, which was introduced in @modularium/discord.

$ npm i @sooomucheffort/fox
$ yarn add @sooomucheffort/fox

Example

const { FoxDispatcher } = require('@sooomucheffort/fox')

const fd = new FoxDispatcher()

fd.add({
    base: 'ping',
    info: 'pongs to you',
    execute() {
        return 'pong!'
    }
})

const [command, args] = fd.parse('ping')

fd.use(command, args)
.then(_ => console.log(_)) // pong!
.catch(e => console.log(_))

Example with argument parsing

const { FoxDispatcher } = require('@sooomucheffort/fox')
const { KitsuneParserType } = require('@sooomucheffort/kitsune')

const fd = new FoxDispatcher()

fd.add({
    base: 'ping',
    info: 'pongs to you',
    args: [{
        type: KitsuneParserType.STRING,
        count: -1
    }],
    execute([ st ]) {
        return st ? 'pong with ' + st + '!' : 'pong!'
    }
})

const [command, args] = fd.parse('ping abracadabra alakazam')

fd.use(command, args)
.then(_ => console.log(_)) // pong with abracadabra alakazam!
.catch(e => console.log(_))