mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-09 18:39:35 +02:00
Use Joke API in joke
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const jokes = require('../../assets/json/joke');
|
||||
const request = require('node-superfetch');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const blacklistFlags = ['religious', 'racist', 'sexist'];
|
||||
const nsfw = ['nsfw', 'explicit'];
|
||||
|
||||
module.exports = class JokeCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -7,11 +10,32 @@ module.exports = class JokeCommand extends Command {
|
||||
name: 'joke',
|
||||
group: 'random-res',
|
||||
memberName: 'joke',
|
||||
description: 'Responds with a random joke.'
|
||||
description: 'Responds with a random joke.',
|
||||
credit: [
|
||||
{
|
||||
name: 'JokeAPI',
|
||||
url: 'https://v2.jokeapi.dev/',
|
||||
reason: 'API'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
return msg.say(jokes[Math.floor(Math.random() * jokes.length)]);
|
||||
async run(msg) {
|
||||
const blacklist = msg.channel.nsfw ? blacklistFlags : blacklistFlags.concat(nsfw);
|
||||
try {
|
||||
const { body } = await request
|
||||
.get('https://v2.jokeapi.dev/joke/Any')
|
||||
.query({ blacklistFlags: blacklist.join(',') });
|
||||
if (body.type === 'twopart') {
|
||||
return msg.say(stripIndents`
|
||||
_${body.setup}_
|
||||
${body.delivery}
|
||||
`);
|
||||
}
|
||||
return msg.say(body.joke);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user