mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 06:37:32 +02:00
Poem Command
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { stripIndents } = require('common-tags');
|
||||
|
||||
module.exports = class PoemCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'poem',
|
||||
aliases: ['poetry'],
|
||||
group: 'search',
|
||||
memberName: 'poem',
|
||||
description: 'Searches for poems by a specific author.',
|
||||
credit: [
|
||||
{
|
||||
name: 'PoetryDB',
|
||||
url: 'https://poetrydb.org/index.html',
|
||||
reason: 'API',
|
||||
reasonURL: 'https://github.com/thundercomb/poetrydb/blob/master/README.md'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'author',
|
||||
prompt: 'What author would you like to get a poem from?',
|
||||
type: 'string',
|
||||
parse: author => encodeURIComponent(author)
|
||||
},
|
||||
{
|
||||
key: 'title',
|
||||
prompt: 'What is the title of the poem you want to get?',
|
||||
type: 'string',
|
||||
parse: title => encodeURIComponent(title)
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { author, title }) {
|
||||
try {
|
||||
const { body } = await request.get(`https://poetrydb.org/author,title/${author};${title}`);
|
||||
const data = body[0];
|
||||
return msg.say(stripIndents`
|
||||
**${data.title}** by **${data.author}**
|
||||
${data.lines.join('\n')}
|
||||
`);
|
||||
} catch (err) {
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user