28 lines
793 B
CoffeeScript
28 lines
793 B
CoffeeScript
# Description:
|
|
# accede a wolfram alpha
|
|
#
|
|
# Dependencies:
|
|
# "wolfram":"0.3.1"
|
|
#
|
|
# Author:
|
|
# Enrico Fasoli (fazo96)
|
|
#
|
|
|
|
|
|
module.exports = (robot) ->
|
|
if not process.env.WOLFRAM_API_KEY?
|
|
console.log 'NO WOLFRAM_API_KEY SET!'
|
|
return # no api key, no wolfy
|
|
wolfram = require('wolfram').createClient process.env.WOLFRAM_API_KEY
|
|
robot.respond /(?:quanto fa|compute|wfa|wolfram) (.+)/i, (res) ->
|
|
res.send 'contattando Wolfram Alpha...'
|
|
wolfram.query res.match[1], (err, result) ->
|
|
if err then return res.send err
|
|
#res.send JSON.stringify result
|
|
parseSubPod = (subpod) -> subpod.value
|
|
parsePod = (pod) ->
|
|
'\n=== ' + pod.title + '\n' + pod.subpods.map(parseSubPod).join('\n')
|
|
res.send (parsePod(pod) for pod in result).join('')
|
|
|
|
|