2019-10-24 20:35:06 +00:00
|
|
|
const fetch = require("node-fetch");
|
|
|
|
|
|
|
|
exports.run = async (message, args) => {
|
|
|
|
const url = args.length > 0 && args[0].match(/^\d+$/) ? `http://xkcd.com/${args[0]}/info.0.json` : "http://xkcd.com/info.0.json";
|
2019-11-23 23:23:28 +00:00
|
|
|
try {
|
|
|
|
const request = await fetch(url);
|
|
|
|
const json = await request.json();
|
|
|
|
const embed = {
|
|
|
|
"embed": {
|
|
|
|
"title": json.safe_title,
|
|
|
|
"url": `https://xkcd.com/${json.num}`,
|
|
|
|
"color": 16711680,
|
|
|
|
"description": json.alt,
|
|
|
|
"image": {
|
|
|
|
"url": json.img
|
|
|
|
}
|
2019-10-24 20:35:06 +00:00
|
|
|
}
|
2019-11-23 23:23:28 +00:00
|
|
|
};
|
2020-04-12 19:51:48 +00:00
|
|
|
return embed;
|
2019-12-02 20:47:22 +00:00
|
|
|
} catch (e) {
|
|
|
|
return `${message.author.mention}, I couldn't get that XKCD!`;
|
2019-11-23 23:23:28 +00:00
|
|
|
}
|
2019-12-02 20:47:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.category = 4;
|
2019-12-05 16:58:46 +00:00
|
|
|
exports.help = "Gets an XKCD comic";
|
|
|
|
exports.params = "{id}";
|