forked from GitHub/dbot
Basic regex replace support [#154]
This commit is contained in:
parent
4d01187346
commit
d8c133a7b3
3
modules/regex/config.json
Normal file
3
modules/regex/config.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"ignorable": true
|
||||
}
|
26
modules/regex/regex.js
Normal file
26
modules/regex/regex.js
Normal file
@ -0,0 +1,26 @@
|
||||
var _ = require('underscore')._;
|
||||
|
||||
var regex = function(dbot) {
|
||||
this.last = {};
|
||||
this.listener = function(event) {
|
||||
var q = event.message.valMatch(/^s\/(.+)\/(.+)\/$/, 3);
|
||||
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(_.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);
|
||||
};
|
Loading…
Reference in New Issue
Block a user