3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-28 05:32:50 +01:00

Started work on persistent timers

This commit is contained in:
amki 2015-04-06 20:46:21 +02:00
parent 7ac7817101
commit b54e5aa22d

View File

@ -3,6 +3,8 @@
* Description: Reminds you
*/
var crypto = require('crypto');
var remind = function(dbot) {
var self = this;
@ -36,26 +38,41 @@ var remind = function(dbot) {
if(dbot.config.debugMode) {
event.reply("The timer will be at "+then);
}
var cb = function() {
if(message) {
if(event.user === user) {
event.reply(user+": This is your reminder. You left a message: "+message);
} else {
event.reply(user+": This is your reminder. "+event.user+" left a message: "+message);
}
} else {
if(event.user === user) {
event.reply(user+": This is your reminder. You did not leave a message.");
} else {
event.reply(user+": This is your reminder. "+event.user+" did not leave a message.");
}
}
};
dbot.api.timers.addTimeout(then,cb,null);
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);
else
event.reply("I've set the timer.");
}.bind(this),
'startTimer': function(server, channel, time, starter, target, message) {
var cb = function() {
if(message) {
if(starter === target) {
dbot.say(server,channel,target+": This is your reminder. You left a message: "+message);
} else {
dbot.say(server,channel,target+": This is your reminder. "+starter+" left a message: "+message);
}
} else {
if(starter === target) {
dbot.say(server,channel,target+": This is your reminder. You did not leave a message.");
} else {
dbot.say(server,channel,target+": This is your reminder. "+starter+" did not leave a message.");
}
}
};
dbot.api.timers.addTimeout(time,cb,null);
dbot.say(server,channel,"Timer queued for "+time);
}.bind(this),
'saveTimer': function(server,channel,time,starter,target,message) {
var hash = this.internalAPI.getHashForTime(time);
dbot.db.remindTimers[hash] = {server:server, channel:channel, time:time.valueOf(), starter:starter, target:target, message:message};
}.bind(this),
'getHashForTime': function(time) {
var md5 = crypto.createHash('md5');
console.log(time.valueOf().toString());
md5.update(time.valueOf().toString());
return hash = md5.digest('hex');
}.bind(this)
};
@ -73,6 +90,17 @@ var remind = function(dbot) {
return;
}
this.internalAPI.doReminder(event,event.user,event.params[1],event.params.splice(2, event.params.length-1).join(' ').trim());
}
};
this.onLoad = function() {
if(!dbot.db.remindTimers) {
dbot.say("tripsit","#epow0","dbot.db.remindTimers is "+dbot.db.remindTimers);
dbot.db.remindTimers = {};
return;
}
for(var i=0;i<Object.keys(dbot.db.remindTimers).length;++i) {
dbot.say("tripsit","#epow0","Found saved timer "+dbot.db.remindTimers[i]);
}
};
};