0.2.0 • Published 3 years ago

@team-choco/command-plugin v0.2.0

Weekly downloads
27
License
-
Repository
github
Last release
3 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

3 years ago

0.1.28

3 years ago

0.2.0

3 years ago

0.1.26

3 years ago

0.1.24

3 years ago

0.1.25

3 years ago

0.1.23

3 years ago

0.1.22

3 years ago

0.1.18

3 years ago

0.1.16

3 years ago

0.1.15

3 years ago

0.1.14

3 years ago

0.1.13

3 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago