PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/scripts/abstract.coffee

http://github.com/github/hubot-scripts
CoffeeScript | 45 lines | 21 code | 1 blank | 23 comment | 9 complexity | 854ee6ef075de384eb4fac03ca955d1b MD5 | raw file
  1. # Description:
  2. # None
  3. #
  4. # Dependencies:
  5. # None
  6. #
  7. # Configuration:
  8. # None
  9. #
  10. # Commands:
  11. # hubot abstract <topic> - Prints a nice abstract of the given topic
  12. #
  13. # Author:
  14. # tantalor
  15. module.exports = (robot) ->
  16. robot.respond /(abs|abstract) (.+)/i, (res) ->
  17. abstract_url = "http://api.duckduckgo.com/?format=json&q=#{encodeURIComponent(res.match[2])}"
  18. res.http(abstract_url)
  19. .header('User-Agent', 'Hubot Abstract Script')
  20. .get() (err, _, body) ->
  21. return res.send "Sorry, the tubes are broken." if err
  22. data = JSON.parse(body.toString("utf8"))
  23. return unless data
  24. topic = data.RelatedTopics[0] if data.RelatedTopics and data.RelatedTopics.length
  25. if data.AbstractText
  26. # hubot abs numerology
  27. # Numerology is any study of the purported mystical relationship between a count or measurement and life.
  28. # http://en.wikipedia.org/wiki/Numerology
  29. res.send data.AbstractText
  30. res.send data.AbstractURL if data.AbstractURL
  31. else if topic and not /\/c\//.test(topic.FirstURL)
  32. # hubot abs astronomy
  33. # Astronomy is the scientific study of celestial objects.
  34. # http://duckduckgo.com/Astronomy
  35. res.send topic.Text
  36. res.send topic.FirstURL
  37. else if data.Definition
  38. # hubot abs contumacious
  39. # contumacious definition: stubbornly disobedient.
  40. # http://merriam-webster.com/dictionary/contumacious
  41. res.send data.Definition
  42. res.send data.DefinitionURL if data.DefinitionURL
  43. else
  44. res.send "I don't know anything about that."