From bcdeb3dcd41f9dd3cbc88ef49fbda5afe1690647 Mon Sep 17 00:00:00 2001 From: Diego <diego@hacklab.com.br> Date: Mon, 9 Oct 2017 10:22:35 -0300 Subject: [PATCH] corrects the name of events/tempo.coffee to events/programacao.coffee --- scripts/events/programacao.coffee | 50 +++++++++++++++++++++-------- scripts/events/tempo.coffee | 52 ------------------------------- 2 files changed, 37 insertions(+), 65 deletions(-) delete mode 100644 scripts/events/tempo.coffee diff --git a/scripts/events/programacao.coffee b/scripts/events/programacao.coffee index 41dc8d7..cd67d24 100644 --- a/scripts/events/programacao.coffee +++ b/scripts/events/programacao.coffee @@ -1,28 +1,52 @@ path = require 'path' natural = require 'natural' +programacao = require '../programacao.json' {msgVariables, stringElseRandomKey} = require path.join '..', 'lib', 'common.coffee' answers = {} -class programacao +currentDate = new Date +currentDate.getTimezoneOffset() + +getTrilha = (programacao, trilha, now = false) -> + currentTime = "#{currentDate.getHours()}:#{currentDate.getMinutes()}" + programacao.filter (item) -> + startTime = item.time[0] + endTime = item.time[1] + return item.track_title is trilha and ((not now and startTime > currentTime) or (now and startTime < currentTime and endTime > currentTime)) + +class tempo constructor: (@interaction) -> - process: (msg) => - # localizar a trilha na mensagem do usuário + process: (msg, text, classification) => + type = @interaction.type?.toLowerCase() or 'random' - # carregar o json com a programacao - programa = require './programacao.json' + variables = { + trilha: classification[0].label + programacao: '' + } - #encontra a trilha e retorna a programação deste horário + currentTalk = getTrilha programacao, variables.trilha, true + nextTalks = getTrilha programacao, variables.trilha + + if currentTalk.length + variables.programacao += "*Acontecendo agora*: \n" + currentTalk.map((talk) -> + return "- *#{talk.time[0]} - #{talk.time[1]}* - #{talk.title}" + ).join("\n") + variables.programacao += "\n\n" + + if nextTalks.length + variables.programacao += "*Próximas palestras*: \n" + nextTalks.map((talk) -> + return "- *#{talk.time[0]} - #{talk.time[1]}* - #{talk.title}" + ).join("\n") - type = @interaction.type?.toLowerCase() or 'random' switch type when 'block' - @interaction.message.forEach (line) -> - message = msgVariables line, msg - msg['send'] message + messages = @interaction.message.map (line) -> + return msgVariables line, msg, variables + msg.sendWithNaturalDelay messages when 'random' message = stringElseRandomKey @interaction.message - message = msgVariables message, msg - msg['send'] message + message = msgVariables message, msg, variables + msg.sendWithNaturalDelay message -module.exports = programacao +module.exports = tempo diff --git a/scripts/events/tempo.coffee b/scripts/events/tempo.coffee deleted file mode 100644 index cd67d24..0000000 --- a/scripts/events/tempo.coffee +++ /dev/null @@ -1,52 +0,0 @@ -path = require 'path' -natural = require 'natural' -programacao = require '../programacao.json' - -{msgVariables, stringElseRandomKey} = require path.join '..', 'lib', 'common.coffee' -answers = {} - -currentDate = new Date -currentDate.getTimezoneOffset() - -getTrilha = (programacao, trilha, now = false) -> - currentTime = "#{currentDate.getHours()}:#{currentDate.getMinutes()}" - programacao.filter (item) -> - startTime = item.time[0] - endTime = item.time[1] - return item.track_title is trilha and ((not now and startTime > currentTime) or (now and startTime < currentTime and endTime > currentTime)) - -class tempo - constructor: (@interaction) -> - process: (msg, text, classification) => - type = @interaction.type?.toLowerCase() or 'random' - - variables = { - trilha: classification[0].label - programacao: '' - } - - currentTalk = getTrilha programacao, variables.trilha, true - nextTalks = getTrilha programacao, variables.trilha - - if currentTalk.length - variables.programacao += "*Acontecendo agora*: \n" + currentTalk.map((talk) -> - return "- *#{talk.time[0]} - #{talk.time[1]}* - #{talk.title}" - ).join("\n") - variables.programacao += "\n\n" - - if nextTalks.length - variables.programacao += "*Próximas palestras*: \n" + nextTalks.map((talk) -> - return "- *#{talk.time[0]} - #{talk.time[1]}* - #{talk.title}" - ).join("\n") - - switch type - when 'block' - messages = @interaction.message.map (line) -> - return msgVariables line, msg, variables - msg.sendWithNaturalDelay messages - when 'random' - message = stringElseRandomKey @interaction.message - message = msgVariables message, msg, variables - msg.sendWithNaturalDelay message - -module.exports = tempo -- GitLab