PageRenderTime 62ms CodeModel.GetById 40ms RepoModel.GetById 0ms app.codeStats 0ms

/src/scripts/abstract.coffee

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