spoike
2/20/2015 - 7:50 AM

Script for celebrating the Swedish past time of "Fika"

Script for celebrating the Swedish past time of "Fika"

# Description:
#   Hubot delivers a fika related pic
#
# Dependencies:
#   cron
#   google-images
#
# Configuration:
#   None
#
# Commands:
#   hubot fika me - Display a fika related picture
#
# Author:
#   spoike

client = require 'google-images'
cronjob = require("cron").CronJob

TIME = "00 20 14 * * 1-5"
ROOM = "general"

fika = ['fikabröd', 'fika bulle', 'apfelstrudel', 'tårta', 'kaffe med påtår']

random = (items) ->
    items[ Math.floor(Math.random() * items.length) ]

module.exports = (robot) ->

  getRandomFika = (cb) ->
    client.search random(fika), (err, images) ->
      cb random images

  getRandomFikaMessage = (cb) ->
    getRandomFika (image) ->
      cb image.url

  robot.respond /fika( me)?/i, (msg) ->
    getRandomFikaMessage (fikaMessage) ->
      msg.reply ":coffee: #{fikaMessage}"

  dailyUpdate = () ->
    getRandomFikaMessage (fikaMessage) ->
      robot.messageRoom ROOM, ":coffee: *FIKA!* #{fikaMessage}"

  remind = new cronjob TIME,
    dailyUpdate
    null
    true