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

greenbot

v1.0.4

Published

A simple greenman-based IRC bot supporting plugins

Downloads

3

Readme

Greenbot

Greenbot is a plugin-oriented IRC bot built on node-greenman, a node-irc wrapper. Plugins are loaded in a configurable order and act in middleware chains, allowing for various handling cases like filtering, message rewriting, logging, and anti-spam. Plugins can also depend on each other to enhance their capabilities. The bot can be run programmatically or from the command line.

Installation and Usage

Install greenbot globally with NPM:

$ npm install -g greenbot

Now you're ready to set up plugins and create a configuration file.

Plugin API

A plugins directory is just a collection of node modules as sibling directories, where the directory name is the module name. Greenbot should be able to just require the directory to get the plugin. The only other requirement is that plugins must implement an init function on their exports. Here is a complete sample plugin that echos messages of the form !echo <message> and uses a rate limiting dependency to prevent spam:

rateLimit = require "nogo"

module.exports = init: (bot, config, plugins) ->
  prefix = config?.global?.prefix || "!"

  limiter = rateLimit
    rate: 0.3
    burst: 2
    strikes: 3
    cooldown: 60

  bot.msg ///^#{prefix}echo\s+(.+)$///i, (nick, channel, match) ->
    limiter nick,
      go: () -> bot.reply nick, channel, match[1]
      no: (strike) -> bot.say nick, "Enhance your calm! (Strike #{strike} of 3)"

The arguments to init are:

  1. bot: A Greenman instance. See the node-greenman readme for its full API
  2. config: The parsed CSON file provided at startup to Greenbot
  3. plugins: A map of all enabled plugins. This can be used to enhance functionality of plugins if certain other plugins are present

Of course, you can also expose other members on exports for other plugins to depend on.

Configuration

Create a config.cson file or copy the example one in this project. This file will configure how the bot connects to IRC channels, what plugins are loaded and in what order, and how plugins will be individually configured.

# The "greenbot" block is only used to setup the bot. All other configuration is of concern to plugins only
greenbot:
  nick: "greenbot"
  server: "irc.example.com"
  # These "options" are passed right through to the underlying dependency, node-irc, on startup
  options:
    floodProtection: true
    floodProtectionDelay: 1000
    channels: [
      "#yourchannel"
    ]
    # Absolute path to the plugins directory
    pluginsDir: "/Users/example/my-greenbot-plugins"
    # List the plugins in pluginsDir you want enabled. See "Why does plugin order matter?" below
    plugins: [
      "ignore",
      "echo"
    ]

# Any additional configuration needed by plugins:

global:
  prefix: "!"

ignore:
  nicks: [
    /.+bot/i
    "ChanServ"
  ]

Why does plugin order matter?

Greenbot is mainly concerned with the idea of plugins, and uses node-greenman as its IRC bot. Greenman allows message handlers to be chained, such that a handler can decide not to pass the message on to subsequent handlers, or even modify the message contents. See the Greenman API for more information. For example, the included "ignore" plugin will only pass messages to the next handler in the chain if they're from non-ignored nicks. Because order matters, the plugin should be listed first.

Run It

$ greenbot ./config.cson

Running programmatically

Install greenbot non-globally:

npm install greenbot

Then require and construct it with a configuration object the same as documented above:

Greenbot = require "greenbot"

bot = new Greenbot(config)
bot.connect()

Alternatives

Not your cup of tea? Check out these other node IRC bots:

License

Licensed under the MIT License.