mrmBot-Matrix/commands/fun/wikihow.js

30 lines
839 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://www.wikihow.com/api.php?action=query&generator=random&prop=imageinfo&format=json&iiprop=url&grnnamespace=6");
const json = await request.json();
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"];
}
export default WikihowCommand;