Wattpad Command Added

This commit is contained in:
dragonfire535
2017-03-05 00:30:19 -05:00
parent e4c10ade07
commit 257d56ec5b
3 changed files with 67 additions and 1 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ class InfoCommand extends commando.Command {
.addField('Packages',
"[Commando](https://github.com/Gawdl3y/discord.js-commando) (0.9.0), [cleverbot-node](https://github.com/fojas/cleverbot-node) (0.3.5), [pirate-speak](https://github.com/mikewesthad/pirate-speak) (1.0.1), [JIMP](https://github.com/oliver-moran/jimp) (0.2.27), [google-translate-api](https://github.com/matheuss/google-translate-api) (2.2.2), [urban](https://github.com/mvrilo/urban) (0.3.1), [zalgoize](https://github.com/clux/zalgolize) (1.2.4), [hepburn](https://github.com/lovell/hepburn) (1.0.0), [wikifakt](https://github.com/coffee-cup/wikifakt) (1.0.3), [osu](https://github.com/IOExceptionOsu/node-osu) (1.0.1), [yahoo-weather](https://github.com/mamal72/node-yahoo-weather) (2.2.2)")
.addField('Other Credit',
"[Cleverbot API](https://www.cleverbot.com/api/)")
"[Cleverbot API](https://www.cleverbot.com/api/), [Wattpad API](https://developer.wattpad.com/docs/api)")
.addField('My Server',
"[Click Here to Join!](https://discord.gg/fqQF8mc)")
.addField('Invite Link:',
+65
View File
@@ -0,0 +1,65 @@
const commando = require('discord.js-commando');
const Discord = require('discord.js');
const request = require('request-promise');
const config = require('../../config.json');
class WattpadCommand extends commando.Command {
constructor(Client){
super(Client, {
name: 'wattpad',
group: 'search',
memberName: 'wattpad',
description: 'Searches Wattpad for a specified book. (;wattpad Heroes of Dreamland)',
examples: [';wattpad Heroes of Dreamland']
});
}
async run(message, args) {
if(message.channel.type !== 'dm') {
if(!message.channel.permissionsFor(this.client.user).hasPermission('SEND_MESSAGES')) return;
if(!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGES')) return;
if(!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return;
}
console.log("[Command] " + message.content);
let querybook = message.content.split(" ").slice(1).join(" ");
const options = {
method: 'GET',
uri: 'https://api.wattpad.com:443/v4/stories',
headers: {
'Authorization': 'Basic ' + config.wattpadkey
},
qs: {
query: querybook,
limit: 1
},
json: true
}
request(options).then(function (response) {
const embed = new Discord.RichEmbed()
.setColor(0xF89C34)
.setAuthor('Wattpad', 'http://www.selfpubtoolbox.com/wp-content/uploads/2015/05/a6044fd3a88acd5043860484db972ca6.png')
.setURL(response.stories[0].url)
.setTitle(response.stories[0].title)
.setDescription(response.stories[0].description.substr(0, 1500) + "... [Read the Rest Here!](" + response.stories[0].url + ")")
.addField('**Author:**',
response.stories[0].user, true)
.addField('**Parts:**',
response.stories[0].numParts, true)
.addField('**Story ID:**',
response.stories[0].id, true)
.addField('**Votes:**',
response.stories[0].voteCount, true)
.addField('**Reads:**',
response.stories[0].readCount, true)
.addField('**Comments:**',
response.stories[0].commentCount, true)
.addField('**Created On:**',
response.stories[0].createDate, true);
message.channel.sendEmbed(embed).catch(console.error);
}).catch(function (err) {
message.channel.sendMessage(":x: Error! Book not Found!");
});
}
}
module.exports = WattpadCommand;
+1
View File
@@ -20,6 +20,7 @@
"jimp": "^0.2.27",
"osu": "^1.0.1",
"pirate-speak": "^1.0.1",
"request-promise": "^4.1.1",
"urban": "^0.3.1",
"wikifakt": "^1.0.3",
"yahoo-weather": "^2.2.2",