Skip to content

Instantly share code, notes, and snippets.

@awaxa
Created August 31, 2014 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awaxa/c28bd02cae59b134b6cd to your computer and use it in GitHub Desktop.
Save awaxa/c28bd02cae59b134b6cd to your computer and use it in GitHub Desktop.
# 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