From eebf1d968072b7507d07ebd2d666c4fa38279e1a Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 9 Dec 2015 18:53:32 +0000 Subject: [PATCH] tell --- modules/tell/tell.js | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 modules/tell/tell.js diff --git a/modules/tell/tell.js b/modules/tell/tell.js new file mode 100644 index 0000000..0855332 --- /dev/null +++ b/modules/tell/tell.js @@ -0,0 +1,61 @@ +/** + * 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, + '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) { + 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); +};