2021-09-22 17:15:31 +00:00
|
|
|
const fn = require('../functions');
|
2022-12-02 18:46:26 +00:00
|
|
|
const axios = require('axios');
|
|
|
|
const dotenv = require('dotenv').config();
|
2024-09-22 23:19:16 +00:00
|
|
|
const Tenor = require('tenorjs-v2');
|
2021-09-22 17:15:31 +00:00
|
|
|
|
2024-09-22 23:46:44 +00:00
|
|
|
const tenor = new Tenor(process.env.TENOR_API_KEY);
|
2022-12-02 17:55:05 +00:00
|
|
|
// 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
|
|
|
|
|
2021-09-22 17:15:31 +00:00
|
|
|
module.exports = {
|
|
|
|
name: 'gif',
|
|
|
|
description: 'Send a GIF',
|
|
|
|
usage: '<GIF name or Search Query>.gif',
|
2022-12-02 18:46:26 +00:00
|
|
|
async execute(message, commandData) {
|
2022-06-09 22:02:44 +00:00
|
|
|
// if (message.deletable) message.delete();
|
2021-09-22 17:15:31 +00:00
|
|
|
const client = message.client;
|
|
|
|
if (!client.gifs.has(commandData.args)) {
|
2022-12-02 18:46:26 +00:00
|
|
|
if (process.env.isDev) console.log('https://tenor.googleapis.com/v2/search?' + `&q=${commandData.args}` + `&key=${process.env.tenorAPIKey}` + '&limit=1&contentfilter=off');
|
2024-09-22 23:19:16 +00:00
|
|
|
tenor.search(commandData.args, "1").then(res => {
|
|
|
|
if (res[0] == undefined) {
|
2021-09-22 17:15:31 +00:00
|
|
|
message.reply('Sorry I was unable to find a GIF of ' + commandData.args);
|
|
|
|
return;
|
|
|
|
};
|
2024-09-22 23:19:16 +00:00
|
|
|
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);
|
2022-06-09 22:02:44 +00:00
|
|
|
message.reply(commandData.embed_url);
|
2021-09-22 17:15:31 +00:00
|
|
|
}).catch(err => console.error(err));
|
|
|
|
} else {
|
|
|
|
// message.reply(commandData.args + ' requested by ' + message.author.username + '\n' + client.gifs.get(commandData.args).embed_url);
|
|
|
|
commandData.embed_url = client.gifs.get(commandData.args).embed_url;
|
|
|
|
// message.reply(fn.embeds.gif(commandData));
|
2022-06-09 22:34:22 +00:00
|
|
|
// message.channel.send(`> ${commandData.author} - ${commandData.args}.gif`);
|
|
|
|
// message.channel.send(commandData.embed_url);
|
|
|
|
message.reply(commandData.embed_url);
|
2021-09-22 17:15:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|