Last active
August 29, 2015 14:16
-
-
Save spoike/6dad13fd8182690baeb3 to your computer and use it in GitHub Desktop.
"Is it friday?" hubot script that displays media from /r/holdmybeer if the current day is a friday
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# Hubot delivers a pic from Reddit's /r/holdmybeer frontpage if it is a friday | |
# based on the aww script. | |
# | |
# Dependencies: | |
# moment | |
# | |
# Configuration: | |
# None | |
# | |
# Commands: | |
# hubot is it friday - Display a picture from /r/holdmybeer if today is a friday | |
# | |
# Author: | |
# spoike | |
url = require("url") | |
moment = require("moment") | |
module.exports = (robot) -> | |
robot.respond /is it friday/i, (msg) -> | |
weekday = moment().format("dddd") | |
return msg.send "No, today is #{weekday}" if !~ weekday.indexOf "Friday" | |
msg.http('http://www.reddit.com/r/holdmybeer.json') | |
.get() (err, res, body) -> | |
result = JSON.parse(body) | |
data = [ ] | |
for child in result.data.children | |
if child.data.domain != "self.holdmybeer" | |
if child.data.url | |
data.push(child.data) | |
if data.count <= 0 | |
msg.send "YES, TODAY IS FRIDAY!" | |
return | |
rnd = Math.floor(Math.random()*data.length) | |
picked_data = data[rnd] | |
picked_url = picked_data.url | |
parsed_url = url.parse(picked_url) | |
picked_title = picked_data.title.replace("HMB", "Hold my beer").replace(/\sbeer\s/gi, " :beer: ") | |
msg.send "YES, TODAY IS FRIDAY!\nNow... #{picked_title} #{picked_url}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment