diff --git a/commands/randomimg/xkcd.js b/commands/search/xkcd.js similarity index 71% rename from commands/randomimg/xkcd.js rename to commands/search/xkcd.js index 92ae3c60..949d51b4 100644 --- a/commands/randomimg/xkcd.js +++ b/commands/search/xkcd.js @@ -7,20 +7,16 @@ module.exports = class XKCDCommand extends Command { super(client, { name: 'xkcd', aliases: ['kcd'], - group: 'randomimg', + group: 'search', memberName: 'xkcd', - description: 'Gets an XKCD Comic, optionally opting for today\'s.', + description: 'Gets an XKCD Comic, optionally opting for today\'s or random.', clientPermissions: ['EMBED_LINKS'], args: [ { key: 'type', prompt: 'Would you like to get the comic for today or random?', type: 'string', - default: 'random', - validate: (type) => { - if (['today', 'random'].includes(type.toLowerCase())) return true; - else return 'Please enter either `today` or `random`'; - } + default: 'random' } ] }); @@ -37,7 +33,7 @@ module.exports = class XKCDCommand extends Command { .setImage(current.body.img) .setFooter(current.body.alt); return msg.embed(embed); - } else { + } else if (type === 'random') { const random = Math.floor(Math.random() * current.body.num) + 1; const { body } = await snekfetch .get(`https://xkcd.com/${random}/info.0.json`); @@ -47,6 +43,17 @@ module.exports = class XKCDCommand extends Command { .setImage(body.img) .setFooter(body.alt); return msg.embed(embed); + } else { + const choice = parseInt(type, 10); + if (isNaN(choice) || body.num < choice || body.num < 0) return msg.say('Invalid Number'); + const { body } = await snekfetch + .get(`https://xkcd.com/${choice}/info.0.json`); + const embed = new RichEmbed() + .setTitle(`${body.num} - ${body.title}`) + .setURL(`https://xkcd.com/${body.num}`) + .setImage(body.img) + .setFooter(body.alt); + return msg.embed(embed); } } }; diff --git a/package.json b/package.json index 99863173..071596e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "22.1.1", + "version": "22.1.2", "description": "A Discord Bot", "main": "Shard.js", "scripts": {