Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Write 9gag in coffeescript #206

Merged
merged 1 commit into from

2 participants

@EnriqueVidal

I rewrote 9gag in coffeescript, also I though it'd be nice if we could send direct links to images instead of the page, those load up fine in campfire.

I couldn't find an effective way to test it, can you please review and advise?

@tombell tombell merged commit 473970f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 9, 2011
  1. @EnriqueVidal

    Update 9gag script

    EnriqueVidal authored
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 13 deletions.
  1. +24 −0 src/scripts/9gag.coffee
  2. +0 −13 src/scripts/9gag.js
View
24 src/scripts/9gag.coffee
@@ -0,0 +1,24 @@
+# Random meme from 9gag
+# Rewrite by Enrique Vidal
+
+Select = require( "soupselect" ).select
+HTMLParser = require "htmlparser"
+
+module.exports = (robot)->
+ robot.respond /9gag/i, (message)->
+ send_meme message, (text)->
+ message.send text
+
+send_meme = (message, response_handler)->
+ meme_domain = "http://9gag.com"
+ message.http( meme_domain + "/random" ).get() (error, response, body)->
+ return response_handler "Sorry, something went wrong" if error
+
+ response get_meme_image( body, "#img-wrap a img" ).children[0]['src']
+
+get_meme_image = (body)->
+ html_handler = new HTMLParser.DefaultHandler((()->), ignoreWhitespace: true )
+ html_parser = new HTMLParser.Parser handler
+
+ html_parser.parseComplete body
+ Select handler.dom, selector
View
13 src/scripts/9gag.js
@@ -1,13 +0,0 @@
-// Random meme from 9gag (9gag.com)
-//
-// hubot 9gag - returns a random meme
-
-var memeDomain = "http://9gag.com";
-
-module.exports = function(robot) {
- robot.respond(/9gag/i, function(msg){
- msg.http(memeDomain + "/random").get()(function(e, r, b) {
- msg.send(memeDomain + r.headers['location']);
- });
- });
-};
Something went wrong with that request. Please try again.