33 lines
1013 B
CoffeeScript
33 lines
1013 B
CoffeeScript
# Description:
|
|
# accede a wolfram alpha
|
|
#
|
|
# Dependencies:
|
|
# "wolfram":"0.3.1"
|
|
#
|
|
# Configuration:
|
|
# WOLFRAM_API_KEY - self explanatory
|
|
#
|
|
# Commands
|
|
# hubot wolfram/wfa/quanto fa/compute ... - pone la domanda a Wolfram Alpha
|
|
#
|
|
# Author:
|
|
# Enrico Fasoli (fazo96)
|
|
#
|
|
|
|
Wolfram = require 'wolfram'
|
|
|
|
module.exports = (robot) ->
|
|
robot.respond /(?:quanto fa|compute|wfa|wolfram) (.+)/i, (res) ->
|
|
unless process.env.WOLFRAM_API_KEY
|
|
return res.send 'non ho le chiavi per Wolfram Alpha :('
|
|
wolfram = Wolfram.createClient process.env.WOLFRAM_API_KEY
|
|
res.send 'Contattando Wolfram Alpha...'
|
|
wolfram.query res.match[1], (err, result) ->
|
|
if err then return res.send err
|
|
unless result?.slice?
|
|
return res.send 'invalid response from Wolfram Alpha'
|
|
parseSubPod = (subpod) -> subpod.value or subpod.image
|
|
parsePod = (pod) ->
|
|
'\n=== ' + pod.title + '\n' + pod.subpods.map(parseSubPod).join('\n')
|
|
res.send (parsePod(pod) for pod in result).join('').trim()
|