2011-10-26 18:19:52 +02:00
|
|
|
var spelling = function(dbot) {
|
|
|
|
var dbot = dbot;
|
|
|
|
var last = {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
'listener': function(data, params) {
|
2011-10-31 18:13:41 +01:00
|
|
|
var q = data.message.valMatch(/^\*\*?([\d\w\s]*)/, 2);
|
2011-10-26 18:19:52 +02:00
|
|
|
if(q) {
|
|
|
|
var correction = q[1];
|
|
|
|
var candidates = last[data.channel][data.user].split(' ');
|
|
|
|
var winner = false;
|
2011-10-26 18:24:19 +02:00
|
|
|
var winnerDistance = 99999999; //urgh fix later
|
2011-10-26 18:19:52 +02:00
|
|
|
|
2011-10-26 18:21:21 +02:00
|
|
|
for(var i=0;i<candidates.length;i++) {
|
2011-10-26 18:19:52 +02:00
|
|
|
var distance = String.prototype.distance(correction, candidates[i]);
|
2011-10-26 18:25:41 +02:00
|
|
|
if(distance < winnerDistance) {
|
2011-10-26 18:19:52 +02:00
|
|
|
winner = candidates[i];
|
2011-10-26 18:24:19 +02:00
|
|
|
winnerDistance = distance;
|
2011-10-26 18:19:52 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-26 18:25:41 +02:00
|
|
|
|
2011-10-26 18:24:19 +02:00
|
|
|
if(winnerDistance < 3) {
|
2011-10-26 21:52:53 +02:00
|
|
|
if(winner !== correction) {
|
|
|
|
var fix = last[data.channel][data.user].replace(winner, correction);
|
2011-11-01 18:48:13 +01:00
|
|
|
last[data.channel][data.user] = fix;
|
2011-10-26 21:56:52 +02:00
|
|
|
dbot.say(data.channel, data.user + ' meant: ' + fix);
|
2011-10-26 21:52:53 +02:00
|
|
|
}
|
2011-10-26 18:19:52 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(last.hasOwnProperty(data.channel)) {
|
|
|
|
last[data.channel][data.user] = data.message;
|
|
|
|
} else {
|
|
|
|
last[data.channel] = { };
|
|
|
|
last[data.channel][data.user] = data.message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'on': 'PRIVMSG'
|
2011-10-26 18:22:19 +02:00
|
|
|
}
|
2011-10-26 18:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return spelling(dbot);
|
|
|
|
};
|