Created
December 18, 2013 21:25
-
-
Save juanmirod/8030118 to your computer and use it in GitHub Desktop.
Hubot script for definitions using duckduckgo.com Instant answer API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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