<commit_before># Description:
#   Allows Hubot to lambast someone with a random insult
#
# Dependencies:
#   "soupselect: "0.2.0"
#   "htmlparser": "1.7.6"
#
# Configuration:
#   None
#
# Commands:
#   hubot insult <name> - give <name> the what-for
#
# Authors:
#   ajacksified, brandonvalentine

Select     	= require("soupselect").select
HtmlParser  = require "htmlparser"

module.exports = (robot) ->
  robot.respond /insult (.*)/i, (msg) ->
    name = msg.match[1].trim()
    insult(msg, name)

insult = (msg, name) ->
  msg
    .http("http://www.randominsults.net")
    .header("User-Agent: Insultbot for Hubot (+https://github.com/github/hubot-scripts)")
    .get() (err, res, body) ->
      quote = parse_html body, "i"
      msg.send name + ": " + parse_quote(quote)

parse_html = (html, selector) ->
  handler = new HtmlParser.DefaultHandler((() ->), ignoreWhitespace: true)
  parser  = new HtmlParser.Parser handler

  parser.parseComplete html
  Select handler.dom, selector

parse_quote = (quote) ->
  quote[0].children[0].data<commit_msg>Refactor improved insult script to use cheerio<commit_after># Description:
#   Allows Hubot to lambast someone with a random insult
#
# Dependencies:
#   "soupselect: "0.2.0"
#   "htmlparser": "1.7.6"
#
# Configuration:
#   None
#
# Commands:
#   hubot insult <name> - give <name> the what-for
#
# Authors:
#   ajacksified, brandonvalentine

cheerio = require('cheerio')

module.exports = (robot) ->
  robot.respond /insult (.*)/i, (msg) ->
    name = msg.match[1].trim()
    insult(msg, name)

insult = (msg, name) ->
  msg
    .http("http://www.randominsults.net")
    .header("User-Agent: Insultbot for Hubot (+https://github.com/github/hubot-scripts)")
    .get() (err, res, body) ->
      msg.send "#{name}: #{getQuote body}"

getQuote = (body) ->
  $ = cheerio.load(body)
  $('i').text()
{'fraction_non_alphanumeric': 0.1702819956616052, 'fraction_numerical': 0.008676789587852495, 'mean_word_length': 3.4565217391304346, 'pattern_counts': {'":': 3, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1430057', 'n_tokens_mistral': 677, 'n_tokens_neox': 669, 'n_words': 153}