Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
109 lines (91 sloc) 3.2 KB
#! ========================================
#! WolframAlpha
r = require "#{__dirname}/../helpers/fetch"
tableToAscii = require "#{__dirname}/../helpers/tableToAscii"
Embed = (require 'discord.js').RichEmbed
path = [
].join ''
generatePlainOrTable = (x) ->
if x.img?.type is "Grid"
tbl = tableToAscii(
.map((l) -> l.split(/\s*\|\s*/g))
return """
if x.plaintext
return x.plaintext
handler = (msg, match, Haruka) ->
args = match.input.tokenize()[1]
if not args
return msg.reply [
"Please enter a search term."
"What would you like to know about?"
msg.reply "Searching for “#{args}”...", disableEveryone: yes
.then (reply) ->
r path + encodeURIComponent args
.then (json) ->
result = json.queryresult
if (not result) or (result.success is no)
return msg.reply [
"An error occurred while processing the input."
embed = new Embed()
embed.setFooter("Powered by WolframAlpha")
embed.setURL "{
encodeURIComponent args
embed.setTitle "Results for “#{args}"
if /^Input/.test result.pods[0].title
input = result.pods.shift()
embed.setTitle input.title
textPods = input.subpods
.filter((x) -> x.plaintext.trim().length)
if textPods.length
.map((x) -> generatePlainOrTable x)
.join '\n'
for pod in result.pods
textPods = pod.subpods
.map (x) ->
generatePlainOrTable x
.filter (x) -> x?
if textPods.length
textPods.join '\n\n'
msg.reply "Results for “#{args}”:", embed
.catch (err) ->
console.log err
msg.reply [
"An error occurred. Whoops."
"Something happened while processing the input."
module.exports = {
name: "WolframAlpha"
regex: /^(wa|wolfram|wolframalpha)(\s+|$)/i
handler: handler
short: "-h wa <query> ::
Ask anything with WolframAlpha."
long: """
=== Help for WolframAlpha ===
*Aliases*: wa, wolfram, wolframalpha
-h wa <query> :: Computes stuff with WolframAlpha
You can’t perform that action at this time.