From 0c4b86dc28685154e45af74002e8fda0e8070daa Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 11 Feb 2012 15:53:18 +0000 Subject: [PATCH 1/8] Random quote page on the web interface. --- modules/web.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/web.js b/modules/web.js index 28bbfd1..94f8fba 100644 --- a/modules/web.js +++ b/modules/web.js @@ -15,20 +15,26 @@ var webInterface = function(dbot) { //res.render('index', { }); }); + // Lists the quote categories app.get('/quotes', function(req, res) { - // Lists the quote categories res.render('quotelist', { 'quotelist': Object.keys(dbot.db.quoteArrs) }); }); + // Lists quotes in a category app.get('/quotes/:key', function(req, res) { - // Lists the quotes in a category var key = req.params.key.toLowerCase(); if(dbot.db.quoteArrs.hasOwnProperty(key)) { - res.render('quotes', { 'quotes': dbot.db.quoteArrs[key], locals: {url_regex: RegExp.prototype.url_regex()}}); + res.render('quotes', { 'quotes': dbot.db.quoteArrs[key], locals: { 'url_regex': RegExp.prototype.url_regex() } }); } else { res.render('error', { 'message': 'No quotes under that key.' }); } }); + + // Load random quote category page + app.get('/rq', function() { + var rCategory = Object.keys(dbot.db.quoteArrs).random(); + res.render('quotes', { 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } }); + }); app.listen(443); From 5ef21027ea4df49ca8ca9687188cdd41606c9242 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 11 Feb 2012 15:55:14 +0000 Subject: [PATCH 2/8] Forgot to add req and res entry --- modules/web.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/web.js b/modules/web.js index 94f8fba..7628272 100644 --- a/modules/web.js +++ b/modules/web.js @@ -31,7 +31,7 @@ var webInterface = function(dbot) { }); // Load random quote category page - app.get('/rq', function() { + app.get('/rq', function(req, res) { var rCategory = Object.keys(dbot.db.quoteArrs).random(); res.render('quotes', { 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } }); }); From e79854638a0603187f2b6269e6892888b7bf1ea4 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 11 Feb 2012 16:02:16 +0000 Subject: [PATCH 3/8] Commenting additions and moved module list specification into the config file. --- modules/web.js | 1 + run.js | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/web.js b/modules/web.js index 7628272..2f7c1f0 100644 --- a/modules/web.js +++ b/modules/web.js @@ -1,5 +1,6 @@ var express = require('express'); +// Web interface module using the express framework var webInterface = function(dbot) { var dbot = dbot; diff --git a/run.js b/run.js index 7a523aa..95b201e 100644 --- a/run.js +++ b/run.js @@ -3,9 +3,7 @@ var timers = require('./timer'); var jsbot = require('./jsbot'); require('./snippets'); -var modules = [ 'js', 'admin', 'karma', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'user', 'web', 'youare' ]; - -var DBot = function(dModules, timers) { +var DBot = function(timers) { this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); @@ -15,6 +13,7 @@ var DBot = function(dModules, timers) { this.nickserv = this.config.nickserv || 'zippy'; this.server = this.config.server || 'elara.ivixor.net'; this.port = this.config.port || 6667; + this.moduleNames = this.config.modules || [ 'js', 'admin', 'karma', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'user', 'web', 'youare' ]; this.timers = timers.create(); this.waitingForKarma = false; @@ -27,7 +26,6 @@ var DBot = function(dModules, timers) { } }.bind(this), this.nickserv, this.password); - this.moduleNames = dModules; this.reloadModules(); this.instance.connect(); }; From c798e42152f04ae3fcbb13a2310b7a93cb119d41 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 11 Feb 2012 16:17:52 +0000 Subject: [PATCH 4/8] Refactored ~kickstats so there's no code repitition. --- modules/user.js | 52 ++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/modules/user.js b/modules/user.js index b0d6142..a3efd29 100644 --- a/modules/user.js +++ b/modules/user.js @@ -1,12 +1,16 @@ +// Commands that probably belong elsewhere. var userCommands = function(dbot) { var dbot = dbot; var commands = { + // Give a karma comment for a given user '~kc': function(data, params) { dbot.say('aisbot', '.karma ' + data.message.split(' ')[1]); dbot.waitingForKarma = data.channel; }, + // Give the number of times a given user has been kicked and has kicked + // other people. '~kickcount': function(data, params) { if(!dbot.db.kicks.hasOwnProperty(params[1])) { var kicks = '0'; @@ -20,47 +24,33 @@ var userCommands = function(dbot) { var kicked = dbot.db.kickers[params[1]]; } - dbot.say(data.channel, params[1] + ' has been kicked ' + kicks + ' times and has kicked people ' + kicked + ' times.'); }, + // Output a list of the people who have been kicked the most and those + // who have kicked other people the most. '~kickstats': function(data, params) { - var kickArr = []; - for(var kickUser in dbot.db.kicks) { - if(dbot.db.kicks.hasOwnProperty(kickUser)) { - kickArr.push([kickUser, dbot.db.kicks[kickUser]]); + var orderedKickLeague = function(list, topWhat) { + var kickArr = []; + for(var kickUser in list) { + if(list.hasOwnProperty(kickUser)) { + kickArr.push([kickUser, list[kickUser]]); + } } - } - var orderedKicks = kickArr.sort(function(a, b) { return a[1] - b[1]; }); - var topKicks = kickArr.slice(kickArr.length - 10).reverse(); - var kickString = "Top Kicked: "; + kickArr = kickArr.sort(function(a, b) { return a[1] - b[1]; }); + kickArr = kickArr.slice(kickArr.length - 10).reverse(); + var kickString = "Top " + topWhat + ": "; - for(var i=0;i Date: Sat, 11 Feb 2012 16:19:40 +0000 Subject: [PATCH 5/8] Fix kickArr reference in ~kickstats --- modules/user.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/user.js b/modules/user.js index a3efd29..a28155d 100644 --- a/modules/user.js +++ b/modules/user.js @@ -42,8 +42,8 @@ var userCommands = function(dbot) { kickArr = kickArr.slice(kickArr.length - 10).reverse(); var kickString = "Top " + topWhat + ": "; - for(var i=0;i Date: Sat, 11 Feb 2012 16:25:20 +0000 Subject: [PATCH 6/8] Remove karma related commands because they're stupid, moved kick-related commands into the kick module. --- modules/karma.js | 30 ---------------------- modules/kick.js | 54 ++++++++++++++++++++++++++++++++++++++- modules/user.js | 66 ------------------------------------------------ run.js | 1 - 4 files changed, 53 insertions(+), 98 deletions(-) delete mode 100644 modules/karma.js delete mode 100644 modules/user.js diff --git a/modules/karma.js b/modules/karma.js deleted file mode 100644 index 7218e74..0000000 --- a/modules/karma.js +++ /dev/null @@ -1,30 +0,0 @@ -var karma = function(dbot) { - var dbot = dbot; - - return { - 'listener': function(data) { - if(data.user == 'aisbot' && data.channel == 'aisbot' && - dbot.waitingForKarma != false && data.message.match(/is at/)) { - var split = data.message.split(' '); - var target = split[0]; - var karma = split[3]; - - if(karma.startsWith('-')) { - dbot.say(dbot.waitingForKarma, target + dbot.db.hatedPhrases.random() + ' (' + karma + ')'); - } else if(karma == '0') { - dbot.say(dbot.waitingForKarma, target + dbot.db.neutralPhrases.random() + ' (0)'); - } else { - dbot.say(dbot.waitingForKarma, target + dbot.db.lovedPhrases.random() + ' (' + karma + ')'); - } - - dbot.waitingForKarma = false; - } - }, - - 'on': 'PRIVMSG' - } -}; - -exports.fetch = function(dbot) { - return karma(dbot); -}; diff --git a/modules/kick.js b/modules/kick.js index 024e2a3..64e17bb 100644 --- a/modules/kick.js +++ b/modules/kick.js @@ -1,7 +1,54 @@ var kick = function(dbot) { var dbot = dbot; + + var commands = { + // Give the number of times a given user has been kicked and has kicked + // other people. + '~kickcount': function(data, params) { + if(!dbot.db.kicks.hasOwnProperty(params[1])) { + var kicks = '0'; + } else { + var kicks = dbot.db.kicks[params[1]]; + } + + if(!dbot.db.kickers.hasOwnProperty(params[1])) { + var kicked = '0'; + } else { + var kicked = dbot.db.kickers[params[1]]; + } + + dbot.say(data.channel, params[1] + ' has been kicked ' + kicks + ' times and has kicked people ' + kicked + ' times.'); + }, + + // Output a list of the people who have been kicked the most and those + // who have kicked other people the most. + '~kickstats': function(data, params) { + var orderedKickLeague = function(list, topWhat) { + var kickArr = []; + for(var kickUser in list) { + if(list.hasOwnProperty(kickUser)) { + kickArr.push([kickUser, list[kickUser]]); + } + } + + kickArr = kickArr.sort(function(a, b) { return a[1] - b[1]; }); + kickArr = kickArr.slice(kickArr.length - 10).reverse(); + var kickString = "Top " + topWhat + ": "; + + for(var i=0;i Date: Sat, 11 Feb 2012 16:26:29 +0000 Subject: [PATCH 7/8] remove modules call when instantiating new dbot --- run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.js b/run.js index f5ec6a2..8cdc538 100644 --- a/run.js +++ b/run.js @@ -131,4 +131,4 @@ DBot.prototype.cleanNick = function(key) { return key; } -new DBot(modules, timers); +new DBot(timers); From c50e20d7bb2a90957355ce8cc85d5a58c8d0a15d Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 11 Feb 2012 16:27:30 +0000 Subject: [PATCH 8/8] Remove karma and user from default modules --- run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.js b/run.js index 8cdc538..b8c6966 100644 --- a/run.js +++ b/run.js @@ -13,7 +13,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.moduleNames = this.config.modules || [ 'js', 'admin', 'karma', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'user', 'web', 'youare' ]; + this.moduleNames = this.config.modules || [ 'js', 'admin', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'web', 'youare' ]; this.timers = timers.create();