@team-choco/command-plugin
v0.2.0
Published
Adds the ability to register commands to Choco Bot Core!
Downloads
9
Readme
NOTE: THIS LIBRARY IS CURRENTLY UNDER HEAVY DEVELOPMENT, USE AT YOUR OWN RISK
@team-choco/command-plugin
Adds the ability to register commands to Choco Bot Core!
Install
$ npm install -S @team-choco/command-plugin
Usage
// ...
import { ChocoBotCore } from '@team-choco/core';
import { ChocoCommandPlugin } from '@team-choco/command-plugin';
const bot = new ChocoBotCore({
// ...
plugins: [
// This adds the '.command' function.
new ChocoCommandPlugin({
prefix: '.',
}),
],
});
// Example Interaction
// <me>: !ping
// <Choco Bot>: pong!
bot.command('ping', async ({ message, args }) => {
console.log(args); // { _: [] }
await message.reply('pong!');
});
bot.on('ready', () => {
console.log('Kweh! Choco Bot is now up and running!');
});
API
command(pattern: string, listener: ({ message }) => void): void
Patterns Syntax
<name>
- matches a positional argument.
<...name>
- matches the remaining positional arguments.
Examples
// ...
// Example Interaction
// <me>: .search Elm
// <Choco Bot>: You searched for "Elm"!
// <me>: .search Elm Log
// -- Choco Bot wouldn't respond in this case.
bot.command('search <name>', async ({ message, args }) => {
await message.reply(`You searched for "${args.name}"!`);
});
// ...
// Example Interaction
// <me>: .search Elm
// <Choco Bot>: You searched for "Elm"!
// <me>: .search Elm Log
// <Choco Bot>: You searched for "Elm Log"!
bot.command('search <...name>', async ({ message, args }) => {
await message.reply(`You searched for "${args.name}"!`);
});