From 0218f0f0e0e58ecf66509e226bb73c61681b186a Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Mon, 28 Mar 2022 15:37:36 -0600 Subject: [PATCH] misc.wolfram: Upload image, haste fallback for long results --- src/modules/misc.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/modules/misc.js b/src/modules/misc.js index 64a1617..25bc8e7 100644 --- a/src/modules/misc.js +++ b/src/modules/misc.js @@ -2,7 +2,7 @@ const Command = require("../lib/command.js"); const CATEGORY = "misc"; const fetch = require("node-fetch"); -const {safeString, parseHtmlEntities} = require("../lib/utils.js"); +const {hastebin, safeString, parseHtmlEntities} = require("../lib/utils.js"); const yt = new Command("youtube"); yt.addAlias("yt"); @@ -118,11 +118,29 @@ wolfram.callback = async function (msg, line) { return {embed}; } else { - return `\`${safeString(line)}\` -> ${ - data[1].subpods[0].plaintext.length > 0 - ? safeString(data[1].subpods[0].plaintext) - : data[1].subpods[0].img.src - }`; + let image; + + if (data[1].subpods[0].img.src) + image = Buffer.from( + await fetch(data[1].subpods[0].img.src).then((x) => x.arrayBuffer()) + ); + + let string = ""; + if (data[1].subpods[0].plaintext.length > 0) + string = safeString(data[1].subpods[0].plaintext); + + if (string.length > 2000 - (6 + safeString(line).length)) + string = + `Output too long: ${hf.config.haste_provider}/` + + (await hastebin(string)); + + return { + content: `\`${safeString(line)}\` -> ${string.length > 0 ? string : ""}`, + file: image && { + file: image, + name: "wolfram_output.gif", + }, + }; } }; hf.registerCommand(wolfram);