Home

Awesome

oftn-bot

This is the repository for both of the IRC bots oftn-bot (in #oftn on freenode) and ecmabot (in ##javascript on freenode). This was originally created as a replacement for v8bot (http://github.com/eisd/v8bot). Over time, it changed to include a full-featured IRC bot library.

Features

API

The underlying IRCBot library has methods which make it easy to add functionality.

Bot(profile)

@profile: An array of objects representing each server to connect to.

This is the main constructor for the bot. It is suggested that you inherit from this object when creating your bot, but you don't have to.

A profile is an array of objects. Each object has the properties:

bot.init()

Goes through each server in the profile and begins connecting and registering event listeners.

bot.register_listener(regex, callback)

Adds a regular expression listeners to incoming traffic on all servers. When the messages match, callback is called with the arguments:

bot.register_command(command, callback, options)

Adds a command.

When the command is called, the callback is called with the arguments:

Install

Clone the repo:

# clone without all of the history
git clone --depth=1 https://github.com/oftn/oftn-bot.git my-bot-directory

If you want to build on ecmabot.js, copy sample-profile.js to ecmabot-profile.js and edit options. nickserv and password can be removed for development.

To run the bot: node ecmabot.js.

Currently the only way to update the bot is a full restart.

REPL

ecmabot can run code in a sandbox. It uses docker, which you'll need to install. If you don't install docker, the code execution will silently fail.

If docker is installed, it'll automatically download js-eval, which provides node, and node+babel for executing code. Each code snippet is run in a fresh container with limited memory, cpu usage, no network access, and a user that owns no files or has any special permissions (see the docker run command). Keep docker up to date in case any critical security vulnerabilities are found.

To update the js-eval version, run docker pull brigand/js-eval. This will get you the latest node stable and babel version. You don't need to restart the bot when you do this. The lazy way to do this:

# check for updates every 3 hours (a build occurs at least once every 12 hours)
screen -dmS 'update-js-eval' bash -c 'while true; do sleep 10800; docker pull brigand/js-eval; done'

Examples

node:

user: n> require('path').join('foo', 'bar')
bot: (okay) foo/bar

babel:

user: b> const [foo, ...bar] = ['a', 'b', 'c'].entries(); bar
bot: (okay) [ [ 1, 'b' ], [ 2, 'c' ] ]

Additional Documentation

This bot AND/OR bot library is still being developed, but those are some of the basic commands. Look at your-bot-here.js for a simple example of an IRC bot using this API, or ecmabot.js for a more complex and featured example.