diff --git a/modules/remind/remind.js b/modules/remind/remind.js index a2ca5b9..da9886e 100644 --- a/modules/remind/remind.js +++ b/modules/remind/remind.js @@ -11,52 +11,77 @@ var remind = function(dbot) { var self = this; this.api = { - 'parseTime': function(time) { - var now = Date.now(); - var datesplits = time.match(/[0-9]+[dhmsy]/g); - if(datesplits == null) { - return; + 'parseTime': function(time) { + var components = time.match(/[0-9]+[ydhms]/g); + if (!components) + return; + + var seconds = 0; + for (var i=0; i < components.length; ++i) { + var value = parseInt(components[i].match(/[0-9]+/)[0]), + component = components[i].match(/[ydhms]/)[0]; + + if (!component) + return; + + seconds += this.internalAPI.getSeconds(value,component); + } + + return new Date(Date.now() + (seconds * 1000)); } - var timeinseconds = 0; - for(var i=0;i 0) { - var output = ''; - _.each(reminders, function(reminder, i) { - output += (i+1) + ': "' + reminder.message + '" in ' + moment(reminder.time).toNow(true) + '. '; - }); - event.reply('You have ' + _.size(reminders) + ' active reminders. ' + output); - } else { - event.reply('You have no currently active timers.'); - } - } + + var r = this.internalAPI.parseParams(event.params.slice(1, event.params.length)); + this.internalAPI.doReminder(event, event.user, r[0], r[1]); + }, + + '~myreminders': function(event) { + var reminders = _.filter(dbot.db.remindTimers, function(t){ return t.target == event.user; }); + if(_.size(reminders) > 0) { + var output = ''; + _.each(reminders, function(reminder, i) { + output += (i+1) + ': "' + reminder.message + '" in ' + moment(reminder.time).toNow(true) + '. '; + }); + event.reply('You have ' + _.size(reminders) + ' active reminders. ' + output); + } + else { + event.reply('You have no currently active timers.'); + } + } }; this.onLoad = function() { @@ -133,7 +167,7 @@ var remind = function(dbot) { var prop = dbot.db.remindTimers[Object.keys(dbot.db.remindTimers)[i]]; if(parseInt(prop.time) < Date.now().valueOf()) { if(dbot.config.debugMode) - console.log("This timer is old I shall delete it."); + console.log("This timer is old. I shall delete it."); delete dbot.db.remindTimers[Object.keys(dbot.db.remindTimers)[i]]; continue; }