Marvin: A little Pogoapp IRC bot

| By paul

We've been careful to try to emphasize the term "app hosting" over "web hosting", because there's becoming more and more overlap in the tools for building and hosting web and other types of internet applications, and Pogoapp has always been intended to build, deploy and manage any type of networked application with the the same underlying infrastructure and philosophy.

For example, here's a really basic demo CoffeeScript IRC bot we whipped up this morning:

irc       = require 'irc'
request   = require 'request'

bot_nick  = process.env.BOT_NICK || 'marvin-bot'
chan      = process.env.CHANNEL
server    = process.env.SERVER
client    = new irc.Client(server, bot_nick, {channels: [chan]} )

log = (from, to, message) ->
  console.log from + ' => ' + to + ': ' + message
say = (msg) ->
  log bot_nick, chan, msg
  client.say chan, msg

client.on "join#{chan}", (nick, message) ->
  if nick == bot_nick
    say "Hi everyone!"
  else
    say "Hi #{nick}!"

client.on "message#{chan}", (nick, text, message) ->
  if text.match(new RegExp(bot_nick))
    if text.match(/stats/)
      request.get { uri: 'https://api.pogoapp.com/status.json', json: true }, (err, r, body) -> 
        if err
          say "Oh no, Pogo Error!"
        else
          results = []
          results.push "#{v} #{k}" for k,v of body
          say "Pogoapp live stats: " + results.join(', ')
    else
      say "#{nick}: sorry, I don't know what to think about that"

client.on 'message', (from, to, message) ->
  log(from, to, message)

Marvin says hi when he enters the channel, and to any user that enters the channel, and if you mention his name and the word "stats" in a message, he'll fetch the live Pogoapp API stats, parse the JSON, and give you a prettified string output.

And he'll log everything to STDOUT so you can review it later in pogo logs (or heroku logs - this should all work just about the same if you host it on heroku).

To get "marvin" online, we just did:

pogo create marvin-irc --remote pogoapp
pogo config:set CHANNEL='#pogoapp' SERVER='irc.freenode.net'
git push pogoapp
pogo ps:scale marvin=1

And then in IRC:

[1:23pm] themgt: marvin-bot: stats?
[1:23pm] marvin-bot: Pogoapp live stats: 66 apps, 512 builds, 2 datacenters, 4 boxes, 96 containers