From f136636093d9f8964af19ba1228b4d33d2833988 Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Sat, 10 Mar 2012 18:21:50 +0000 Subject: [PATCH 1/5] webPort config option, default 443 --- modules/web.js | 2 +- run.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/web.js b/modules/web.js index b188487..e3ac0fa 100644 --- a/modules/web.js +++ b/modules/web.js @@ -37,7 +37,7 @@ var webInterface = function(dbot) { res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } }); }); - app.listen(443); + app.listen(dbot.webPort); return { 'onDestroy': function() { diff --git a/run.js b/run.js index 0390b3f..be242b4 100644 --- a/run.js +++ b/run.js @@ -44,6 +44,7 @@ var DBot = function(timers) { this.nickserv = this.config.nickserv || 'zippy'; this.server = this.config.server || 'elara.ivixor.net'; this.port = this.config.port || 6667; + this.webPort = this.config.webPort || 443; this.moduleNames = this.config.modules || [ 'command', 'js', 'admin', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'web', 'youare' ]; this.timers = timers.create(); From 92767dbfb188b8af812fb8beac89567b5654031f Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Sat, 10 Mar 2012 18:38:56 +0000 Subject: [PATCH 2/5] Fail on invalid-syntax DBs, instead of replacing them. Also, shunt creation of 'realityonce' array to the realityonce listener, so it's not created before being needed. --- modules/quotes.js | 3 +++ run.js | 57 +++++++++++++++++++++++++---------------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/modules/quotes.js b/modules/quotes.js index cedd678..f08b3e1 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -247,6 +247,9 @@ var quotes = function(dbot) { dbot.db.bans['*'].include(data.user)) { dbot.say(data.channel, data.user + ' is banned from using this command. Commence incineration.'); } else { + if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) { + dbot.db.quoteArrs['realityonce'] = []; + } dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.'); addStack.push('realityonce'); rmAllowed = true; diff --git a/run.js b/run.js index be242b4..f9b5927 100644 --- a/run.js +++ b/run.js @@ -6,35 +6,38 @@ require('./snippets'); var DBot = function(timers) { // Load external files this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); + this.db = null; + var rawDB; try { - this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); + var rawDB = fs.readFileSync('db.json', 'utf-8'); } catch (e) { - this.db = {}; - } finally { /* fill any missing parts of the db; if this is a new DB, that's all of them */ - if(!this.db.hasOwnProperty("bans")) { - this.db.bans = {}; - } - if(!this.db.bans.hasOwnProperty("*")) { - this.db.bans["*"] = []; - } - if(!this.db.hasOwnProperty("quoteArrs")) { - this.db.quoteArrs = {}; - } - if(!this.db.quoteArrs.hasOwnProperty("realityonce")) { - this.db.quoteArrs.realityonce = []; - } - if(!this.db.hasOwnProperty("kicks")) { - this.db.kicks = {}; - } - if(!this.db.hasOwnProperty("kickers")) { - this.db.kickers = {}; - } - if(!this.db.hasOwnProperty("modehate")) { - this.db.modehate = []; - } - if(!this.db.hasOwnProperty("locks")) { - this.db.locks = []; - } + this.db = {}; /* if no db file, make empty one */ + } + if(!this.db) { /* if it wasn't empty */ + this.db = JSON.parse(rawDB); + } + + /* repair any deficiencies in the DB; if this is a new DB, that's everything */ + if(!this.db.hasOwnProperty("bans")) { + this.db.bans = {}; + } + if(!this.db.bans.hasOwnProperty("*")) { + this.db.bans["*"] = []; + } + if(!this.db.hasOwnProperty("quoteArrs")) { + this.db.quoteArrs = {}; + } + if(!this.db.hasOwnProperty("kicks")) { + this.db.kicks = {}; + } + if(!this.db.hasOwnProperty("kickers")) { + this.db.kickers = {}; + } + if(!this.db.hasOwnProperty("modehate")) { + this.db.modehate = []; + } + if(!this.db.hasOwnProperty("locks")) { + this.db.locks = []; } // Populate bot properties with config data From 94430e52a11272ca2f7be62717b87c82072c7b77 Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Mon, 12 Mar 2012 13:07:24 +0000 Subject: [PATCH 3/5] sessionData hash for storage which should explicitly not survive beyond full restarts (as opposed to reloading modules). --- run.js | 1 + 1 file changed, 1 insertion(+) diff --git a/run.js b/run.js index f9b5927..9da733a 100644 --- a/run.js +++ b/run.js @@ -49,6 +49,7 @@ var DBot = function(timers) { this.port = this.config.port || 6667; this.webPort = this.config.webPort || 443; this.moduleNames = this.config.modules || [ 'command', 'js', 'admin', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'web', 'youare' ]; + this.sessionData = {}; this.timers = timers.create(); From 064d898f4a845b1ba10f665d7cba3c06cdac6ddc Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Mon, 12 Mar 2012 13:45:52 +0000 Subject: [PATCH 4/5] ~ignore command for, well, ignoring commands temporarily. Add a timer.js wrapper for setTimeout, too. --- modules/command.js | 44 +++++++++++++++++++++++++++++++++++++++++--- timer.js | 8 ++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/modules/command.js b/modules/command.js index ed7451f..434b2db 100644 --- a/modules/command.js +++ b/modules/command.js @@ -3,17 +3,55 @@ var command = function(dbot) { var dbot = dbot; + var ignoreCommands = function (data, params) { + if(data.channel == dbot.name) data.channel = data.user; + var targetCommand = params[1]; + var ignoreMins = parseFloat(params[2]); + + if(!dbot.sessionData.hasOwnProperty("ignoreCommands")) { + dbot.sessionData.ignoreCommands = {}; + } + if(!dbot.sessionData.ignoreCommands.hasOwnProperty(targetCommand)) { + dbot.sessionData.ignoreCommands[targetCommand] = []; + } + + if(dbot.sessionData.ignoreCommands[targetCommand].include(data.channel)) { + dbot.say(data.channel, "Already ignoring '" + targetCommand + "' in '" + data.channel + "'."); + } else { + dbot.sessionData.ignoreCommands[targetCommand].push(data.channel); + dbot.timers.addOnceTimer(ignoreMins * 60 * 1000, function() { + dbot.sessionData.ignoreCommands[targetCommand].splice(dbot.sessionData.ignoreCommands[targetCommand].indexOf(data.channel), 1); + dbot.say(data.channel, "No longer ignoring '" + targetCommand + "' in '" + data.channel + "'."); + }); + dbot.say(data.channel, "Ignoring '" + targetCommand + "' in '" + data.channel + "' for the next " + ignoreMins + " minute" + (ignoreMins == 1 ? "" : "s") + "."); + } + }; + return { + 'onLoad': function() { + return { + '~ignore': ignoreCommands + }; + }, 'listener': function(data) { params = data.message.split(' '); if(data.channel == dbot.name) data.channel = data.user; - if(dbot.commands.hasOwnProperty(params[0])) { + var ignoringCommand = false; + if(dbot.sessionData.hasOwnProperty("ignoreCommands")) { + if(dbot.sessionData.ignoreCommands.hasOwnProperty(params[0])) { + if(dbot.sessionData.ignoreCommands[params[0]].include(data.channel)) { + ignoringCommand = true; + } + } + } + + if(dbot.commands.hasOwnProperty(params[0]) && (!(ignoringCommand))) { if((dbot.db.bans.hasOwnProperty(params[0]) && - dbot.db.bans[params[0]].include(data.user)) || dbot.db.bans['*'].include(data.user)) + dbot.db.bans[params[0]].include(data.user)) || dbot.db.bans['*'].include(data.user)) { dbot.say(data.channel, data.user + ' is banned from using this command. Commence incineration.'); - else { + } else { dbot.commands[params[0]](data, params); dbot.save(); } diff --git a/timer.js b/timer.js index de260dd..7d494a6 100644 --- a/timer.js +++ b/timer.js @@ -1,15 +1,23 @@ var timers = function() { var timers = []; + var timeouts = []; return { 'addTimer': function(interval, callback) { // Because who puts the callback first. Really. timers.push(setInterval(callback, interval)); }, + + 'addOnceTimer': function(delay, callback) { // Because who seriously puts the callback first here too? + timeouts.push(setTimeout(callback, delay)); + }, 'clearTimers': function() { for(var i;i Date: Mon, 12 Mar 2012 13:49:55 +0000 Subject: [PATCH 5/5] Oops, stop falling out of the command logic when commands are ignored. --- modules/command.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/command.js b/modules/command.js index 434b2db..7c23cec 100644 --- a/modules/command.js +++ b/modules/command.js @@ -46,11 +46,13 @@ var command = function(dbot) { } } - if(dbot.commands.hasOwnProperty(params[0]) && (!(ignoringCommand))) { + if(dbot.commands.hasOwnProperty(params[0])) { if((dbot.db.bans.hasOwnProperty(params[0]) && dbot.db.bans[params[0]].include(data.user)) || dbot.db.bans['*'].include(data.user)) { dbot.say(data.channel, data.user + ' is banned from using this command. Commence incineration.'); + } else if(ignoringCommand) { + // do nothing, this stops us falling through to the non-command stuff } else { dbot.commands[params[0]](data, params); dbot.save();