This commit is contained in:
Daniel Odendahl Jr
2017-09-27 16:49:37 +00:00
parent 9f1b9688ae
commit 8a70e44902
16 changed files with 88 additions and 18 deletions
+13 -1
View File
@@ -1,4 +1,5 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { GIPHY_KEY } = process.env;
@@ -10,6 +11,7 @@ module.exports = class GiphyCommand extends Command {
group: 'search',
memberName: 'giphy',
description: 'Searches Giphy for your query.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
@@ -30,7 +32,17 @@ module.exports = class GiphyCommand extends Command {
rating: msg.channel.nsfw ? 'r' : 'pg'
});
if (!body.data.length) return msg.say('Could not find any results.');
return msg.say(body.data[Math.floor(Math.random() * body.data.length)].images.original.url);
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);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}