Skip to content
This repository
file 45 lines (40 sloc) 1.003 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
# Description:
# Rage face script
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot rage <tag> - Send a rageface for a given tag, if no tag is given, one will be chosen at random
#
# Author:
# brianmichel

Array::shuffle = -> @sort -> 0.5 - Math.random()
String::strip = -> if String::trim? then @trim() else @replace /^\s+|\s+$/g, ""

emotions = [
"happy",
"rage",
"AW YEAH",
"money",
"cereal",
"guy",
"accepted",
"derp",
"fuck"
]

module.exports = (robot) ->
robot.respond /(rage)( .*)?/i, (msg) ->
tag = if msg.match[2] then msg.match[2] else msg.random emotions
rageFacesCall msg, tag, (image_url) ->
msg.send image_url

rageFacesCall = (msg, tag, cb) ->
encoded_tag = encodeURI tag.strip()
rage_faces_url = "http://ragefac.es/api/tag/" + encoded_tag
msg.http(rage_faces_url)
.get() (err, res, body) ->
json_body = JSON.parse(body)
items = json_body.items.shuffle()
cb if items.length > 1 then items[0].face_url else "Unable to rage"
Something went wrong with that request. Please try again.