mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-07 06:45:31 +02:00
Book Command
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { shorten } = require('../../util/Util');
|
||||
const { GOOGLE_KEY } = process.env;
|
||||
|
||||
module.exports = class GoogleBookCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'google-book',
|
||||
aliases: ['google-books', 'book'],
|
||||
group: 'search',
|
||||
memberName: 'google-book',
|
||||
description: 'Searches Google Books for a book.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What book would you like to search for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.get('https://www.googleapis.com/books/v1/volumes')
|
||||
.query({
|
||||
apiKey: GOOGLE_KEY,
|
||||
q: query,
|
||||
maxResults: 1,
|
||||
printType: 'books'
|
||||
});
|
||||
if (!body.items) return msg.say('Could not find any results.');
|
||||
const data = body.items[0].volumeInfo;
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x4285F4)
|
||||
.setTitle(data.title)
|
||||
.setURL(data.previewLink)
|
||||
.setAuthor('Google Books', 'https://i.imgur.com/N3oHABo.png')
|
||||
.setDescription(data.description ? shorten(data.description) : 'No description available.')
|
||||
.setThumbnail(data.imageLinks ? data.imageLinks.thumbnail : null)
|
||||
.addField('❯ Authors',
|
||||
data.authors.length ? data.authors.join(', ') : '???')
|
||||
.addField('❯ Publisher',
|
||||
data.publisher || '???', true)
|
||||
.addField('❯ Publish Date',
|
||||
data.publishedDate || '???', true)
|
||||
.addField('❯ Page Count',
|
||||
data.pageCount || '???', true)
|
||||
.addField('❯ Genres',
|
||||
data.categories.length ? data.categories.join(', ') : '???');
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "55.0.1",
|
||||
"version": "55.1.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "XiaoBot.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user