Skip to content

Instantly share code, notes, and snippets.

@juanmirod
Created December 18, 2013 21:25
Show Gist options
  • Select an option

  • Save juanmirod/8030118 to your computer and use it in GitHub Desktop.

Select an option

Save juanmirod/8030118 to your computer and use it in GitHub Desktop.
Hubot script for definitions using duckduckgo.com Instant answer API
# Description:
# Get a definition from duckduckgo.com api
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot define (.*) - return the definition of the word/phrase
#
# Author:
# [email protected]
#
getDefinition = (msg, query) ->
msg.http("http://api.duckduckgo.com/?q=define+#{query}&format=json&t=hubotscript")
.get() (err, res, body) ->
results = JSON.parse body
if results.Definition
definition = results.Definition + '('
if results.DefinitionSource
definition += results.DefinitionSource + ' '
definition += 'via api.duckduckgo.com)'
msg.send definition
else
msg.send "Sorry, I couldn't find the meaning of #{query}"
module.exports = (robot) ->
robot.respond /(define )(.*)/i, (msg) ->
getDefinition msg, msg.match[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment