mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Add Number Choice to XKCD
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "22.1.1",
|
||||
"version": "22.1.2",
|
||||
"description": "A Discord Bot",
|
||||
"main": "Shard.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user