2021-06-11 04:20:39 +00:00
|
|
|
const Command = require("../lib/command.js");
|
|
|
|
const CATEGORY = "misc";
|
|
|
|
|
|
|
|
const fetch = require("node-fetch");
|
2022-03-28 21:37:36 +00:00
|
|
|
const {hastebin, safeString, parseHtmlEntities} = require("../lib/utils.js");
|
2021-06-11 04:20:39 +00:00
|
|
|
|
|
|
|
const yt = new Command("youtube");
|
|
|
|
yt.addAlias("yt");
|
|
|
|
yt.category = CATEGORY;
|
|
|
|
yt.helpText = "Search YouTube";
|
|
|
|
yt.usage = "[search term]";
|
|
|
|
yt.callback = async function (msg, line) {
|
|
|
|
if (!line) return "Arguments are required.";
|
|
|
|
|
|
|
|
const req = await fetch(
|
|
|
|
`https://www.googleapis.com/youtube/v3/search?key=${
|
|
|
|
hf.apikeys.google
|
|
|
|
}&maxResults=5&part=snippet&type=video&q=${encodeURIComponent(line)}`
|
|
|
|
).then((x) => x.json());
|
|
|
|
|
|
|
|
const topVid = req.items[0];
|
|
|
|
|
|
|
|
let out = `**${safeString(
|
|
|
|
parseHtmlEntities(topVid.snippet.title)
|
|
|
|
)}** | \`${safeString(
|
|
|
|
parseHtmlEntities(topVid.snippet.channelTitle)
|
|
|
|
)}\`\nhttps://youtu.be/${topVid.id.videoId}\n\n**__See Also:__**\n`;
|
|
|
|
|
|
|
|
for (let i = 1; i < req.items.length; i++) {
|
|
|
|
const vid = req.items[i];
|
|
|
|
out += `- **${safeString(
|
|
|
|
parseHtmlEntities(vid.snippet.title)
|
|
|
|
)}** | By: \`${safeString(
|
|
|
|
parseHtmlEntities(vid.snippet.channelTitle)
|
|
|
|
)}\` | <https://youtu.be/${vid.id.videoId}>\n`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
};
|
|
|
|
hf.registerCommand(yt);
|
|
|
|
|
|
|
|
const fyt = new Command("fyt");
|
|
|
|
fyt.category = CATEGORY;
|
|
|
|
fyt.helpText = "Search YouTube and take the first result.";
|
|
|
|
fyt.usage = "[search term]";
|
|
|
|
fyt.callback = async function (msg, line) {
|
|
|
|
if (!line) return "Arguments are required.";
|
|
|
|
|
|
|
|
const req = await fetch(
|
|
|
|
`https://www.googleapis.com/youtube/v3/search?key=${
|
|
|
|
hf.apikeys.google
|
|
|
|
}&maxResults=2&part=snippet&type=video&q=${encodeURIComponent(line)}`
|
|
|
|
).then((x) => x.json());
|
|
|
|
|
|
|
|
const vid = req.items[0];
|
|
|
|
|
|
|
|
return `**${safeString(
|
|
|
|
parseHtmlEntities(vid.snippet.title)
|
|
|
|
)}** | \`${safeString(
|
|
|
|
parseHtmlEntities(vid.snippet.channelTitle)
|
|
|
|
)}\`\nhttps://youtu.be/${vid.id.videoId}`;
|
|
|
|
};
|
|
|
|
hf.registerCommand(fyt);
|
2021-07-24 02:39:57 +00:00
|
|
|
|
|
|
|
const WA_NO_ANSWER = "<:ms_cross:503341994974773250> No answer.";
|
|
|
|
|
|
|
|
const wolfram = new Command("wolfram");
|
|
|
|
wolfram.category = CATEGORY;
|
2022-03-28 21:16:03 +00:00
|
|
|
wolfram.helpText = "Wolfram Alpha";
|
2021-07-24 02:39:57 +00:00
|
|
|
wolfram.usage = "<-v> [query]";
|
|
|
|
wolfram.addAlias("wa");
|
2021-07-29 20:16:11 +00:00
|
|
|
wolfram.callback = async function (msg, line) {
|
2021-07-24 02:39:57 +00:00
|
|
|
let verbose = false;
|
|
|
|
|
2021-07-29 20:16:11 +00:00
|
|
|
if (line.includes("-v")) {
|
|
|
|
line = line.replace("-v", "").trim();
|
2021-07-24 02:39:57 +00:00
|
|
|
verbose = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const req = await fetch(
|
|
|
|
`http://api.wolframalpha.com/v2/query?input=${encodeURIComponent(
|
2021-07-29 20:16:11 +00:00
|
|
|
line
|
2021-07-24 02:39:57 +00:00
|
|
|
)}&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 = {
|
2021-07-29 20:16:11 +00:00
|
|
|
title: `Result for: \`${safeString(line)}\``,
|
2021-07-24 02:39:57 +00:00
|
|
|
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 {
|
2022-03-28 21:37:36 +00:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
};
|
2021-07-24 02:39:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
hf.registerCommand(wolfram);
|