misc.wolfram: Upload image, haste fallback for long results
This commit is contained in:
		
							parent
							
								
									c0223017bc
								
							
						
					
					
						commit
						0218f0f0e0
					
				
					 1 changed files with 24 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue