@team-choco/command-plugin
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

NOTE: THIS LIBRARY IS CURRENTLY UNDER HEAVY DEVELOPMENT, USE AT YOUR OWN RISK

NPM Version NPM Downloads

@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}"!`);
});

Readme

Keywords

none

Package Sidebar

Install

npm i @team-choco/command-plugin

Weekly Downloads

1

Version

0.2.0

License

none

Unpacked Size

44.8 kB

Total Files

19

Last publish

Collaborators

  • cecilia-sanare
  • kweh-bot