misc: port wolfram
This commit is contained in:
		
							parent
							
								
									6ba2f696ac
								
							
						
					
					
						commit
						3a3e4fc4ad
					
				
					 1 changed files with 70 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -61,3 +61,73 @@ fyt.callback = async function (msg, line) {
 | 
			
		|||
  )}\`\nhttps://youtu.be/${vid.id.videoId}`;
 | 
			
		||||
};
 | 
			
		||||
hf.registerCommand(fyt);
 | 
			
		||||
 | 
			
		||||
const WA_NO_ANSWER = "<:ms_cross:503341994974773250> No answer.";
 | 
			
		||||
 | 
			
		||||
const wolfram = new Command("wolfram");
 | 
			
		||||
wolfram.category = CATEGORY;
 | 
			
		||||
wolfram.helpText = "Search YouTube and take the first result.";
 | 
			
		||||
wolfram.usage = "<-v> [query]";
 | 
			
		||||
wolfram.addAlias("wa");
 | 
			
		||||
wolfram.callback = async function (msg, line, verboseFlag, _query) {
 | 
			
		||||
  let verbose = false;
 | 
			
		||||
 | 
			
		||||
  let query = _query;
 | 
			
		||||
 | 
			
		||||
  if (verboseFlag == "-v" && _query) {
 | 
			
		||||
    verbose = true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!_query) {
 | 
			
		||||
    query = verboseFlag;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const req = await fetch(
 | 
			
		||||
    `http://api.wolframalpha.com/v2/query?input=${encodeURIComponent(
 | 
			
		||||
      query
 | 
			
		||||
    )}&appid=LH2K8H-T3QKETAGT3&output=json`
 | 
			
		||||
  ).then((x) => x.json());
 | 
			
		||||
 | 
			
		||||
  const data = req.queryresult.pods;
 | 
			
		||||
 | 
			
		||||
  if (!data) return WA_NO_ANSWER;
 | 
			
		||||
 | 
			
		||||
  // fake no answer
 | 
			
		||||
  if (data[0].subpods[0].plaintext.includes("geoIP")) return WA_NO_ANSWER;
 | 
			
		||||
 | 
			
		||||
  if (verbose) {
 | 
			
		||||
    const embed = {
 | 
			
		||||
      title: `Result for: \`${safeString(query)}\``,
 | 
			
		||||
      fields: [],
 | 
			
		||||
      footer: {
 | 
			
		||||
        icon_url: "http://www.wolframalpha.com/share.png",
 | 
			
		||||
        text: "Powered by Wolfram Alpha",
 | 
			
		||||
      },
 | 
			
		||||
      image: {
 | 
			
		||||
        url: data[1].subpods[0].img.src,
 | 
			
		||||
      },
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const extra = data.slice(1, 6);
 | 
			
		||||
    for (const x in extra) {
 | 
			
		||||
      embed.fields.push({
 | 
			
		||||
        name: extra[x].title,
 | 
			
		||||
        value: `[${
 | 
			
		||||
          extra[x].subpods[0].plaintext.length > 0
 | 
			
		||||
            ? extra[x].subpods[0].plaintext
 | 
			
		||||
            : "<click for image>"
 | 
			
		||||
        }](${extra[x].subpods[0].img.src})`,
 | 
			
		||||
        inline: true,
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return {embed};
 | 
			
		||||
  } else {
 | 
			
		||||
    return `\`${safeString(query)}\` -> ${
 | 
			
		||||
      data[1].subpods[0].plaintext.length > 0
 | 
			
		||||
        ? safeString(data[1].subpods[0].plaintext)
 | 
			
		||||
        : data[1].subpods[0].img.src
 | 
			
		||||
    }`;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
hf.registerCommand(wolfram);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue