MOOver.js/helpFunctions.js
ZyLacx 45affbf744 FIxed mooving
YouTube links should be embedding now, attachments aswell, file upload limit no longer a problem
2022-09-06 19:53:19 +02:00

61 lines
1.5 KiB
JavaScript

const axios = require('axios').default;
const Discord = require('discord.js');
require('dotenv').config();
module.exports = {
randomColor: randomColor,
RNG: RNG,
getGifs: getGifs,
getGifEmbed: getGifEmbed,
getGifWithMessage: getGifWithMessage,
returnPromiseString: returnPromiseString,
};
function randomColor() {
let color = '#';
for (let i = 0; i < 6; i++) {
const random = Math.random();
const bit = (random * 16) | 0;
color += (bit).toString(16);
}
return color;
}
function RNG(max) {
return Math.floor(Math.random() * max);
}
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[RNG(gifAmount)].media[0].gif.url;
const gifEmbed = new Discord.MessageEmbed()
.setImage(gif)
.setColor(randomColor());
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;
}
async function returnPromiseString(guildMembers) {
return new Promise(() => {
guildMembers.fetch();
});
}