3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 22:39:26 +01:00

Merge branch 'master' of github.com:reality/depressionbot

This commit is contained in:
Luke Slater 2012-02-13 03:49:48 +00:00
commit 2cd7a3992c
5 changed files with 66 additions and 116 deletions

View File

@ -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);
};

View File

@ -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<kickArr.length;i++) {
kickString += kickArr[i][0] + " (" + kickArr[i][1] + "), ";
}
return kickString.slice(0, -2);
};
dbot.say(data.channel, orderedKickLeague(dbot.db.kicks, 'Kicked'));
dbot.say(data.channel, orderedKickLeague(dbot.db.kickers, 'Kickers'));
}
};
return {
// Counts kicks
'listener': function(data) {
if(data.kickee == dbot.name) {
dbot.instance.join(data.channel);
@ -35,7 +82,12 @@ var kick = function(dbot) {
}
},
on: 'KICK'
on: 'KICK',
'onLoad': function() {
return commands;
}
};
};

View File

@ -1,76 +0,0 @@
var userCommands = function(dbot) {
var dbot = dbot;
var commands = {
'~kc': function(data, params) {
dbot.say('aisbot', '.karma ' + data.message.split(' ')[1]);
dbot.waitingForKarma = data.channel;
},
'~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.');
},
'~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 orderedKicks = kickArr.sort(function(a, b) { return a[1] - b[1]; });
var topKicks = kickArr.slice(kickArr.length - 10).reverse();
var kickString = "Top Kicked: ";
for(var i=0;i<topKicks.length;i++) {
kickString += topKicks[i][0] + " (" + topKicks[i][1] + "), ";
}
kickString = kickString.slice(0, -2);
dbot.say(data.channel, kickString);
// code repetition bad
var kickArr = [];
for(var kickUser in dbot.db.kickers) {
if(dbot.db.kickers.hasOwnProperty(kickUser)) {
kickArr.push([kickUser, dbot.db.kickers[kickUser]]);
}
}
var orderedKicks = kickArr.sort(function(a, b) { return a[1] - b[1]; });
var topKicks = kickArr.slice(kickArr.length - 10).reverse();
var kickString = "Top Kickers: ";
for(var i=0;i<topKicks.length;i++) {
kickString += topKicks[i][0] + " (" + topKicks[i][1] + "), ";
}
kickString = kickString.slice(0, -2);
dbot.say(data.channel, kickString);
}
};
return {
'onLoad': function() {
return commands;
}
};
};
exports.fetch = function(dbot) {
return userCommands(dbot);
};

View File

@ -1,5 +1,6 @@
var express = require('express');
// Web interface module using the express framework
var webInterface = function(dbot) {
var dbot = dbot;
@ -15,21 +16,27 @@ var webInterface = function(dbot) {
//res.render('index', { });
});
app.get('/quotes', function(req, res) {
// Lists the quote categories
app.get('/quotes', function(req, res) {
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(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() } });
});
app.listen(443);
return {

9
run.js
View File

@ -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,9 +13,9 @@ 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', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'web', 'youare' ];
this.timers = timers.create();
this.waitingForKarma = false;
this.instance = jsbot.createJSBot(this.name, this.server, this.port, this, function() {
if(this.config.hasOwnProperty('channels')) {
@ -27,7 +25,6 @@ var DBot = function(dModules, timers) {
}
}.bind(this), this.nickserv, this.password);
this.moduleNames = dModules;
this.reloadModules();
this.instance.connect();
};
@ -134,4 +131,4 @@ DBot.prototype.cleanNick = function(key) {
return key;
}
new DBot(modules, timers);
new DBot(timers);