 class Reminder
     constructor: (@callback) ->
         @pending = []
+        @crons = []
 
     addPending: (user, message) ->
         reminder = @getPending user


    complete: (user, executionDate) ->
        if reminder = @getPending user
            console.debug "hubot-remind-advanced: Reminder created."
            @addCron reminder[0], reminder[1], executionDate
            @pending.splice @pending.indexOf(reminder), 1
            return [reminder[0], reminder[1], executionDate]
        false

    addCron: (user, message, executionDate) ->
        console.debug "hubot-remind-advanced: Adding cron job."
        setTimeout =>
            @callback user, message
        , moment(executionDate).diff()


module.exports = (robot) ->

            res.reply "Your reminder operation has been cancelled."
        else
            res.reply "You have no reminders pending creation."
        res.message.done = true

    robot.respond /remind clear/i, (res) ->
        Reminder.clearCron()
        cleared = 0
        for reminder in BrainReminders()
            if reminder[0].id is res.message.user.id
                ++cleared
                BrainReminders().splice reminder, 1

        if cleared isnt 0
            res.reply "#{cleared} of your reminder(s) have been cleared."
        else
            res.reply "You have no reminders."
        res.message.done = true

    robot.respond /remind( me)? now/i, (res) ->
        message = ""
        for reminder in BrainReminders()
            if reminder[0].id is res.message.user.id
                message += "[#{moment(reminder[2]).fromNow()}] "
                message += "#{reminder[1]}\n"
        res.reply message if message.length isnt 0
        res.message.done = true

    robot.respond /remind( me)? (.+)/i, (res) ->
