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

waldorf

v1.0.2

Published

Simple Mattermost Bot

Downloads

13

Readme

Waldorf

License NPM version Dependency Status devDependency Status

Simple Mattermost Bot 🤡🤠

Uses Webhooks

Installation

  • Prerequisites: Node.js
  • Install Waldorf sudo npm install -g waldorf
  • Create a directory for the Scripts e.g. mkdir /opt/waldorf

Mattermost Setup

  • In the System Console - Integrations - Custom Integrations:
    • Enable Incoming Webhooks
    • Enable Outgoing Webhooks
    • Enable Integrations to Override Usernames
  • Create the Webhooks in the Team Settings - Integrations
    • an Incoming Webhook for every Channel where Waldorf should be able to say something

    • an Outgoing Webhook, you don't need to select a Channel here - then Waldorf will be able to subscribe to messages in every Channel. Define desired Trigger Words, e.g. "@waldorf". As Callback URL you need to supply the IP Address and the Port where Waldorf listens, if Waldorf runs on the same server as Mattermost you can use e.g. http://127.0.0.1:31337

Start Waldorf

See waldorf --help for available options.

Example Start command:

waldorf -u http://127.0.0.1:8065/hooks/ \
    -n waldorf \
    -s /opt/waldorf \
    -t s1zz8e1wxzgwjfmsnz3c43dnpa \
    -c ij6osdf3ofnidp199ronuinwne:town-square \
    -c hiirtud1spfwmfegd3pejamzsr:another-channel 

The -t option supplies the Secret Mattermost generated for the Outgoing Webhook, the -c options define Channels and the Secrets of the Incoming Webhooks.

I suggest to use PM2 to start Waldorf.

Scripts

Just place Javascript Files in the /opt/waldorf folder and mind that you have to restart Waldorf when you change or add Scripts there.

Example Scripts:

// Stupid :)
schedule('37 13 * * *', () => pub('town-square', '1337 time!!1! 🤓'));
// Respond "Hi @user" when someone says "Hello" or "hallo" ...
sub(/[Hh][ea]llo/, (match, user, channel) => pub(channel, `Hi @${user}`));
// simple quote script
const fs = require('fs');
const file = '/opt/waldorf/quotes.json';

let quotes = [];

if (fs.existsSync(file)) quotes = JSON.parse(fs.readFileSync(file));

sub(/\!addquote (.*)/, (match, user, channel) => {
    quotes.push(match[1]);
    fs.writeFileSync(file, JSON.stringify(quotes));
});

sub(/\!randomquote/, (text, user, channel) => {
    pub(channel, '> ' + quotes[Math.floor(Math.random() * quotes.length)]);
});

Script API

Classes

Functions

Typedefs

log

Log to stdout/stderr. Messages are prefixed with a timestamp and the calling scripts path.

Kind: global class

log.debug()

Log a debug message

Kind: static method of log

| Type | | --- | | * |

log.info()

Log an info message

Kind: static method of log

| Type | | --- | | * |

log.warn()

Log a warning message

Kind: static method of log

| Type | | --- | | * |

log.error()

Log an error message

Kind: static method of log

| Type | | --- | | * |

pub(channel, text)

Send Text to a Channel

Kind: global function

| Param | Type | | --- | --- | | channel | string | | text | string |

sub(pattern, callback) ⇒ subscriptionId

Add a Subscription that calls a Callback when pattern matches text said in a Channel

Kind: global function

| Param | Type | | --- | --- | | pattern | string | RegExp | | callback | subscribeCallback |

Example

// Respond "Hi @User" when someone says "Hello" or "hello"
sub(/[Hh]ello/, (match, user, channel) => pub(`Hi @${user}`));

unsub(id)

Remove a Subscription

Kind: global function

| Param | Type | | --- | --- | | id | subscriptionId |

schedule(pattern, [options], callback)

Schedule recurring and one-shot events

Kind: global function

| Param | Type | Description | | --- | --- | --- | | pattern | string | Date | Object | Array.<mixed> | pattern or array of patterns. May be cron style string, Date object or node-schedule object literal. See https://github.com/tejasmanohar/node-schedule/wiki | | [options] | Object | | | [options.random] | number | random delay execution in seconds. Has to be positive | | callback | function | is called with no arguments |

Example

// every full Hour.
schedule('0 * * * *', callback);

// Monday till friday, random between 7:30am an 8:00am
schedule('30 7 * * 1-5', {random: 30 * 60}, callback);

// once on 21. December 2018 at 5:30am
schedule(new Date(2018, 12, 21, 5, 30, 0), callback);

// every Sunday at 2:30pm
schedule({hour: 14, minute: 30, dayOfWeek: 0}, callback);

subscribeCallback : function

Kind: global typedef

| Param | Type | Description | | --- | --- | --- | | text | string | Array.<string> | text or .match(RegExp) array | | user | string | the Name of the User that said something | | channel | string | the Channel where something was said |

License

MIT (c) Copyright Sebastian Raff