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, moveMessage: moveMessage, }; 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(); }); } //YouTube not working, file exceeds upload limit function moveMessage(message, channelId) { message.react('🐮'); const replyChannel = message.channel; const msgToMooveId = message.reference.messageId; const mentionedChannelId = channelId.substring(2, channelId.length - 1); replyChannel.messages.fetch(msgToMooveId).then(msg => { if (msg.attachments.size > 0) { const newMsgAttachments = []; const allAttachments = msg.attachments.values(); for (let i = 0; i < msg.attachments.size; i++) { const currAttachment = allAttachments.next().value; newMsgAttachments.push(new MessageAttachment(currAttachment.url)); } if (msg.embeds.length > 0) { client.channels.cache.get(mentionedChannelId) .send({ content: `Sent by ${msg.author}\nmooved ${message.author}`, embeds: msg.embeds, files: newMsgAttachments }); } else { client.channels.cache.get(mentionedChannelId) .send({ content: `Sent by ${msg.author}\nmooved ${message.author}`, files: newMsgAttachments }); } } else { const embed = new Discord.MessageEmbed() .setColor(help.randomColor()) .addField('MOO', `Sent by ${msg.author}\nmooved ${message.author}`); if (msg.content.includes('http')) { const file = new MessageAttachment(msg.content); client.channels.cache.get(mentionedChannelId).send({ embeds: [embed], files: [file] }); } else { embed.addField('Message:', msg.content); client.channels.cache.get(mentionedChannelId).send({ embeds: [embed] }); } } setTimeout(() => msg.delete(), 3000); }); setTimeout(() => message.delete(), 3000); }