First Pull Request

2011-11-04 21:52:36

I submitted my first Pull Request (Link), and it was accepted.  Super sweet.

It wasn’t anything too special, but it was fun to do, I have a lot of people to thank.

For those interested, the snippets of code that changed were:

module.exports = (robot) ->
  robot.respond /(hipster|clown|scumbag|rohan|jason)( me)? (.*)/i, (msg) ->
    type = msg.match[1]
    imagery = msg.match[3]

    if imagery.match /^https?:\/\//i
      msg.send "http://faceup.me/img?overlay=#{type}&src;=#{imagery}"
    else
      imageMe msg, imagery, (url) ->
        msg.send "http://faceup.me/img?overlay=#{type}&src;=#{url}"

imageMe = (msg, query, cb) ->
  msg.http('http://ajax.googleapis.com/ajax/services/search/images')
    .query(v: "1.0", rsz: '8', q: query)
    .get() (err, res, body) ->
      images = JSON.parse(body)
      images = images.responseData.results
      image  = msg.random images
      cb "#{image.unescapedUrl}"

I threw in the if statement to determine whether an url was given for a direct image link or a string to be queried.  If it turns out to be a query string, pass it to imageMe, slam it into the google image search, and give back a random result.  Fun stuff!