Skip to content
This repository
Ian Young iangreenleaf
file 47 lines (43 sloc) 1.379 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 45 46 47
# Description
# Grab images from "Fuck yeah nouns"
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# fuck yeah <noun> - Displays a fuck yeah image for the given noun
#
# Notes:
# Uses holman/fuck-yeah as a provider. Can be altered to use the original FYN,
# but be sure to read the caveats in the comments.
#
# Author:
# iangreenleaf

providers =
  holman: (noun) ->
    noun = escape noun
    "http://fuckyeah.herokuapp.com/#{noun}#.jpg"
  # If you want the original FYN, you can use this URL instead.
  # WARNING: The results from FYN are a bit "quirky", to put it charitably.
  # Using this endpoint turned Hubot into a demented, pervy old man who
  # occasionally posted very NSFW images.
  fyn: (noun) ->
    noun = noun.replace /\s+/g, "_"
    noun = noun.replace /\W/g, ""
    "http://fuckyeahnouns.com/images/#{noun}.jpg"

module.exports = (robot) ->
  robot.hear /fuck yeah (.+)/i, (msg) ->
    noun = msg.match[1]

    url = providers.holman noun

    # This is subtly different from the common usage, because I want a response
    # as soon as we have a status code, don't care about the actual body.
    ping = msg.http(url).get (e, req) =>
      req.addListener "response", (res) =>
        if res.statusCode != 200
          robot.logger.error "Bad response from FYN: #{res.statusCode}"
        else
          msg.send url
    ping()
Something went wrong with that request. Please try again.