forked from GitHub/dbot
Merge pull request #643 from amki/remind
Added remind module according to #171
This commit is contained in:
commit
448309dc37
20
modules/remind/README.md
Normal file
20
modules/remind/README.md
Normal file
@ -0,0 +1,20 @@
|
||||
## Remind
|
||||
|
||||
Reminder!
|
||||
|
||||
### Description
|
||||
This module reminds you!
|
||||
|
||||
### TIME
|
||||
The TIME parameter for this module needs to be in a fashion NdNhNmNs.
|
||||
Example: 4d3h2m1s
|
||||
You can give skip parameters if you like. (Example: 4d5m)
|
||||
|
||||
### Commands
|
||||
|
||||
#### ~remind [USER] [TIME] [MESSAGE]
|
||||
Reminds you in now+TIME with message [MESSAGE]
|
||||
|
||||
#### ~remindme [TIME] [MESSAGE]
|
||||
Reminds the given user in now+TIME with message [MESSAGE]
|
||||
|
73
modules/remind/remind.js
Normal file
73
modules/remind/remind.js
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Module Name: Remind
|
||||
* Description: Reminds you
|
||||
*/
|
||||
|
||||
var remind = function(dbot) {
|
||||
var self = this;
|
||||
|
||||
this.internalAPI = {
|
||||
'getSeconds': function(number,interval) {
|
||||
switch(interval) {
|
||||
case "d":
|
||||
return number*24*60*60;
|
||||
case "h":
|
||||
return number*60*60;
|
||||
case "m":
|
||||
return number*60;
|
||||
case "s":
|
||||
return number;
|
||||
}
|
||||
}.bind(this),
|
||||
'doReminder': function(event,user,time,message) {
|
||||
var now = Date.now();
|
||||
var datesplits = time.match(/[0-9]+[dhms]/g);
|
||||
if(datesplits == null) {
|
||||
event.reply("The time parameter was not a valid time mah boy, it was "+time);
|
||||
return;
|
||||
}
|
||||
var timeinseconds = 0;
|
||||
for(var i=0;i<datesplits.length;++i) {
|
||||
var number = parseInt(datesplits[i].match(/[0-9]+/)[0]);
|
||||
var interval = datesplits[i].match(/[^0-9]/)[0];
|
||||
timeinseconds += this.internalAPI.getSeconds(number,interval);
|
||||
}
|
||||
var then = new Date(now + (timeinseconds*1000));
|
||||
if(dbot.config.debugMode) {
|
||||
event.reply("The timer will be at "+then);
|
||||
}
|
||||
var cb = function() {
|
||||
if(message)
|
||||
event.reply(user+": This is your reminder. You left a message: "+message);
|
||||
else
|
||||
event.reply(user+": This is your reminder. You did not leave a message.");
|
||||
};
|
||||
dbot.api.timers.addTimeout(then,cb,null);
|
||||
if(message)
|
||||
event.reply("I've set the timer with message "+message);
|
||||
else
|
||||
event.reply("I've set the timer.");
|
||||
}.bind(this)
|
||||
};
|
||||
|
||||
this.commands = {
|
||||
'~remind': function(event) {
|
||||
if(event.params.length < 3) {
|
||||
event.reply("You need to give me a user and time dude.");
|
||||
return;
|
||||
}
|
||||
this.internalAPI.doReminder(event,event.params[1],event.params[2],event.params[3]);
|
||||
},
|
||||
'~remindme': function(event) {
|
||||
if(event.params.length < 2) {
|
||||
event.reply("You need to give me a time dude.");
|
||||
return;
|
||||
}
|
||||
this.internalAPI.doReminder(event,event.user,event.params[1],event.params[2]);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return new remind(dbot);
|
||||
};
|
Loading…
Reference in New Issue
Block a user