Files
xiao/commands/search/wattpad.js
T
Daniel Odendahl Jr fd4e35533a 23
2017-06-17 03:26:31 +00:00

57 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const Command = require('../../structures/Command');
const { RichEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const moment = require('moment');
const { WATTPAD_KEY } = process.env;
module.exports = class WattpadCommand extends Command {
constructor(client) {
super(client, {
name: 'wattpad',
group: 'search',
memberName: 'wattpad',
description: 'Searches Wattpad for your query.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
prompt: 'What book would you like to search for?',
type: 'string'
}
]
});
}
async run(msg, args) {
const { query } = args;
const { body } = await snekfetch
.get('https://api.wattpad.com:443/v4/stories')
.query({
query,
limit: 1
})
.set({ Authorization: `Basic ${WATTPAD_KEY}` });
if (!body.stories.length) return msg.say('No Results.');
const embed = new RichEmbed()
.setColor(0xF89C34)
.setAuthor('Wattpad', 'https://i.imgur.com/Rw9vRQB.png')
.setURL(body.stories[0].url)
.setTitle(body.stories[0].title)
.setDescription(body.stories[0].description.substr(0, 2000))
.setThumbnail(body.stories[0].cover)
.addField(' Created On',
moment(body.stories[0].createDate).format('MMMM Do YYYY'), true)
.addField(' Author',
body.stories[0].user, true)
.addField(' Parts',
body.stories[0].numParts, true)
.addField(' Reads',
body.stories[0].readCount, true)
.addField(' Votes',
body.stories[0].voteCount, true)
.addField(' Comments',
body.stories[0].commentCount, true);
return msg.embed(embed);
}
};