Skip to content

Commit

Permalink
Add remind command
Browse files Browse the repository at this point in the history
  • Loading branch information
Suguru Odai committed Sep 5, 2015
1 parent ab059e8 commit f15b6f4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/remind.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,21 @@
# Commands:
# hubot remind 07:00 Good morning! - Send "Good morning!" at 7:00

scheduler = require('node-schedule')

module.exports = (robot) ->
robot.respond /remind (\d+):(\d+) (.*)/i, (msg) ->
remind robot, msg, msg.match[1], msg.match[2], msg.match[3]

remind = (robot, msg, hour, minute, message) ->
try
currentDate = new Date()
currentYear = currentDate.getFullYear()
currentMonth = currentDate.getMonth()
currentDay = currentDate.getDay() - 1
scheduleDate = new Date(currentYear, currentMonth, currentDay, hour, minute)
new scheduler.scheduleJob scheduleDate, =>
msg.send message
msg.send "#{scheduleDate} \"#{message}\", accepted."
catch error
msg.send error

0 comments on commit f15b6f4

Please sign in to comment.