const fn = require('../functions'); const axios = require('axios'); const dotenv = require('dotenv').config(); const Tenor = require('tenorjs-v2'); const tenor = new Tenor(process.env.TENOR_API_KEY); // TODO: Tenor has changed API versions, switch from TenorJS (unmaintained) to axios for // general API usage. See: https://github.com/Jinzulen/TenorJS/issues/12 // see also: https://developers.google.com/tenor/guides/migrate-from-v1 module.exports = { name: 'gif', description: 'Send a GIF', alias: ['jpg', 'png', 'gifv', 'webm', 'mp4', 'wav', 'wmv', 'webp', 'mp3', 'flac', 'ogg', 'avi', 'mov', 'mpg', 'mpeg', 'mkv', 'flv', 'bmp', 'tiff', 'tif', 'svg', 'ico'], usage: '.gif', async execute(message, commandData) { // if (message.deletable) message.delete(); const client = message.client; if (!client.gifs.has(commandData.args.toLowerCase())) { if (process.env.isDev) console.log('https://tenor.googleapis.com/v2/search?' + `&q=${commandData.args}` + `&key=${process.env.tenorAPIKey}` + '&limit=1&contentfilter=off'); tenor.search(commandData.args, "1").then(res => { if (res[0] == undefined) { message.reply('Sorry I was unable to find a GIF of ' + commandData.args); return; }; commandData.embed_url = res[0].mediaUrl; // message.reply(fn.embeds.gif(commandData)); // message.channel.send(`> ${commandData.author} - ${commandData.args}.gif`); // message.channel.send(commandData.embed_url); message.reply(commandData.embed_url); }).catch(err => console.error(err)); } else { // message.reply(commandData.args + ' requested by ' + message.author.username + '\n' + client.gifs.get(commandData.args).embed_url); const gifData = client.gifs.get(commandData.args.toLowerCase()); // message.reply(fn.embeds.gif(commandData)); // message.channel.send(`> ${commandData.author} - ${commandData.args}.gif`); // message.channel.send(commandData.embed_url); message.reply(gifData.url); } } }