var spelling = function(dbot) { var name = 'spelling'; var dbot = dbot; var last = {}; var correct = function (event, correction, candidate, output_callback) { var rawCandidates = last[event.channel][candidate].split(' ').allGroupings(); var candidates = []; for(var i=0;i 0)) { winner = candidates[i]; winnerDistance = distance; } } if(winnerDistance < Math.ceil(winner.length * 1.33)) { if(winner !== correction) { var fix = last[event.channel][candidate].replace(winner, correction); if (/^.ACTION/.test(fix)) { fix = fix.replace(/^.ACTION/, '/me'); } last[event.channel][candidate] = fix; var output = { 'fix': fix, 'correcter': event.user, 'candidate': candidate }; output_callback(output); } } } return { 'listener': function(event) { if((dbot.db.ignores.hasOwnProperty(event.user) && dbot.db.ignores[event.user].include(name)) == false) { var q = event.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); var otherQ = event.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4); if(q) { correct(event, q[1] || q[2], event.user, function (e) { event.reply(dbot.t('spelling_self', e)); }); } else if(otherQ) { correct(event, otherQ[2] || otherQ[3], otherQ[1], function (e) { event.reply(dbot.t('spelling_other', e)); }); } else { if(last.hasOwnProperty(event.channel)) { last[event.channel][event.user] = event.message; } else { last[event.channel] = { }; last[event.channel][event.user] = event.message; } } } }, 'on': 'PRIVMSG', 'name': name, 'ignorable': true } } exports.fetch = function(dbot) { return spelling(dbot); };