From 467abf13abdd1d5d938aee5407afd9726237056a Mon Sep 17 00:00:00 2001 From: Essem Date: Sun, 6 Feb 2022 22:17:39 -0600 Subject: [PATCH] Remove RapidAPI dependency from wikihow --- .env.example | 2 -- commands/fun/wikihow.js | 31 ++++++++++++++++--------------- utils/handler.js | 3 +-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.env.example b/.env.example index 41a21d9..1a6e80c 100644 --- a/.env.example +++ b/.env.example @@ -29,8 +29,6 @@ PREFIX=& # (you can still make the bot leave using the stop command) STAYVC=false -# Put Mashape/RapidAPI key here -MASHAPE= # Put DBL/top.gg token here DBL= # Put Tenor API key here (used for obtaining raw tenor GIF urls) diff --git a/commands/fun/wikihow.js b/commands/fun/wikihow.js index 8a5ccae..1c9f6cb 100644 --- a/commands/fun/wikihow.js +++ b/commands/fun/wikihow.js @@ -4,25 +4,26 @@ import Command from "../../classes/command.js"; class WikihowCommand extends Command { async run() { this.client.sendChannelTyping(this.message.channel.id); - const request = await fetch("https://hargrimm-wikihow-v1.p.rapidapi.com/images?count=1", { - headers: { - "X-RapidAPI-Key": process.env.MASHAPE, - "X-RapidAPI-Host": "hargrimm-wikihow-v1.p.rapidapi.com", - "Accept": "application/json" - } - }); + const request = await fetch("https://www.wikihow.com/api.php?action=query&generator=random&prop=imageinfo&format=json&iiprop=url&grnnamespace=6"); const json = await request.json(); - const image = await fetch(json["1"]); - const imageBuffer = Buffer.from(await image.arrayBuffer()); - return { - file: imageBuffer, - name: json["1"].split("/")[json["1"].split("/").length - 1] - }; + const id = Object.keys(json.query.pages)[0]; + const data = json.query.pages[id]; + if (data.imageinfo) { + return { + embeds: [{ + color: 16711680, + image: { + url: json.query.pages[id].imageinfo[0].url + } + }] + }; + } else { + return await this.run(); + } } static description = "Gets a random WikiHow image"; static aliases = ["wiki"]; - static requires = ["mashape"]; } -export default WikihowCommand; \ No newline at end of file +export default WikihowCommand; diff --git a/utils/handler.js b/utils/handler.js index bbd7194..84a44a7 100644 --- a/utils/handler.js +++ b/utils/handler.js @@ -7,7 +7,6 @@ let queryValue = 0; export async function load(command, soundStatus) { const { default: props } = await import(`../${command}?v=${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}...`); const commandArray = command.split("/"); const commandName = commandArray[commandArray.length - 1].split(".")[0]; @@ -30,4 +29,4 @@ export async function load(command, soundStatus) { } } return false; -} \ No newline at end of file +}