Created
January 18, 2012 23:07
-
-
Save zenhob/1636401 to your computer and use it in GitHub Desktop.
hubot script for tracking days since an event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generates commands to track days since an event | |
# | |
# it's been <number> days since <event> - Set the day when the event happened | |
# how long since <event>? - Display the number of days since the event | |
module.exports = (robot) -> | |
robot.respond /it's been (\d+) days since\s+(.*?)[.?!]?$/i, (msg) -> | |
date = new Date | |
date.setTime(date.getTime() - (parseInt(msg.match[1])*1000*24*60*60)) | |
robot.brain.data.days_since ||= {} | |
robot.brain.data.days_since[msg.match[2]] = date | |
msg.send "okay, it's been " + msg.match[1] + " days since " + msg.match[2] | |
robot.respond /how long since\s+(.*?)\??$/i, (msg) -> | |
if robot.brain.data.days_since && robot.brain.data.days_since[msg.match[1]] | |
date = robot.brain.data.days_since[msg.match[1]] | |
days_since = Math.floor((new Date - date.getTime()) / (1000*24*60*60)) | |
msg.send "it's been " + days_since + " days since " + msg.match[1] | |
else | |
msg.send "I don't recall that event" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment