DIE EMBEDS

This commit is contained in:
Daniel Odendahl Jr
2017-09-28 18:09:06 +00:00
parent 92d9f11e74
commit 70dd45af9a
11 changed files with 39 additions and 108 deletions
+6 -10
View File
@@ -1,6 +1,6 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
const { WORDNIK_KEY } = process.env;
module.exports = class WordOfTheDayCommand extends Command {
@@ -10,8 +10,7 @@ module.exports = class WordOfTheDayCommand extends Command {
aliases: ['wordnik-word-of-the-day'],
group: 'random',
memberName: 'word-of-the-day',
description: 'Gets the word of the day.',
clientPermissions: ['EMBED_LINKS']
description: 'Gets the word of the day.'
});
}
@@ -20,13 +19,10 @@ module.exports = class WordOfTheDayCommand extends Command {
const { body } = await snekfetch
.get('http://api.wordnik.com/v4/words.json/wordOfTheDay')
.query({ api_key: WORDNIK_KEY });
const embed = new MessageEmbed()
.setAuthor('Wordnik', 'https://i.imgur.com/VcLZLXn.jpg')
.setColor(0xFE6F11)
.setTitle(body.word)
.setURL('http://wordnik.com/word-of-the-day')
.setDescription(`(${body.definitions[0].partOfSpeech || 'N/A'}) ${body.definitions[0].text}`);
return msg.embed(embed);
return msg.say(stripIndents`
**${body.word}**
(${body.definitions[0].partOfSpeech || 'N/A'}) ${body.definitions[0].text}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
+5 -18
View File
@@ -1,7 +1,6 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { shorten } = require('../../structures/Util');
const { stripIndents } = require('common-tags');
module.exports = class DerpibooruCommand extends Command {
constructor(client) {
@@ -11,7 +10,6 @@ module.exports = class DerpibooruCommand extends Command {
group: 'search',
memberName: 'derpibooru',
description: 'Searches Derpibooru for your query.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
@@ -33,21 +31,10 @@ module.exports = class DerpibooruCommand extends Command {
if (!search.body) return msg.say('Could not find any results.');
const { body } = await snekfetch
.get(`https://derpibooru.org/images/${search.body.id}.json`);
if (!msg.channel.nsfw && body.tags.includes('suggestive')) {
return msg.say('This image is only viewable in NSFW channels.');
}
const embed = new MessageEmbed()
.setAuthor('Derpibooru', 'https://i.imgur.com/cptnecp.png')
.setColor(0xC6D2E1)
.setURL(`https://derpibooru.org/images/${body.id}`)
.setImage(`https:${body.representations.medium}`)
.addField(' Uploader',
body.uploader, true)
.addField(' Upload Date',
new Date(body.created_at).toDateString(), true)
.addField(' Tags',
shorten(body.tags, 1000));
return msg.embed(embed);
return msg.say(stripIndents`
Result for ${query}:
${body.representations.medium}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
+5 -9
View File
@@ -1,6 +1,6 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
const { WORDNIK_KEY } = process.env;
module.exports = class DictionaryCommand extends Command {
@@ -11,7 +11,6 @@ module.exports = class DictionaryCommand extends Command {
group: 'search',
memberName: 'dictionary',
description: 'Defines a word.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
@@ -34,13 +33,10 @@ module.exports = class DictionaryCommand extends Command {
});
if (!body.length) return msg.say('Could not find any results.');
const data = body[0];
const embed = new MessageEmbed()
.setAuthor('Wordnik', 'https://i.imgur.com/VcLZLXn.jpg')
.setColor(0xFE6F11)
.setTitle(data.word)
.setURL(`http://wordnik.com/words/${query}#define`)
.setDescription(`(${data.partOfSpeech || 'N/A'}) ${data.text}`);
return msg.embed(embed);
return msg.say(stripIndents`
**${data.word}**
(${data.partOfSpeech || 'N/A'}) ${data.text}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
+1 -9
View File
@@ -1,5 +1,4 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { FLICKR_KEY } = process.env;
@@ -11,7 +10,6 @@ module.exports = class FlickrCommand extends Command {
group: 'search',
memberName: 'flickr',
description: 'Searches Flickr for your query.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
@@ -35,13 +33,7 @@ module.exports = class FlickrCommand extends Command {
});
if (!body.photos.photo.length) return msg.say('Could not find any results.');
const data = body.photos.photo[Math.floor(Math.random() * body.photos.photo.length)];
const embed = new MessageEmbed()
.setAuthor('Flickr', 'https://i.imgur.com/8QPPlV9.png')
.setColor(0x0059D4)
.setImage(`https://farm${data.farm}.staticflickr.com/${data.server}/${data.id}_${data.secret}.jpg`)
.setTitle(data.title)
.setURL(`https://www.flickr.com/photos/${data.owner}/${data.id}`);
return msg.embed(embed);
return msg.say(`https://farm${data.farm}.staticflickr.com/${data.server}/${data.id}_${data.secret}.jpg`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
+1 -13
View File
@@ -1,5 +1,4 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { GIPHY_KEY } = process.env;
@@ -11,7 +10,6 @@ module.exports = class GiphyCommand extends Command {
group: 'search',
memberName: 'giphy',
description: 'Searches Giphy for your query.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
@@ -32,17 +30,7 @@ module.exports = class GiphyCommand extends Command {
rating: msg.channel.nsfw ? 'r' : 'pg'
});
if (!body.data.length) return msg.say('Could not find any results.');
const data = body.data[Math.floor(Math.random() * body.data.length)];
const embed = new MessageEmbed()
.setAuthor('Giphy', 'https://i.imgur.com/rWphUCU.jpg')
.setColor(0x4C177F)
.setURL(data.url)
.setImage(data.images.original.url.replace(/\?fingerprint=.+/gi, ''))
.addField(' Uploader',
data.username || 'N/A', true)
.addField(' Upload Date',
new Date(data.import_datetime).toDateString(), true);
return msg.embed(embed);
return msg.say(body.data[Math.floor(Math.random() * body.data.length)].images.original.url);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
+5 -9
View File
@@ -1,6 +1,6 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
module.exports = class JishoCommand extends Command {
constructor(client) {
@@ -10,7 +10,6 @@ module.exports = class JishoCommand extends Command {
group: 'search',
memberName: 'jisho',
description: 'Defines a word, but with Japanese.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
@@ -28,13 +27,10 @@ module.exports = class JishoCommand extends Command {
.query({ keyword: query });
if (!body.data.length) return msg.say('Could not find any results.');
const data = body.data[0];
const embed = new MessageEmbed()
.setAuthor('Jisho', 'https://i.imgur.com/CBJZe2m.png')
.setColor(0x0BC510)
.setTitle(data.japanese[0].word)
.setURL(`http://jisho.org/word/${data.japanese[0].word}`)
.setDescription(data.senses[0].english_definitions.join(', '));
return msg.embed(embed);
return msg.say(stripIndents`
**${data.japanese[0].word}**
${data.senses[0].english_definitions.join(', ')}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
+6 -24
View File
@@ -1,12 +1,7 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { xml2js } = require('xml-js');
const { shorten } = require('../../structures/Util');
const ratings = {
s: 'Safe',
q: 'Questionable'
};
const { stripIndents } = require('common-tags');
module.exports = class SafebooruCommand extends Command {
constructor(client) {
@@ -16,13 +11,11 @@ module.exports = class SafebooruCommand extends Command {
group: 'search',
memberName: 'safebooru',
description: 'Searches Safebooru for your query.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
prompt: 'What image would you like to search for?',
type: 'string',
default: ''
type: 'string'
}
]
});
@@ -40,21 +33,10 @@ module.exports = class SafebooruCommand extends Command {
});
const parsed = xml2js(text, { compact: true }).posts;
if (parsed._attributes.count === '0' || !parsed.post.length) return msg.say('Could not find any results.');
const posts = msg.channel.nsfw ? parsed.post : parsed.post.filter(post => post._attributes.rating === 's');
if (!posts.length) return msg.say('Could not find any results.');
const data = posts[Math.floor(Math.random() * posts.length)]._attributes;
const embed = new MessageEmbed()
.setAuthor('Safebooru', 'https://i.imgur.com/iGMNwhf.jpg')
.setColor(0xC6D2E1)
.setURL(`http://safebooru.org/index.php?page=post&s=view&id=${data.id}`)
.setImage(`https:${data.file_url}`)
.addField(' Upload Date',
new Date(data.created_at).toDateString(), true)
.addField(' Rating',
ratings[data.rating], true)
.addField(' Tags',
shorten(data.tags, 1000));
return msg.embed(embed);
return msg.say(stripIndents`
Result for ${query}:
http:${parsed.post.posts[Math.floor(Math.random() * parsed.post.posts.length)]._attributes.file_url}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
+6 -12
View File
@@ -1,6 +1,6 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
const { WORDNIK_KEY } = process.env;
module.exports = class ThesaurusCommand extends Command {
@@ -11,7 +11,6 @@ module.exports = class ThesaurusCommand extends Command {
group: 'search',
memberName: 'thesaurus',
description: 'Gets the synonyms and antonyms of a word.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
@@ -35,16 +34,11 @@ module.exports = class ThesaurusCommand extends Command {
if (!body.length) return msg.say('Could not find any results.');
const synonyms = body.find(i => i.relationshipType === 'synonym');
const antonyms = body.find(i => i.relationshipType === 'antonym');
const embed = new MessageEmbed()
.setAuthor('Wordnik', 'https://i.imgur.com/VcLZLXn.jpg')
.setColor(0xFE6F11)
.setTitle(query)
.setURL(`http://wordnik.com/words/${query}#relate`)
.addField(' Synonyms',
synonyms ? synonyms.words.join(', ') : 'N/A')
.addField(' Antonyms',
antonyms ? antonyms.words.join(', ') : 'N/A');
return msg.embed(embed);
return msg.say(stripIndents`
**${query}**
__Synonyms:__ ${synonyms ? synonyms.words.join(', ') : 'N/A'}
__Antonyms:__ ${antonyms ? antonyms.words.join(', ') : 'N/A'}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
-2
View File
@@ -67,9 +67,7 @@ module.exports = class TranslateCommand extends Command {
});
const lang = body.lang.split('-');
const embed = new MessageEmbed()
.setAuthor('Yandex.Translate', 'https://i.imgur.com/HMpH9sq.png')
.setColor(0xFF0000)
.setURL(`https://translate.yandex.com/?lang=${body.lang}&text=${encodeURIComponent(text)}`)
.addField(` From: ${codes[lang[0]]}`,
text)
.addField(` To: ${codes[lang[1]]}`,
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "42.15.1",
"version": "42.15.2",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {
+3 -1
View File
@@ -4,7 +4,8 @@ class XiaoCommand extends Command {
constructor(client, info) {
super(client, info);
this.ownerOnly = info.ownerOnly;
this.ownerOnly = !!info.ownerOnly;
this.nsfw = !!info.nsfw;
this.throttling = info.throttling || {
usages: 1,
duration: 2
@@ -17,6 +18,7 @@ class XiaoCommand extends Command {
if (this.ownerOnly && !this.client.isOwner(msg.author)) {
return `The \`${this.name}\` command can only be used by the bot owner.`;
}
if (this.nsfw && !msg.channel.nsfw) return `The \`${this.name}\` command can only be used in NSFW channels.`;
return true;
}
}