A generic command parser meant for discord bots, though works for just about anything else
Go to file
2023-08-15 18:29:24 +03:00
scripts
src minor tweaks to typings 2023-08-15 18:29:24 +03:00
tests
.drone.yml
.eslintignore
.eslintrc.json
.gitignore
babel.config.cjs
index.ts Export command interface 2023-08-15 16:43:50 +03:00
jest.config.cjs
package.json v1.5.4 2023-08-15 17:51:30 +03:00
README.md update readme 2023-05-12 19:37:54 +03:00
tsconfig.cjs.json
tsconfig.json
yarn.lock

A command parser initially made for quickly making discord bots, but works as a standalone parser too.

Your commands are expected to inherit from the Command class

Example usage


const commands: Command[] = [
    new Command({
        name: 'ping',
        options: [
            {
                name: 'respond',            //
                type: OptionType.BOOLEAN,   // Boolean type expects the parser to have some kind of string -> boolean resolver, see the resolver interface for which methods are expected
                required: true,             // Will throw error if not provided
                defaultValue: true,         // The value that will be given back if no value is given, or if option is required but not provided
                flag: true                  // The parser will look for the option in the "--respond value" form
            }
        ]
    })
]; // Command definitions

const parser = new Parser({commands, prefix: ''}); // Empty prefix
const parsed = await parser.parseMessage('ping --respond');

/**
 * Parsed will be an object cotaining properties args, command, subcommand, and subcommandgroup
 * the args property is an object of the given options mapped by their names, e.g.
 * {
 *   respond: {
 *     ... properties,
 *     value: true
 *   }
 * }
 * 
*/

Some of the option types have built-in parsers (e.g. numbers, strings), but others will require the resolver implementation, and in some cases CommandOption extensions.