nodbot/dot-commands/gif.js
Skylar Grant c342f4741a
All checks were successful
NodBot PE Dockerization / build (push) Successful in 1m7s
Remove TenorJS completely
2026-09-21 20:32:06 -04:00

55 lines
2.3 KiB
JavaScript

const fn = require('../functions');
const axios = require('axios');
const dotenv = require('dotenv').config();
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 name or Search Query>.gif',
async execute(message, commandData) {
// if (message.deletable) message.delete();
const client = message.client;
if (!client.gifs.has(commandData.args.toLowerCase())) {
// TODO: Implement proper logging
if (process.env.isDev) console.log('https://api.giphy.com/v2/search?' + `&q=${commandData.args}` + `&key=${process.env.giphyAPIKey}` + '&limit=1&contentfilter=off');
const q = await axios.get(
'https://api.giphy.com/v2/search?' +
`&q=${commandData.args}` +
`&key=${process.env.giphyAPIKey}` +
'&limit=1' +
`&contentfilter=off`
).then(async (res) => {
if (process.env.isDev) console.log(res.data.results);
if (res.data.results[0] == undefined) {
message.reply('Sorry I was unable to find a GIF of ' + commandData.args);
return;
};
commandData.embed_url = res.data.results[0].url;
// Handle when the invoking message is a reply to someone else
if (message.reference) {
// Fetch the referenced message from the channels' MessageManager
await message.channel.messages.fetch(message.reference.messageId).then(async (refMsg) => {
// Send the reply to the referenced message
await refMsg.reply(commandData.embed_url);
}).catch(async (e) => {
// Failed fetching the message from the channel, fallback to regular send
console.error(e);
await message.reply(commandData.embed_url);
});
} else {
await 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);
}
}
}