示例#1
0
irc.on('message', function (nick, to, text) {
  var nameRegExp = new RegExp( botname_private, 'i' );
  if (/^#/.test(to) && (nameRegExp.test(text))) {
    // general handling of messages to snakeeyes in a channel
    var command = text.substr(10).trim();
    for (var i = 0; i < watchers.length; i++) {
      var watcher = watchers[i];
      if (watcher.pattern.test(command)) {
        watcher.callback(nick, to, command);
        return;
      }
    }
    // default (for command it doesn't understand)
    irc.say(to, nick + ': ' + eliza.transform(command));
    if (eliza.quit) { eliza.reset(); }
  }
  else {
    // responses to all non-command messages
    if (text.toLowerCase().match(/firefox/) && Math.random()<=0.15) {
      irc.say(to, "YOU'RE TEARING ME APART, FIREFOX!");
    }
    // never question snake-eyes
    if ( text.match(/(why|what).+\sop(s)?.*/i) ) {
      irc.send('mode', to, '-o', nick);
      irc.say(to, nick + ": " + botname_private + " has spoken.");
    }
  }
});
示例#2
0
  http.createServer( httpHandler ).listen( http_port );
});

var httpHandler = function (req, res) {
  req.setEncoding('utf8');

  // on POSTs to /room, say body in #room
  req.on('data', function (data) {
    var room = req.url.replace(/\//, '');
    irc.say('#' + room, '\x032' + data);
  });
  req.on('end', function () { res.writeHead(204); res.end(); });
};

// give the bot some personality
var eliza = new ElizaBot();
// throw away initial (do I need to do this?)
eliza.getInitial();

// simple router
var watchers = [];
var watch = function (pattern, callback) {
  watchers.push({ pattern: pattern, callback: callback });
};

// op everyone internally
irc.on('join', function (channel, nick) {
  irc.send('mode', channel, '+o', nick);
});

// nerdery on the internal irc server