freemyipod r970 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r969‎ | r970 | r971 >
Date:02:36, 21 December 2014
Author:user890104
Status:new
Tags:
Comment:
fmibot: Reconnect on IRC ping timeouts
Modified paths:
  • /tools/fmibot/fmibot.js (modified) (history)

Diff [purge]

Index: tools/fmibot/fmibot.js
@@ -27,12 +27,13 @@
2828
2929 var control = require('./control');
3030
31 -var server = 'hitchcock.freenode.net';
 31+var server = 'irc.freenode.net';
3232 var nickname = 'fmibot';
3333 var nicknamePassword = fs.readFileSync('nickserv.txt');
3434
3535 var announceChannel = '#freemyipod';
3636 var socketPath = '/tmp/fmibot.sock';
 37+var pingTimer = null;
3738
3839 var config = {
3940 autoConnect: false,
@@ -83,10 +84,32 @@
8485 console.info(info.name, info.users, info.topic);
8586 });
8687
 88+function ircConnect() {
 89+ ircbot.connect(Math.pow(2, 32) - 1);
 90+}
 91+
 92+// ping
 93+ircbot.addListener('ping', function() {
 94+ if (pingTimer !== null) {
 95+ clearTimeout(pingTimer);
 96+ }
 97+
 98+ pingTimer = setTimeout(function() {
 99+ pingTimer = null;
 100+ ircbot.disconnect();
 101+ setTimeout(ircConnect, 10 * 1000);
 102+ }, 30 * 60 * 1000);
 103+});
 104+
 105+// misc
 106+ircbot.addListener('action', function(from, to, message) {
 107+ if (to.indexOf('#') === 0 && message === 'kicks ' + nickname) {
 108+ ircbot.say(to, 'ouch!');
 109+ }
 110+});
 111+
87112 // control socket
88 -var controlSocket = new control.Socket(socketPath, function() {
89 - ircbot.connect();
90 -}, function(cmd) {
 113+var controlSocket = new control.Socket(socketPath, ircConnect, function(cmd) {
91114 var args = cmd.split(' ');
92115 var cmd = args.shift().toLowerCase();
93116