Remove RapidAPI dependency from wikihow
This commit is contained in:
parent
7536352858
commit
467abf13ab
3 changed files with 17 additions and 19 deletions
|
@ -29,8 +29,6 @@ PREFIX=&
|
||||||
# (you can still make the bot leave using the stop command)
|
# (you can still make the bot leave using the stop command)
|
||||||
STAYVC=false
|
STAYVC=false
|
||||||
|
|
||||||
# Put Mashape/RapidAPI key here
|
|
||||||
MASHAPE=
|
|
||||||
# Put DBL/top.gg token here
|
# Put DBL/top.gg token here
|
||||||
DBL=
|
DBL=
|
||||||
# Put Tenor API key here (used for obtaining raw tenor GIF urls)
|
# Put Tenor API key here (used for obtaining raw tenor GIF urls)
|
||||||
|
|
|
@ -4,25 +4,26 @@ import Command from "../../classes/command.js";
|
||||||
class WikihowCommand extends Command {
|
class WikihowCommand extends Command {
|
||||||
async run() {
|
async run() {
|
||||||
this.client.sendChannelTyping(this.message.channel.id);
|
this.client.sendChannelTyping(this.message.channel.id);
|
||||||
const request = await fetch("https://hargrimm-wikihow-v1.p.rapidapi.com/images?count=1", {
|
const request = await fetch("https://www.wikihow.com/api.php?action=query&generator=random&prop=imageinfo&format=json&iiprop=url&grnnamespace=6");
|
||||||
headers: {
|
|
||||||
"X-RapidAPI-Key": process.env.MASHAPE,
|
|
||||||
"X-RapidAPI-Host": "hargrimm-wikihow-v1.p.rapidapi.com",
|
|
||||||
"Accept": "application/json"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const json = await request.json();
|
const json = await request.json();
|
||||||
const image = await fetch(json["1"]);
|
const id = Object.keys(json.query.pages)[0];
|
||||||
const imageBuffer = Buffer.from(await image.arrayBuffer());
|
const data = json.query.pages[id];
|
||||||
|
if (data.imageinfo) {
|
||||||
return {
|
return {
|
||||||
file: imageBuffer,
|
embeds: [{
|
||||||
name: json["1"].split("/")[json["1"].split("/").length - 1]
|
color: 16711680,
|
||||||
|
image: {
|
||||||
|
url: json.query.pages[id].imageinfo[0].url
|
||||||
|
}
|
||||||
|
}]
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
return await this.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static description = "Gets a random WikiHow image";
|
static description = "Gets a random WikiHow image";
|
||||||
static aliases = ["wiki"];
|
static aliases = ["wiki"];
|
||||||
static requires = ["mashape"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default WikihowCommand;
|
export default WikihowCommand;
|
|
@ -7,7 +7,6 @@ let queryValue = 0;
|
||||||
export async function load(command, soundStatus) {
|
export async function load(command, soundStatus) {
|
||||||
const { default: props } = await import(`../${command}?v=${queryValue}`);
|
const { default: props } = await import(`../${command}?v=${queryValue}`);
|
||||||
queryValue++;
|
queryValue++;
|
||||||
if (props.requires.includes("mashape") && process.env.MASHAPE === "") return log("warn", `Mashape/RapidAPI info not provided in config, skipped loading command ${command}...`);
|
|
||||||
if (props.requires.includes("sound") && soundStatus) return log("warn", `Failed to connect to some Lavalink nodes, skipped loading command ${command}...`);
|
if (props.requires.includes("sound") && soundStatus) return log("warn", `Failed to connect to some Lavalink nodes, skipped loading command ${command}...`);
|
||||||
const commandArray = command.split("/");
|
const commandArray = command.split("/");
|
||||||
const commandName = commandArray[commandArray.length - 1].split(".")[0];
|
const commandName = commandArray[commandArray.length - 1].split(".")[0];
|
||||||
|
|
Loading…
Reference in a new issue