diff --git a/commands/message/search/wolfram-alpha.js b/commands/message/search/wolfram-alpha.js index e0f367f..f966392 100644 --- a/commands/message/search/wolfram-alpha.js +++ b/commands/message/search/wolfram-alpha.js @@ -8,12 +8,6 @@ const { citation } = require('../../../labscore/utils/markdown'); const { Permissions } = require("detritus-client/lib/constants"); -function getWolframSource(ref, sources){ - for(const s of Object.values(sources)){ - if(s.ref == ref) return s - } -} - function createWolframPage(context, pod, query, sources){ let res = { "embeds": [ @@ -34,9 +28,13 @@ function createWolframPage(context, pod, query, sources){ if(pod.value) res.embeds[0].description = pod.value.substr(0,1000) if(pod.value && pod.refs) { for(const r of pod.refs){ - let src = getWolframSource(r, sources) + let src = Object.values(sources).filter((s)=>s.ref == r)[0] + // Only add a direct source if one is available + if(src.sources && src.sources[0].url){ + res.embeds[0].description += citation(r, src.sources[0].url, src.title + ' | ' + src.sources[0].text) + continue; + } if(src.url) res.embeds[0].description += citation(r, src.url, src.title) - if(src.sources) res.embeds[0].description += citation(r, src.sources[0].url, src.title + ' | ' + src.sources[0].text) } } if(pod.image) res.embeds[0].image = { url: pod.image }; diff --git a/labscore/utils/markdown.js b/labscore/utils/markdown.js index 615f8ee..a8c2665 100644 --- a/labscore/utils/markdown.js +++ b/labscore/utils/markdown.js @@ -42,7 +42,10 @@ module.exports.citation = function(number = 1, url, tooltip = ""){ let formatted = ""; for(const n of number.toString().split('')) formatted += SUPERSCRIPT_NUMBERS[parseInt(n)] if(url){ - if(tooltip.length) tooltip = ` '${tooltip}'` + if(tooltip.length){ + if(tooltip.endsWith(' ')) tooltip = tooltip.substr(0, tooltip.length - 1) + tooltip = ` '${tooltip.replace(/["*]/g, '')}'` + } return `[⁽${formatted}⁾](${url}${tooltip})` } return `⁽${formatted}⁾`