Created
January 25, 2012 17:56
-
-
Save titanous/1677601 to your computer and use it in GitHub Desktop.
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
# Allows hubot to answer almost any question by asking Wolfram Alpha | |
# | |
# Set the HUBOT_WOLFRAM_APPID environment var to your AppID | |
# | |
# compute <question> - Searches Wolfram Alpha for the answer to the question. | |
Wolfram = require('wolfram').createClient(process.env.HUBOT_WOLFRAM_APPID) | |
pickPrimary = (results) -> | |
for result in results | |
return result.subpods[0] if result.primary | |
results[1].subpods[0] | |
module.exports = (robot) -> | |
robot.respond /c(?:ompute)?(?: me)? (.*)$/i, (msg) -> | |
wolfram msg.match[1], (result) -> | |
if result | |
msg.send result.image + '#png', result.value.split("\n")... | |
else | |
msg.send "Could not compute." | |
robot.catchall (msg) -> | |
if match = msg.message?.text?.match new RegExp("^#{msg.robot.name}:?\\s*(.+)", 'i') | |
wolfram match[1], (result) -> | |
if result | |
msg.send result.value.split("\n")... | |
wolfram = (query, callback) -> | |
Wolfram.query query, (e, result) -> | |
if result?.length > 0 | |
callback pickPrimary(result) | |
else | |
callback null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment