Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: github/hubot-scripts
...
head fork: github/hubot-scripts
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 2 contributors
Showing with 18 additions and 40 deletions.
  1. +18 −40 src/scripts/archer.coffee
View
58 src/scripts/archer.coffee
@@ -8,15 +8,9 @@
# get archer
# REQUIRED MODULES
-# sudo npm install htmlparser
-# sudo npm install soupselect
-# sudo npm install jsdom
-# sudo npm install underscore
+# npm install scraper
-Select = require("soupselect").select
-HtmlParser = require "htmlparser"
-JsDom = require "jsdom"
-_ = require("underscore")
+scraper = require 'scraper'
module.exports = (robot) ->
@@ -29,39 +23,23 @@ module.exports = (robot) ->
robot.hear /^sitting down/i, (msg) ->
msg.reply "What?! At the table? Look, he thinks he's people!"
- robot.hear "I love that you know how to do that.", (msg) ->
+ robot.hear /love/i, (msg) ->
msg.reply "And I love that I have an erection... that doesn't involve homeless people."
robot.hear /archer/i, (msg) ->
- msg
- .http("http://en.wikiquote.org/wiki/Archer_(TV_series)")
- .header("User-Agent: Archerbot for Hubot (+https://github.com/github/hubot-scripts)")
- .get() (err, res, body) ->
- quotes = parse_html(body, "dl")
- quote = get_quote msg, quotes
-get_quote = (msg, quotes) ->
-
- nodeChildren = _.flatten childern_of_type(quotes[Math.floor(Math.random() * quotes.length)])
- quote = (textNode.data for textNode in nodeChildren).join(' ').replace(/^\s+|\s+$/g, '')
-
- msg.send quote
-
-# Helpers
-parse_html = (html, selector) ->
- handler = new HtmlParser.DefaultHandler((() ->), ignoreWhitespace: true)
- parser = new HtmlParser.Parser handler
-
- parser.parseComplete html
- Select handler.dom, selector
-
-childern_of_type = (root) ->
- return [root] if root?.type is "text"
-
- if root?.children?.length > 0
- return (childern_of_type(child) for child in root.children)
-
-get_dom = (xml) ->
- body = JsDom.jsdom(xml)
- throw Error("No XML data returned.") if body.getElementsByTagName("FilterReturn")[0].childNodes.length == 0
- return body
+ options = {
+ 'uri': 'http://en.wikiquote.org/wiki/Archer_(TV_series)',
+ 'headers': {
+ 'User-Agent': 'User-Agent: Archerbot for Hubot (+https://github.com/github/hubot-scripts)'
+ }
+ }
+
+ scraper options, (err, jQuery) ->
+ throw err if err
+ quotes = jQuery("dl").toArray()
+ dialog = ''
+ quote = quotes[Math.floor(Math.random()*quotes.length)]
+ dialog += jQuery(quote).text().trim() + "\n"
+ msg.send dialog
+

No commit comments for this range

Something went wrong with that request. Please try again.