Use brain 'loaded' event in remind.coffee

- Removes hacky setTimeout method
This commit is contained in:
Alex Whitman 2011-10-29 09:14:32 +01:00
Родитель b835bf1b86
Коммит 7ed2430eba
1 изменённых файлов: 3 добавлений и 4 удалений

7
src/scripts/remind.coffee Normal file → Executable file
Просмотреть файл

@ -9,11 +9,11 @@ class Reminders
@cache = []
@current_timeout = null
loadReminders = =>
@robot.brain.on 'loaded', =>
if @robot.brain.data.reminders
@cache = @robot.brain.data.reminders
@queue()
setTimeout loadReminders, 5000 # Hacky until there's some kind of 'loaded' notification
loadReminders = =>
add: (reminder) ->
@cache.push reminder
@ -58,7 +58,7 @@ class Reminder
seconds:
value: 0
regex: "seconds?|secs?"
for period of periods
pattern = new RegExp('^.*?([\\d\\.]+)\\s*(?:(?:' + periods[period].regex + ')).*$', 'i')
matches = pattern.exec(@time)
@ -81,4 +81,3 @@ module.exports = (robot) ->
reminder = new Reminder msg.message.user, time, action
reminders.add reminder
msg.send 'I\'ll remind you to ' + action + ' on ' + reminder.dueDate()