Merge git://github.com/reality/depressionbot into database

This commit is contained in:
reality 2013-04-12 19:29:03 +00:00
commit 36254c9e03
8 changed files with 54 additions and 26 deletions

View File

@ -64,20 +64,13 @@ var dent = function(dbot) {
}
}.bind(this));
}
}.bind(this);
this.listener = function(event) {
for (s in this.StatusRegex) {
if (this.StatusRegex.hasOwnProperty(s)) {
var matches = this.StatusRegex[s].exec(event.message);
if (matches != null) {
this.lookup(event, matches[1], s);
}
}
}
}.bind(this);
this.on = 'PRIVMSG';
for(s in this.StatusRegex) {
dbot.api.link.addHandler(s, this.StatusRegex[s], function(event, matches, name) {
this.lookup(event, matches[1], name);
}.bind(this));
}
}.bind(this);
};
exports.fetch = function(dbot) {

View File

@ -12,8 +12,14 @@ var flashy = function(dbot) {
'green': '00FF00',
'blue': '0000FF',
'yellow': 'FFFF00',
'pink': 'FFC0CB',
'magenta': 'FF00FF',
'cyan': '00FFFF'
'purple': 'AA00FF',
'cyan': '00FFFF',
'orange': 'FFAA00',
'lime': 'AAFF00',
'grey': 'AAAAAA',
'infrared': '000000'
};
this.commands = {

View File

@ -31,7 +31,7 @@ var imgur = function(dbot) {
this.commands = {
'~ri': function(event) {
this.api.getRandomImage(function(link) {
event.reply(event.user + ': ' + link);
event.reply(event.user + ': (' + dbot.t('nsfw') + ') ' + link);
});
}
}

View File

@ -0,0 +1,6 @@
{
"nsfw": {
"en": "might be NSFW",
"na'vi": "kxawm ke wivìntxu evengur"
}
}

View File

@ -10,6 +10,7 @@ var request = require('request'),
var link = function(dbot) {
this.urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
this.links = {};
this.handlers = [];
this.fetchTitle = function(event, link) {
var limit = 1000000,
size = 0,
@ -30,6 +31,16 @@ var link = function(dbot) {
}
});
};
this.api = {
'addHandler': function(name, regex, handler) {
this.handlers.push({
'name': name,
'regex': regex,
'callback': handler
});
}
};
var commands = {
'~title': function(event) {
@ -84,7 +95,7 @@ var link = function(dbot) {
try {
var result = JSON.parse(body);
if(_.has(result, 'result_type') && result.result_type != 'no_results') {
event.reply(query + ': ' + result.list[0].definition.split('\n')[0]);
event.reply(result.list[0].word + ': ' + result.list[0].definition.split('\n')[0]);
} else {
event.reply(event.user + ': No definition found.');
}
@ -100,7 +111,15 @@ var link = function(dbot) {
if(urlMatches !== null) {
this.links[event.channel.name] = urlMatches[0];
if(dbot.config.link.autoTitle == true) {
this.fetchTitle(event, urlMatches[0]);
var handlerFound = false;
for(var i=0;i<this.handlers.length;i++) {
var matches = this.handlers[i].regex.exec(urlMatches[0]);
if(matches) {
this.handlers[i].callback(event, matches, this.handlers[i].name);
handlerFound = true; break;
}
}
if(!handlerFound) this.fetchTitle(event, urlMatches[0]);
}
}
}.bind(this);

View File

@ -1,5 +1,6 @@
{
"ignorable": true,
"notifyVoice": false,
"dependencies": [ "command", "users" ],
"help": "http://github.com/reality/depressionbot/blob/master/modules/report/README.md"
}

View File

@ -12,8 +12,12 @@ var report = function(dbot) {
if(dbot.api.users.isChannelUser(event.server, nick, channelName, true)) {
var nick = dbot.api.users.resolveUser(event.server, nick, true);
var ops = _.filter(channel.nicks, function(user) {
return user.op;
});
if(this.config.notifyVoice) {
return user.op || user.voice;
} else {
return user.op;
}
}, this);
_.each(ops, function(user) {
dbot.say(event.server, user.name, dbot.t('report', {

View File

@ -58,14 +58,13 @@ var spotify = function(dbot) {
}
};
commands['~spotify'].regex = [/^~spotify (.*)/, 2];
this.listener = function(event) {
var spotifyMatches = event.message.match(this.spotifyRegex);
if (spotifyMatches != null) {
this.lookup(event, spotifyMatches[0]);
}
}.bind(this);
this.on = 'PRIVMSG';
this.commands = commands;
this.onLoad = function() {
dbot.api.link.addHandler(this.name, this.spotifyRegex, function(event, matches, name) {
this.lookup(event, matches[0]);
}.bind(this));
}.bind(this);
};
exports.fetch = function(dbot) {