Skip to content

Instantly share code, notes, and snippets.

@spoike
Created February 20, 2015 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spoike/0b83a325010e7c0cc8da to your computer and use it in GitHub Desktop.
Save spoike/0b83a325010e7c0cc8da to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment