2023-02-28 22:48:15 +00:00
|
|
|
const { SlashCommandBuilder } = require('discord.js');
|
2023-03-30 09:07:37 +00:00
|
|
|
const gifEmbed = require('../gifs.js');
|
2022-02-12 13:04:18 +00:00
|
|
|
const gifAmount = 50;
|
|
|
|
require('dotenv').config();
|
|
|
|
|
|
|
|
|
|
|
|
async function getGifEmbed(options) {
|
|
|
|
let rating = 'low';
|
|
|
|
try {
|
|
|
|
if (options.getBoolean('r-rated')) {
|
|
|
|
rating = 'off';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
rating = 'low';
|
|
|
|
}
|
|
|
|
|
|
|
|
let search;
|
|
|
|
try {
|
|
|
|
search = options.getString('what').trim();
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
const gifs = `https://g.tenor.com/v1/random?key=${process.env.TENOR}&limit=${gifAmount}&contentfilter=${rating}`;
|
2023-03-30 09:07:37 +00:00
|
|
|
return gifEmbed.getGifEmbed(gifs, gifAmount);
|
2022-02-12 13:04:18 +00:00
|
|
|
}
|
2023-02-28 22:48:15 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
const searchSplits = search.split(/[ ]+/);
|
|
|
|
const searchKey = searchSplits.join('-');
|
2023-02-28 22:48:15 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
const gifs = `https://g.tenor.com/v1/search?q=${searchKey}&key=${process.env.TENOR}&limit=${gifAmount}&contentfilter=${rating}`;
|
2023-03-30 09:07:37 +00:00
|
|
|
return gifEmbed.getGifEmbed(gifs, gifAmount);
|
2023-02-25 12:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('gif')
|
|
|
|
.setDescription('Sends gif')
|
|
|
|
.addStringOption(option =>
|
|
|
|
option.setName('what')
|
|
|
|
.setDescription('What should I search for? (If this is empty I will give you something random!)'))
|
|
|
|
.addBooleanOption(option => option.setName('r-rated').setDescription('Should the gif be R-rated')),
|
|
|
|
async execute(interaction) {
|
|
|
|
const embed = await getGifEmbed(interaction.options);
|
|
|
|
await interaction.reply({ embeds: [embed] });
|
|
|
|
},
|
|
|
|
};
|