0.2.0 • Published 4 years ago

@team-choco/command-plugin v0.2.0

Weekly downloads
27
License
-
Repository
github
Last release
4 years ago

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

4 years ago

0.1.28

4 years ago

0.2.0

4 years ago

0.1.26

4 years ago

0.1.24

4 years ago

0.1.25

4 years ago

0.1.23

4 years ago

0.1.22

4 years ago

0.1.18

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.2

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago