npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coffea-bot

v0.0.0

Published

_a bot framework for [coffea 1.0-beta](https://github.com/caffeinery/coffea/tree/1.0-beta) using ES6 modules for plugins_

Downloads

4

Readme

coffea-bot

a bot framework for coffea 1.0-beta using ES6 modules for plugins

WARNING: work-in-progress - not implemented yet!

Installation

First you need to clone the repository to get the latest version of the bot.

git clone https://github.com/caffeinery/coffea-bot my_bot
cd my_bot

Now you can install the dependencies (in the bot directory):

npm install

Configuration

Create a config.json file:

{
  "name": "my_bot",
  "networks": [
    {
      "protocol": "slack",
      "token": "SLACK_BOT_TOKEN_HERE"
    }
  ]
}

Note: The networks config will be passed directly to coffea's connect function.

Running

Just run (in the bot directory):

npm start

Installing plugins

Install them via npm:

npm install --save plugin-name

and then include them in your config:

{
  "name": "my_bot",
  "plugins": [ "plugin-name" ],
  "networks": [
    {
      "protocol": "slack",
      "token": "SLACK_BOT_TOKEN_HERE"
    }
  ]
}

Writing your own plugins

You can also put plugins into a plugins/ folder. coffea-bot will look in that folder first before searching for the plugin in node_modules/ (this is where npm installs them).

  • Create plugins/PLUGINNAME.js, e.g. plugins/test.js
  • Add the plugin to the plugins array in the config, e.g. "plugins": [ "test" ]

coffea-bot uses ES6 modules, plugins are simply functions that get passed event and reply (just like normal coffea event listeners) and return an object that maps commands to handler functions.

  • Edit plugins/PLUGINNAME.js and type:
export default function pluginName(networks) {
  return {
    'hello': (event, reply) => reply('hello world!')
  }
}

You can also extract your handler functions (e.g. if they're more complicated):

export default function pluginName(networks) {
  const handleHello = (event, reply) => reply('hello world!')

  return { 'hello': handleHello }
}

Listening to other events

You can listen to other coffea events by accessing networks, which is a coffea instance container.

export default function logger(networks) {
  networks.on('event', e => console.log(e)) // log all events
}

Nested commands

coffea-bot has built-in support for nested commands. You can return a command tree of any depth in your plugin functions.

e.g. if you want to make /hello world:

export default function helloWorld() {
  const handleHelloWorld = (event, reply) => reply('hello world!')
  const notEnoughArgumentsError = (event, reply) => reply('not enough arguments.')

  return {
    'hello': {
      'world': handleHelloWorld
      'default': notEnoughArgumentsError
    }
  }
}

Now you can try this out:

> /hello
< not enough arguments
> /hello world
< hello world!

Parsing arguments

After nested commands are matched and processed, the rest of the arguments are forwarded to the handler function in the event object as event.args.

export default function hello() {
  const handleHello = (event, reply) => {
    if (event.args.length > 0) reply(`hello ${event.args[0]}!`)
    else reply('not enough arguments.')
  }

  return {
    'hello': handleHello
  }
}
> /hello
< not enough arguments
> /hello destiny
< hello destiny!