Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding wheninaustin.coffee #400

Merged
merged 8 commits into from
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 0 deletions.
  1. +23 −0 src/scripts/wheninaustin.coffee
View
23 src/scripts/wheninaustin.coffee
@@ -0,0 +1,23 @@
+# When in Austin.
+
+http = require 'http'
+jsdom = require 'jsdom'
+
+module.exports = (robot) ->
+ robot.respond /when(\s)?in(\s)?austin/i, (msg) ->
+ options =
+ host: 'wheninatx.tumblr.com',
+ port: 80,
+ path: '/random'
+
+ # Random redirects us to another article, grab that url and respond.
+ http.get options, (res) ->
+ location = res.headers.location
+ jsdom.env location, [ 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' ], (errors, window) ->
+ (($) ->
+ title = $('meta[property="og:title"]').attr('content')
+ img = $('article p[align="center"] img').attr('src')
+
+ msg.send title + ' ' + img
+ )(window.jQuery)
+
Something went wrong with that request. Please try again.