mirror of
https://github.com/reality/dbot.git
synced 2025-02-09 02:54:22 +01:00
Fix up spelling [#131]
This commit is contained in:
parent
6896536a3b
commit
478d344fe2
@ -74,9 +74,13 @@ var distance = function(s1, s2) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var spelling = function(dbot) {
|
var spelling = function(dbot) {
|
||||||
var last = {};
|
this.name = 'spelling';
|
||||||
var correct = function (event, correction, candidate, output_callback) {
|
this.ignorable = true;
|
||||||
var rawCandidates = allGroupings(last[event.channel.name][candidate].split(' '));
|
|
||||||
|
this.last = {};
|
||||||
|
this.internalAPI = {};
|
||||||
|
this.internalAPI.correct = function (event, correction, candidate, output_callback) {
|
||||||
|
var rawCandidates = allGroupings(this.last[event.channel.name][candidate].split(' '));
|
||||||
|
|
||||||
var candidates = [];
|
var candidates = [];
|
||||||
for(var i=0;i<rawCandidates.length;i++) {
|
for(var i=0;i<rawCandidates.length;i++) {
|
||||||
@ -95,11 +99,11 @@ var spelling = function(dbot) {
|
|||||||
|
|
||||||
if(winnerDistance < Math.ceil(winner.length * 1.33)) {
|
if(winnerDistance < Math.ceil(winner.length * 1.33)) {
|
||||||
if(winner !== correction) {
|
if(winner !== correction) {
|
||||||
var fix = last[event.channel.name][candidate].replace(winner, correction);
|
var fix = this.last[event.channel.name][candidate].replace(winner, correction);
|
||||||
if (/^.ACTION/.test(fix)) {
|
if (/^.ACTION/.test(fix)) {
|
||||||
fix = fix.replace(/^.ACTION/, '/me');
|
fix = fix.replace(/^.ACTION/, '/me');
|
||||||
}
|
}
|
||||||
last[event.channel.name][candidate] = fix;
|
this.last[event.channel.name][candidate] = fix;
|
||||||
var output = {
|
var output = {
|
||||||
'fix': fix,
|
'fix': fix,
|
||||||
'correcter': event.user,
|
'correcter': event.user,
|
||||||
@ -108,36 +112,31 @@ var spelling = function(dbot) {
|
|||||||
output_callback(output);
|
output_callback(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}.bind(this);
|
||||||
|
|
||||||
return {
|
this.listener = function(event) {
|
||||||
'name': 'spelling',
|
|
||||||
'ignorable': true,
|
|
||||||
|
|
||||||
'listener': function(event) {
|
|
||||||
var q = event.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3);
|
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);
|
var otherQ = event.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4);
|
||||||
if(q) {
|
if(q) {
|
||||||
correct(event, q[1] || q[2], event.user, function (e) {
|
this.internalAPI.correct(event, q[1] || q[2], event.user, function (e) {
|
||||||
event.reply(dbot.t('spelling_self', e));
|
event.reply(dbot.t('spelling_self', e));
|
||||||
});
|
});
|
||||||
} else if(otherQ) {
|
} else if(otherQ) {
|
||||||
correct(event, otherQ[2] || otherQ[3], otherQ[1], function (e) {
|
this.internalAPI.correct(event, otherQ[2] || otherQ[3], otherQ[1], function (e) {
|
||||||
event.reply(dbot.t('spelling_other', e));
|
event.reply(dbot.t('spelling_other', e));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if(_.has(last, event.channel.name)) {
|
if(_.has(this.last, event.channel.name)) {
|
||||||
last[event.channel.name][event.user] = event.message;
|
this.last[event.channel.name][event.user] = event.message;
|
||||||
} else {
|
} else {
|
||||||
last[event.channel.name] = { };
|
this.last[event.channel.name] = { };
|
||||||
last[event.channel.name][event.user] = event.message;
|
this.last[event.channel.name][event.user] = event.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}.bind(this);
|
||||||
'on': 'PRIVMSG'
|
this.on = 'PRIVMSG';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetch = function(dbot) {
|
exports.fetch = function(dbot) {
|
||||||
return spelling(dbot);
|
return new spelling(dbot);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user