mirror of
https://github.com/reality/dbot.git
synced 2024-12-24 03:33:07 +01:00
Bit more efficient. dont bother saying the replacement if replacement not made [#154]
This commit is contained in:
parent
400d215734
commit
24bb198c5d
@ -3,19 +3,23 @@ var _ = require('underscore')._;
|
||||
var regex = function(dbot) {
|
||||
this.last = {};
|
||||
this.listener = function(event) {
|
||||
var q = event.message.valMatch(/^s\/(.+)\/(.+)\/$/, 3);
|
||||
var otherQ = event.message.valMatch(/^([\d\w\s]*): s\/(.+)\/(.+)\/$/, 4);
|
||||
var q = event.message.valMatch(/^([\d\w\s]*)?:? ?s\/(.+)\/(.+)\/$/, 4);
|
||||
if(q) {
|
||||
var toMatch = new RegExp(q[1]);
|
||||
var replaceWith = q[2];
|
||||
var last = this.last[event.channel.name][event.user];
|
||||
event.reply(event.user + " meant: " + last.replace(toMatch, replaceWith));
|
||||
} else if(otherQ) {
|
||||
var user = otherQ[1];
|
||||
var toMatch = new RegExp(otherQ[2]);
|
||||
var replaceWith = otherQ[3];
|
||||
var last = this.last[event.channel.name][user];
|
||||
event.reply(event.user + " thinks " + user + " meant: " + last.replace(toMatch, replaceWith));
|
||||
var toMatch = new RegExp(q[2]),
|
||||
replaceWith = q[3],
|
||||
last,
|
||||
replacement;
|
||||
|
||||
if(q[1] != null) {
|
||||
var user = q[1];
|
||||
last = this.last[event.channel.name][user];
|
||||
replacement = last.replace(toMatch, replaceWith);
|
||||
if(replacement != last) event.reply(event.user + " thinks " + user + " meant: " + replacement);
|
||||
} else {
|
||||
last = this.last[event.channel.name][event.user];
|
||||
replacement = last.replace(toMatch, replaceWith);
|
||||
if(replacement != last) event.reply(event.user + " meant: " + replacement);
|
||||
}
|
||||
} else {
|
||||
if(_.has(this.last, event.channel.name)) {
|
||||
this.last[event.channel.name][event.user] = event.message;
|
||||
|
Loading…
Reference in New Issue
Block a user