2013-01-21 20:42:51 +01:00
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
|
|
|
var regex = function(dbot) {
|
|
|
|
this.last = {};
|
|
|
|
this.listener = function(event) {
|
2013-01-21 21:14:51 +01:00
|
|
|
var q = event.message.valMatch(/^([\d\w\s]*)?:? ?s\/(.+)\/(.+)\/$/, 4);
|
2013-01-21 20:42:51 +01:00
|
|
|
if(q) {
|
2013-01-21 21:14:51 +01:00
|
|
|
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);
|
|
|
|
}
|
2013-01-21 20:42:51 +01:00
|
|
|
} else {
|
|
|
|
if(_.has(this.last, event.channel.name)) {
|
|
|
|
this.last[event.channel.name][event.user] = event.message;
|
|
|
|
} else {
|
|
|
|
this.last[event.channel.name] = { };
|
|
|
|
this.last[event.channel.name][event.user] = event.message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.bind(this);
|
|
|
|
this.on = [ 'PRIVMSG' ];
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return new regex(dbot);
|
|
|
|
};
|