Embedded XKCD

This commit is contained in:
Daniel Odendahl Jr
2017-05-25 18:00:11 +00:00
parent 61e5acce66
commit c22ec43fed
2 changed files with 14 additions and 6 deletions
+13 -5
View File
@@ -1,4 +1,5 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
module.exports = class XKCDCommand extends Command { module.exports = class XKCDCommand extends Command {
@@ -31,14 +32,21 @@ module.exports = class XKCDCommand extends Command {
try { try {
const current = await snekfetch const current = await snekfetch
.get('https://xkcd.com/info.0.json'); .get('https://xkcd.com/info.0.json');
if (type === 'today') return msg.say({ files: [current.body.img] }) if (type === 'today') {
.catch(err => msg.say(`${err.name}: ${err.message}`)); const embed = new RichEmbed()
else { .setTitle(`${current.body.num} - ${current.body.title}`)
.setImage(current.body.img)
.setFooter(current.body.alt);
return msg.embed(embed);
} else {
const random = Math.floor(Math.random() * current.body.num) + 1; const random = Math.floor(Math.random() * current.body.num) + 1;
const { body } = await snekfetch const { body } = await snekfetch
.get(`https://xkcd.com/${random}/info.0.json`); .get(`https://xkcd.com/${random}/info.0.json`);
return msg.say({ files: [body.img] }) const embed = new RichEmbed()
.catch(err => msg.say(`${err.name}: ${err.message}`)); .setTitle(`${body.num} - ${body.title}`)
.setImage(body.img)
.setFooter(body.alt);
return msg.embed(embed);
} }
} catch (err) { } catch (err) {
return msg.say(`${err.name}: ${err.message}`); return msg.say(`${err.name}: ${err.message}`);
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiaobot", "name": "xiaobot",
"version": "21.1.0", "version": "21.1.1",
"description": "A Discord Bot", "description": "A Discord Bot",
"main": "Shard.js", "main": "Shard.js",
"scripts": { "scripts": {