mrmBot-Matrix/commands/fun/wikihow.js

28 lines
865 B
JavaScript
Raw Normal View History

import fetch from "node-fetch";
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 json = await request.json();
const image = await fetch(json["1"]);
const imageBuffer = await image.buffer();
return {
file: imageBuffer,
name: json["1"].split("/")[json["1"].split("/").length - 1]
};
}
static description = "Gets a random WikiHow image";
static aliases = ["wiki"];
static requires = ["mashape"];
}
export default WikihowCommand;