Welcome

Gears is a JavaScript library for building command powered bots.
Get started here or Check out the documentation

Also check out the repository if you are curious or have any issues you want to address.

Demo

This is a demo that features a running version of a Gears bot.
Type some words and type !count to check how many times that word was said.
Like this:
!count Gears
The word "Gears" was said 1 times
Gears is neat, huh?
!count Gears
The word "Gears" was said 2 times

The above example can be summed up in this code block:

const regex = /(?:[a-z]'[a-z]|[a-z0-9\-])+/gi

class WordCountService extends Service {
  serviceDidInitialize() {
    this.wordMap = new Map()

    this.getWordCount = word => this.wordMap.get(word) || 0

    this.incrementWordCount = word => {
      const currentCount = this.wordMap.get(word) || 0
      this.wordMap.set(word.toLowerCase(), currentCount + 1)
    }
  }
}

const countCommand = new Command()
  .match(matchPrefixes("!count "))
  .use(context => {
    const { content, manager } = context

    const words = content.match(regex) || []

    if (!words) return "No word was specified"
    if (words.length > 1) return "More than one word was specified"

    const service = manager.getService(WordCountService)
    const count = service.getWordCount(words[0].toLowerCase())

    return `The word "${words[0]}" was said ${count} times`
  })

const wordCounterCommand = new Command()
  .match(matchAlways())
  .use(context => {
    const { content, manager } = context

    const words = content.match(regex) || []
    const service = manager.getService(WordCountService)

    for (const word of words) {
      service.incrementWordCount(word.toLowerCase())
    }
  })

const bot = new Bot({
  adapter: ...,
  commands: [countCommand, wordCounterCommand],
  services: [WordCountService]
})