From fc068119076e163d26f3a72018c624f5608d23b2 Mon Sep 17 00:00:00 2001 From: amki Date: Mon, 6 Apr 2015 23:38:21 +0200 Subject: [PATCH] Fixed bugs, removed debug output, timers now persistent --- modules/remind/remind.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/remind/remind.js b/modules/remind/remind.js index 7ef9a2b..29ad279 100644 --- a/modules/remind/remind.js +++ b/modules/remind/remind.js @@ -35,18 +35,16 @@ var remind = function(dbot) { timeinseconds += this.internalAPI.getSeconds(number,interval); } var then = new Date(now + (timeinseconds*1000)); - if(dbot.config.debugMode) { + if(dbot.config.debugMode) event.reply("The timer will be at "+then); - } this.internalAPI.startTimer(event.server,event.channel,then,event.user,user,message); this.internalAPI.saveTimer(event.server,event.channel,then,event.user,user,message); if(message) - event.reply("I've set the timer with message "+message); + event.reply("I have set the timer with your message \""+message+"\""); else - event.reply("I've set the timer."); + event.reply("I have set the timer."); }.bind(this), 'startTimer': function(server, channel, time, starter, target, message) { - dbot.say(server,channel,"startTimer called!"); var cb = function() { if(message) { if(starter === target) { @@ -61,10 +59,14 @@ var remind = function(dbot) { dbot.say(server,channel,target+": This is your reminder. "+starter+" did not leave a message."); } } - dbot.say(server,channel,"REMOTE THE FUCKING TIMER NOW!"); + var hash = self.internalAPI.getHashForTime(time); + if(dbot.config.debugMode) + dbot.say(server,channel,"Removing timer with hash "+hash); + delete dbot.db.remindTimers[hash]; }; dbot.api.timers.addTimeout(time,cb,null); - dbot.say(server,channel,"Timer queued for "+time); + if(dbot.config.debugMode) + dbot.say(server,channel,"Timer queued for "+time); }.bind(this), 'saveTimer': function(server,channel,time,starter,target,message) { var hash = this.internalAPI.getHashForTime(time); @@ -97,21 +99,20 @@ var remind = function(dbot) { this.onLoad = function() { if(!dbot.db.remindTimers) { - dbot.say("tripsit","#epow0","dbot.db.remindTimers is "+dbot.db.remindTimers); dbot.db.remindTimers = {}; return; } - dbot.say("tripsit","#epow0","dbot.db.remindTimers has length "+Object.keys(dbot.db.remindTimers).length); for(var i=0;i