View on GitHub

Omnibot

Simple NodeJS Chat Bot

download .ZIPdownload .TGZ

API Reference

Robot(name, config, httpd)

Create a new Robot.

Robot = require 'omnibot'

config =
  server: 'irc.example.com'
  channels: [ '#list', '#of', '#channels' ]
  port: 6667
  password: 'server-password'

httpd =
  port: 8080
  user: 'username'
  password: 'password'

bot = new Robot 'Name', config, httpd
bot.start(callback)

Start the bot and connect to IRC.

bot.start ->
  # Say hi or load modules
bot.shutdown(callback)

Close the IRC connection.

bot.shutdown ->
  # Do some cleanup
bot.say(to, message)

Send a message to a channel or user.

bot.say '#channel', 'Message to the channel'
bot.say 'Nick', 'Private message'
bot.respond(regex, callback)

Respond to a message aimed at the bot. Callback recieves a new Response instance.

bot.respond /foo/, (resp) ->
  resp.send 'bar'
bot.hear(regex, callback)

Respond to a message. Callback recieves a new Response instance.

bot.hear /hello/, (resp) ->
  resp.send 'hello'
bot.load(path)

Load a directory of modules.

bot.load './modules'
bot.loadModules(modules)

Load a list of OmniBot-Modules.

modules = [ 'joke', 'join', 'weather' ]
bot.loadModules modules
bot.loadFile(path, file)

Load a single module.

bot.load './modules', 'foo'
bot.http(url)

Return a new Scoped HTTP Client.

bot.http("https://github.com/mloberg/OmniBot")
  .get() (err, res, body) ->
    console.log body
bot.set(name, value)

Set a config item's value.

bot.set 'foo', 'bar'
bot.get(name)

Get a config item's value.

bot.get 'foo' # => bar
bot.router

The bot includes a Connect httpd server if a third option was passed when creating the bot.

bot.router.get '/info', (req, res) ->
  res.end "OmniBot info"
bot.connection

The IRC adapter.

Response

The Response class is used when making a callback using the Robot.respond or Robot.hear methods.

response.from

The Nick of the user that sent the message.

response.to

Where the message was recieved. If a private message, it will be null.

response.message

The message text.

response.match

An array of matches from the message.

response.send(message)

Send a response back. Will be sent to resp.to if not null, otherwise resp.from.

response.random(items)

Select a random item from an array of items.

response.http(url)

Return a Scoped HTTP Client.