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

gu

v0.6.2

Published

Streaming bot makers library with regex handlers

Downloads

174

Readme

gu

npm status build status dependency status coverage status

Gu is a streaming bot makers library that you can pipe your transports to and from.

It has two main features:

  • regular expression handlers in a style similar to hubot (but without all those annoying environment variables and coffee-script..)
  • streaming input and output allows for easy control, extensibility and transport-less testing of handlers

Usage

Find a library that does the transport you want, say irc-stream:

Create a main file; bot.js:

var gu = require('gu')(scriptPath, files);
var ircStream = require('ircStream')(name, server, {chan: [chan]});

ircStream.pipe(gu).pipe(ircStream);

The script path and the files (relative to the scriptpath) will be watched for changes, and is assumed to contain handlers exported behind a function.

Then, put a file in your scriptpath, love.js, say, and add handlers therein:

module.exports = function (gu) {
  gu.handle(/^what is (\w*)$/, function (say, match) {
    if (match === 'love') {
      say("baby don't hurt me");
    }
  });
};

Then fire up the bot with node bot.js, navigate to the specified server and channel (in ircOpts), and try saying botName: what is love in the channel.

Changing the handler in love.js will result in different behaviour without having to restart bot.js.

A more extensive example is avaiable in the example directory.

Complete examples

The following bots are built on gu:

Stream Specification

A gu instance expects to have objects written to it, and will new objects readable on the other end.

Therefore, the sensible interface (unless you are doing some weird asymmetrical connection setup), is a Duplex stream in objectMode.

Inputs & Outputs

Expected input objects:

{
  user: String, // unique identifier of user
  channel: String, // unique group chat identifier (if relevant)
  message: String, // raw message to be matched by gu
}

Output objects are identical. As an example an example message from/to irc-stream can look like this { user: 'clux', channel: '#quake', message: 'hi' } for a private message, the channel key is unset.

An optional name property may be set for the convenience of the stream handler (such as xmpp-stream). It is used when doing group chat highlighting without having to necessarily use the larg UID. For IRC it is unused.

Compatible Transports

Best tested: irc-stream.

Early prototype of xmpp-stream also available.

Options

A few options can be passed along to the gu instance as the third parameter, these are:

{
  verbose: Boolean // enable regex match log when gu receives messages
}

Logging

Emitted logs are available on the instance as gu.log. They are emitted in the form of smell.

To actually print them out, you should use sulfur as such:

var sulfur = require('sulfur');
sulfur.absorb(gu.log, 'gu');

You can also log from gu handlers by calling the log methods error, warn, or info on gu.log:

gu.handle(/^(.*)$/, function (say, match) {
  gu.log.info("matched the everything handler with", match);
});

Installation

$ npm install gu

License

MIT-Licensed. See LICENSE file for details.