MOOver.js/gifs.js

38 lines
1 KiB
JavaScript
Raw Normal View History

2023-02-25 12:42:21 +00:00
const axios = require('axios').default;
const { EmbedBuilder } = require('discord.js');
const help = require('./helpFunctions');
2023-02-25 12:42:21 +00:00
module.exports = ({
2023-02-25 12:42:21 +00:00
getGifs: getGifs,
getGifEmbed: getGifEmbed,
getGifWithMessage: getGifWithMessage,
});
2023-02-25 12:42:21 +00:00
async function getGifs(gifs) {
return new Promise((resolve) => {
resolve(axios.get(gifs));
});
}
async function getGifEmbed(gifQuery, gifAmount) {
const response = await getGifs(gifQuery);
const gif = response.data.results[help.RNG(gifAmount)].media[0].gif.url;
const gifEmbed = new EmbedBuilder()
2023-02-25 12:42:21 +00:00
.setImage(gif)
.setColor(help.randomColor());
2023-02-25 12:42:21 +00:00
return gifEmbed;
}
async function getGifWithMessage(interaction, gifQuery, gifAmount) {
const gifEmbed = await getGifEmbed(gifQuery, gifAmount);
const who = interaction.options.getMentionable('who');
if (who == null) {
return gifEmbed;
}
gifEmbed.setDescription(interaction.user.username
+ ` ${interaction.commandName}s ` + `${who}`);
return gifEmbed;
}