Created
August 31, 2014 22:12
-
-
Save awaxa/c28bd02cae59b134b6cd to your computer and use it in GitHub Desktop.
This file contains 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: | |
# Allows hubot to answer almost any question by asking Wolfram Alpha | |
# | |
# Dependencies: | |
# "wolfram": "0.2.2" | |
# | |
# Configuration: | |
# HUBOT_WOLFRAM_APPID - your AppID | |
# | |
# Commands: | |
# hubot question <question> - Searches Wolfram Alpha for the answer to the question | |
# | |
# Notes: | |
# This may not work with node 0.6.x | |
# | |
# Author: | |
# dhorrigan | |
# awaxa | |
Wolfram = require('wolfram').createClient(process.env.HUBOT_WOLFRAM_APPID) | |
module.exports = (robot) -> | |
robot.respond /(question|wfa) (.*)$/i, (msg) -> | |
Wolfram.query msg.match[2], (e, result) -> | |
if result and result.length > 0 | |
response = result[1]['subpods'][0]['value'] | |
if process.env.HUBOT_WOLFRAM_ONELINE | |
response = response.replace /\s/g, ' ' | |
response = response.replace /\r?\n|\r/g, ', ' | |
response = response.replace /\|/g, ':' | |
msg.send response | |
else | |
msg.send 'Hmm...not sure' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment