mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-25 14:21:41 +02:00
Add Number Choice to XKCD
This commit is contained in:
@@ -7,20 +7,16 @@ module.exports = class XKCDCommand extends Command {
|
|||||||
super(client, {
|
super(client, {
|
||||||
name: 'xkcd',
|
name: 'xkcd',
|
||||||
aliases: ['kcd'],
|
aliases: ['kcd'],
|
||||||
group: 'randomimg',
|
group: 'search',
|
||||||
memberName: 'xkcd',
|
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'],
|
clientPermissions: ['EMBED_LINKS'],
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'type',
|
key: 'type',
|
||||||
prompt: 'Would you like to get the comic for today or random?',
|
prompt: 'Would you like to get the comic for today or random?',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: 'random',
|
default: 'random'
|
||||||
validate: (type) => {
|
|
||||||
if (['today', 'random'].includes(type.toLowerCase())) return true;
|
|
||||||
else return 'Please enter either `today` or `random`';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -37,7 +33,7 @@ module.exports = class XKCDCommand extends Command {
|
|||||||
.setImage(current.body.img)
|
.setImage(current.body.img)
|
||||||
.setFooter(current.body.alt);
|
.setFooter(current.body.alt);
|
||||||
return msg.embed(embed);
|
return msg.embed(embed);
|
||||||
} else {
|
} else if (type === 'random') {
|
||||||
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`);
|
||||||
@@ -47,6 +43,17 @@ module.exports = class XKCDCommand extends Command {
|
|||||||
.setImage(body.img)
|
.setImage(body.img)
|
||||||
.setFooter(body.alt);
|
.setFooter(body.alt);
|
||||||
return msg.embed(embed);
|
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",
|
"name": "xiaobot",
|
||||||
"version": "22.1.1",
|
"version": "22.1.2",
|
||||||
"description": "A Discord Bot",
|
"description": "A Discord Bot",
|
||||||
"main": "Shard.js",
|
"main": "Shard.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user