forked from GitHub/dbot
more efficient regex code
This commit is contained in:
parent
8ca4796295
commit
9befd818d5
@ -9,21 +9,22 @@ var regex = function(dbot) {
|
|||||||
toMatch = new RegExp(q[2], flags),
|
toMatch = new RegExp(q[2], flags),
|
||||||
replaceWith = q[3],
|
replaceWith = q[3],
|
||||||
last,
|
last,
|
||||||
replacement;
|
replacement,
|
||||||
|
user;
|
||||||
|
|
||||||
if(!replaceWith) replaceWith = "";
|
if(!replaceWith) replaceWith = "";
|
||||||
|
|
||||||
if(q[1] != null) {
|
user = q[1] || event.user;
|
||||||
var user = q[1];
|
|
||||||
last = this.last[event.channel.name][user];
|
last = this.last[event.channel.name][user];
|
||||||
replacement = last.replace(toMatch, replaceWith);
|
replacement = last.replace(toMatch, replaceWith);
|
||||||
replacement = replacement.replace(/^.ACTION/, user).replace("\x01", '');
|
replacement = replacement.replace(/^.ACTION/, user).replace("\x01", '');
|
||||||
if(replacement != last) event.reply(event.user + " thinks " + user + " meant: " + replacement);
|
|
||||||
|
if(replacement != last) {
|
||||||
|
if(q[1]) {
|
||||||
|
event.reply(event.user + " thinks " + user + " meant: " + replacement);
|
||||||
} else {
|
} else {
|
||||||
last = this.last[event.channel.name][event.user];
|
event.reply(event.user + " meant: " + replacement);
|
||||||
replacement = last.replace(toMatch, replaceWith);
|
}
|
||||||
replacement = replacement.replace(/^.ACTION/, event.user).replace("\x01", '');
|
|
||||||
if(replacement != last) event.reply(event.user + " meant: " + replacement);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(_.has(this.last, event.channel.name)) {
|
if(_.has(this.last, event.channel.name)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user