nodbot/dot-commands/gif.js

54 lines
2.4 KiB
JavaScript
Raw Normal View History

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();
2021-09-22 17:15:31 +00:00
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',
2024-09-26 13:07:26 +00:00
alias: ['jpg', 'png', 'gifv', 'webm', 'mp4', 'wav', 'wmv', 'webp', 'mp3', 'flac', 'ogg', 'avi', 'mov', 'mpg', 'mpeg', 'mkv', 'flv', 'bmp', 'tiff', 'tif', 'svg', 'ico'],
2021-09-22 17:15:31 +00:00
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.toLowerCase())) {
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');
const q = await axios.get(
'https://tenor.googleapis.com/v2/search?' +
`&q=${commandData.args}` +
`&key=${process.env.tenorAPIKey}` +
'&limit=1' +
`&contentfilter=off`
).then(res => {
if (process.env.isDev) console.log(res.data.results);
if (res.data.results[0] == undefined) {
2021-09-22 17:15:31 +00:00
message.reply('Sorry I was unable to find a GIF of ' + commandData.args);
return;
};
2022-12-02 18:46:26 +00:00
commandData.embed_url = res.data.results[0].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));
2022-12-02 18:46:26 +00:00
// tenor.Search.Query(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].media[0].gif.url;
// // 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));
2021-09-22 17:15:31 +00:00
} 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());
2021-09-22 17:15:31 +00:00
// 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(gifData.url);
2021-09-22 17:15:31 +00:00
}
}
}