Code Improvements, NSFW Anime Command

This commit is contained in:
Daniel Odendahl Jr
2017-05-08 23:09:37 +00:00
parent 9db1d8f6e0
commit 448c137b38
23 changed files with 77 additions and 32 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ You can join the home server with [this link](https://discord.gg/fqQF8mc).
[discord.js](https://discord.js.org), [commando](https://github.com/Gawdl3y/discord.js-commando), [zalgoize](https://github.com/clux/zalgolize), [superagent](https://visionmedia.github.io/superagent), [mathjs](http://mathjs.org), [moment](http://momentjs.com), [moment-duration-format](https://github.com/jsmreese/moment-duration-format), [jimp](https://github.com/oliver-moran/jimp), [cheerio](https://cheerio.js.org), [sequelize](http://docs.sequelizejs.com), [pg](https://github.com/brianc/node-postgres)
## APIs
[Wattpad](https://developer.wattpad.com), [Wordnik](http://developer.wordnik.com), [osu!](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link), [YuGiOh](http://docs.yugiohprices.apiary.io), [YouTube](https://developers.google.com/youtube), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com), [Yahoo Weather](https://developer.yahoo.com/weather), [Google Maps](https://developers.google.com/maps), [Strawpoll](https://github.com/strawpoll/strawpoll/wiki/API), [rrrather](http://www.rrrather.com/botapi), [SoundCloud](https://developers.soundcloud.com), [random.cat](http://random.cat), [random.dog](https://random.dog), [fixer.io](http://fixer.io)
[Wattpad](https://developer.wattpad.com), [Wordnik](http://developer.wordnik.com), [osu!](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link), [YuGiOh](http://docs.yugiohprices.apiary.io), [YouTube](https://developers.google.com/youtube), [Discord Bots](https://bots.discord.pw/api), [Today in History](http://history.muffinlabs.com/#api), [jService](http://jservice.io), [Urban Dictionary](https://github.com/zdict/zdict/wiki/Urban-dictionary-API-documentation), [OMDB](http://www.omdbapi.com), [Yahoo Weather](https://developer.yahoo.com/weather), [Google Maps](https://developers.google.com/maps), [Strawpoll](https://github.com/strawpoll/strawpoll/wiki/API), [rrrather](http://www.rrrather.com/botapi), [SoundCloud](https://developers.soundcloud.com), [random.cat](http://random.cat), [random.dog](https://random.dog), [fixer.io](http://fixer.io), [konachan](https://konachan.net)
## Licensing
The bot is licensed under an [ISC License](https://opensource.org/licenses/ISC). See the file `LICENSE.md` for more information.
+1 -1
View File
@@ -21,7 +21,7 @@ module.exports = class GuildInfoCommand extends Command {
return msg.say('This Command requires the `Embed Links` Permission.');
const embed = new RichEmbed()
.setColor(0x00AE86)
.setThumbnail(msg.guild.iconURL('png'))
.setThumbnail(msg.guild.iconURL())
.addField('**Name:**',
msg.guild.name, true)
.addField('**ID:**',
+28
View File
@@ -0,0 +1,28 @@
const { Command } = require('discord.js-commando');
const request = require('superagent');
module.exports = class NSFWAnimeCommand extends Command {
constructor(client) {
super(client, {
name: 'nsfw-anime',
group: 'randomimg',
memberName: 'nsfw-anime',
description: 'Sends a random (NSFW!) anime image.',
guildOnly: true
});
}
async run(msg) {
if (!msg.channel.nsfw) return msg.say('This Command can only be used in NSFW Channels.');
if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES'))
return msg.say('This Command requires the `Attach Files` Permission.');
try {
const { body } = await request
.get('https://konachan.net/post.json?tags=order:random&limit=1');
return msg.channel.send({ files: [`https:${body[0].file_url}`] })
.catch(err => msg.say(err));
} catch (err) {
return msg.say(err);
}
}
};
+2 -1
View File
@@ -1,6 +1,7 @@
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const request = require('superagent');
const { DISCORD_BOTS_KEY } = process.env;
module.exports = class BotSearchCommand extends Command {
constructor(client) {
@@ -27,7 +28,7 @@ module.exports = class BotSearchCommand extends Command {
try {
const { body } = await request
.get(`https://bots.discord.pw/api/bots/${bot.id}`)
.set({ 'Authorization': process.env.DISCORD_BOTS_KEY });
.set({ 'Authorization': DISCORD_BOTS_KEY });
const embed = new RichEmbed()
.setColor(0x9797FF)
.setAuthor('Discord Bots', 'https://i.imgur.com/lrKYBQi.jpg')
+2 -1
View File
@@ -1,6 +1,7 @@
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const request = require('superagent');
const { WORDNIK_KEY } = process.env;
module.exports = class DefineCommand extends Command {
constructor(client) {
@@ -27,7 +28,7 @@ module.exports = class DefineCommand extends Command {
const { query } = args;
try {
const { body } = await request
.get(`http://api.wordnik.com:80/v4/word.json/${query}/definitions?limit=1&includeRelated=false&useCanonical=false&api_key=${process.env.WORDNIK_KEY}`);
.get(`http://api.wordnik.com:80/v4/word.json/${query}/definitions?limit=1&includeRelated=false&useCanonical=false&api_key=${WORDNIK_KEY}`);
if (body.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0x9797FF)
+1 -1
View File
@@ -33,7 +33,7 @@ module.exports = class GoogleCommand extends Command {
href = querystring.parse(href.replace('/url?', ''));
return message.edit(href.q);
} catch (err) {
return message.edit('An Error Occurred: No Results.');
return message.edit('Error: No Results.');
}
}
};
+2 -1
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando');
const request = require('superagent');
const { GOOGLE_KEY } = process.env;
module.exports = class MapCommand extends Command {
constructor(client) {
@@ -37,7 +38,7 @@ module.exports = class MapCommand extends Command {
const { zoom, query } = args;
try {
const { body } = await request
.get(`https://maps.googleapis.com/maps/api/staticmap?center=${query}&zoom=${zoom}&size=500x500&key=${process.env.GOOGLE_KEY}`);
.get(`https://maps.googleapis.com/maps/api/staticmap?center=${query}&zoom=${zoom}&size=500x500&key=${GOOGLE_KEY}`);
return msg.channel.send({ files: [{ attachment: body, name: 'map.png' }] })
.catch(err => msg.say(err));
} catch (err) {
+2 -1
View File
@@ -1,6 +1,7 @@
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const request = require('superagent');
const { OSU_KEY } = process.env;
module.exports = class OsuCommand extends Command {
constructor(client) {
@@ -27,7 +28,7 @@ module.exports = class OsuCommand extends Command {
const { query } = args;
try {
const { body } = await request
.get(`https://osu.ppy.sh/api/get_user?k=${process.env.OSU_KEY}&u=${query}&type=string`);
.get(`https://osu.ppy.sh/api/get_user?k=${OSU_KEY}&u=${query}&type=string`);
if (body.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xFF66AA)
+2 -1
View File
@@ -1,6 +1,7 @@
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const request = require('superagent');
const { SOUNDCLOUD_KEY } = process.env;
module.exports = class SoundCloudCommand extends Command {
constructor(client) {
@@ -27,7 +28,7 @@ module.exports = class SoundCloudCommand extends Command {
const { query } = args;
try {
const { body } = await request
.get(`https://api.soundcloud.com/tracks?q=${query}&client_id=${process.env.SOUNDCLOUD_KEY}`);
.get(`https://api.soundcloud.com/tracks?q=${query}&client_id=${SOUNDCLOUD_KEY}`);
if (body.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xF15A22)
+2 -1
View File
@@ -1,6 +1,7 @@
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const request = require('superagent');
const { WATTPAD_KEY } = process.env;
module.exports = class WattpadCommand extends Command {
constructor(client) {
@@ -28,7 +29,7 @@ module.exports = class WattpadCommand extends Command {
try {
const { body } = await request
.get(`https://api.wattpad.com:443/v4/stories?query=${query}&limit=1`)
.set({ 'Authorization': `Basic ${process.env.WATTPAD_KEY}` });
.set({ 'Authorization': `Basic ${WATTPAD_KEY}` });
if (body.stories.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xF89C34)
+2 -1
View File
@@ -1,6 +1,7 @@
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const request = require('superagent');
const { GOOGLE_KEY } = process.env;
module.exports = class YouTubeCommand extends Command {
constructor(client) {
@@ -27,7 +28,7 @@ module.exports = class YouTubeCommand extends Command {
const { query } = args;
try {
const { body } = await request
.get(`https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResults=1&q=${query}&key=${process.env.GOOGLE_KEY}`);
.get(`https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResults=1&q=${query}&key=${GOOGLE_KEY}`);
if (body.items.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xDD2825)
+10 -9
View File
@@ -36,7 +36,7 @@ module.exports = class YuGiOhCommand extends Command {
.setDescription(body.data.text)
.setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/7gPm9Rr.png')
.addField('**Card Type:**',
'monster', true)
body.data.card_type, true)
.addField('**Type:**',
body.data.type, true)
.addField('**Attribute:**',
@@ -48,15 +48,16 @@ module.exports = class YuGiOhCommand extends Command {
.addField('**Level:**',
body.data.level, true);
return msg.embed(embed);
} else {
const embed = new RichEmbed()
.setColor(0xBE5F1F)
.setTitle(body.data.name)
.setDescription(body.data.text)
.setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/7gPm9Rr.png')
.addField('**Card Type:**',
body.data.card_type, true);
return msg.embed(embed);
}
const embed = new RichEmbed()
.setColor(0xBE5F1F)
.setTitle(body.data.name)
.setDescription(body.data.text)
.setAuthor('Yu-Gi-Oh!', 'https://i.imgur.com/7gPm9Rr.png')
.addField('**Card Type:**',
body.data.card_type, true);
return msg.embed(embed);
} catch (err) {
return msg.say(err);
}
+2 -1
View File
@@ -1,5 +1,6 @@
const { Command } = require('discord.js-commando');
const request = require('superagent');
const { WEBHOOK_URL } = process.env;
module.exports = class WebhookCommand extends Command {
constructor(client) {
@@ -31,7 +32,7 @@ module.exports = class WebhookCommand extends Command {
try {
msg.delete();
await request
.post(process.env.WEBHOOK_URL)
.post(WEBHOOK_URL)
.send({ content });
return null;
} catch (err) {
+1 -1
View File
@@ -19,6 +19,6 @@ module.exports = class AvatarCommand extends Command {
run(msg, args) {
const { user } = args;
return msg.say(user.avatarURL('png', 2048) || user.displayAvatarURL);
return msg.say(user.avatarURL('webp', 2048) || user.displayAvatarURL);
}
};
+2 -1
View File
@@ -82,7 +82,8 @@ module.exports = class InfoCommand extends Command {
[SoundCloud](https://developers.soundcloud.com),
[random.cat](http://random.cat),
[random.dog](https://random.dog),
[fixer.io](http://fixer.io)
[fixer.io](http://fixer.io),
[konachan](https://konachan.net)
`
);
return msg.embed(embed);
+1
View File
@@ -52,6 +52,7 @@
<li><a href="http://random.cat">random.cat</a></li>
<li><a href="https://random.dog">random.dog</a></li>
<li><a href="http://fixer.io">fixer.io</a></li>
<li><a href="https://konachan.net">konachan</a></li>
</ul>
<h2>Information</h2>
<ul>
+1
View File
@@ -28,6 +28,7 @@
<li>Random Roasts, Fortunes, and Compliments!</li>
<li>Random Fact Core Quotes!</li>
<li>Random Name Generation!</li>
<li>Random Anime Images (with NSFW)!</li>
<li>Roleplay Commands!</li>
<li>Search Various sites including:</li>
<ul>
+2
View File
@@ -25,6 +25,7 @@
<li>Random Roasts, Fortunes, and Compliments!</li>
<li>Random Fact Core Quotes!</li>
<li>Random Name Generation!</li>
<li>Random Anime Images (with NSFW)!</li>
<li>Roleplay Commands!</li>
<li>Search Various sites including:</li>
<ul>
@@ -95,6 +96,7 @@
<li><a href="http://random.cat">random.cat</a></li>
<li><a href="https://random.dog">random.dog</a></li>
<li><a href="http://fixer.io">fixer.io</a></li>
<li><a href="https://konachan.net">konachan</a></li>
</ul>
<h2>Information</h2>
<ul>
+5 -4
View File
@@ -1,9 +1,10 @@
const { TOKEN, OWNER, PREFIX, INVITE } = process.env;
const { CommandoClient } = require('discord.js-commando');
const client = new CommandoClient({
commandPrefix: 'x;',
owner: '242699360352206850',
commandPrefix: PREFIX,
owner: OWNER,
disableEveryone: true,
invite: 'https://discord.gg/fqQF8mc',
invite: INVITE,
unknownCommandResponse: false
});
const path = require('path');
@@ -120,4 +121,4 @@ client.on('ready', () => {
client.user.setGame(`x;help | Shard ${client.shard.id}`);
});
client.login(process.env.TOKEN);
client.login(TOKEN);
+1 -2
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "18.6.4",
"version": "18.7.0",
"description": "A Discord Bot",
"main": "shardingmanager.js",
"scripts": {
@@ -42,7 +42,6 @@
"moment-duration-format": "^1.3.0",
"pg": "^6.1.5",
"sequelize": "^3.30.4",
"snekfetch": "guscaplan/snekfetch",
"superagent": "^3.5.2",
"zalgolize": "^1.2.4"
}
+2 -1
View File
@@ -1,3 +1,4 @@
const { ShardingManager } = require('discord.js');
const Manager = new ShardingManager('./index.js', { token: process.env.TOKEN });
const { TOKEN } = process.env;
const Manager = new ShardingManager('./index.js', { token: TOKEN });
Manager.spawn();
+2 -1
View File
@@ -1,5 +1,6 @@
const Sequelize = require('sequelize');
const database = new Sequelize(process.env.DATABASE_URL, { logging: false });
const { DATABASE_URL } = process.env;
const database = new Sequelize(DATABASE_URL, { logging: false });
class Database {
static get db() {
+3 -2
View File
@@ -1,17 +1,18 @@
const request = require('superagent');
const { CARBON_KEY, DISCORD_BOTS_KEY } = process.env;
class Stats {
static discordBots(server_count, userID) {
return request
.post(`https://bots.discord.pw/api/bots/${userID}/stats`)
.set({ 'Authorization': process.env.DISCORD_BOTS_KEY })
.set({ 'Authorization': DISCORD_BOTS_KEY })
.send({ server_count });
}
static carbon(servercount) {
return request
.post('https://www.carbonitex.net/discord/data/botdata.php')
.send({ key: process.env.CARBON_KEY, servercount });
.send({ key: CARBON_KEY, servercount });
}
}