mirror of
https://github.com/reality/dbot.git
synced 2024-12-12 13:59:26 +01:00
64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
/**
|
|
* Module name: tell
|
|
* Description: tell people things when they r next about
|
|
*/
|
|
|
|
var _ = require('underscore')._,
|
|
request = require('request');
|
|
|
|
var tell = function(dbot) {
|
|
if(!_.has(dbot.db, 'tells')) {
|
|
dbot.db.tells = {};
|
|
}
|
|
var tells = dbot.db.tells;
|
|
|
|
this.commands = {
|
|
'tell': function(event) {
|
|
var target = event.input[1],
|
|
message = event.input[2];
|
|
|
|
dbot.api.users.resolveUser(event.server, target, function(err, user) {
|
|
if(!err && user) {
|
|
if(!_.has(tells, user.id)) {
|
|
tells[user.id] = [];
|
|
}
|
|
|
|
if(_.any(tells[user.id], function(it) { return it.from == event.user; })) {
|
|
return event.reply('Don\'t be a Repetitious Reginald - you can only leave one message for ' + target + '!');
|
|
} else if(user.id == event.rUser.id) {
|
|
return event.reply('Take a long look in the mirror mate, that\'s you');
|
|
}
|
|
|
|
tells[user.id].push({
|
|
'channel': event.channel.name,
|
|
'message': event.message,
|
|
'from': event.user
|
|
}); // i feel like i'm data structure challenged today
|
|
event.reply(event.user + ': I will probably relay your message to ' + target + ' when I see them in this channel next');
|
|
} else {
|
|
event.reply('no idea who that is mate');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
this.commands.tell.regex = [/tell ([^ ]+) (.+)/, 3];
|
|
|
|
this.listener = function(event) {
|
|
if(_.has(tells, event.rUser.id)) {
|
|
var done = [];
|
|
_.each(tells[event.rUser.id], function(tell, i) {
|
|
if(event.channel.name == tell.channel) {
|
|
event.reply('Dear ' + event.user + ', ' + tell.from + ' left you a message: ' + tell.message);
|
|
tells[event.rUser.id].splice(i, 1);
|
|
}
|
|
}); // i disgust me
|
|
tells[event.rUser.id] = _.without(tells[event.rUser.id], done);
|
|
}
|
|
}.bind(this);
|
|
this.on = 'PRIVMSG';
|
|
};
|
|
|
|
exports.fetch = function(dbot) {
|
|
return new tell(dbot);
|
|
};
|