class.js (1904B)
1 const { EmbedBuilder } = require("discord.js"); 2 const model = require("../../models/weapons"); 3 const Attachments = require("../../util/Data/attachments.json"); 4 module.exports = { 5 name: "class", 6 description: "Generate random class in CODM", 7 category: "CODM", 8 run: async (client, interaction) => { 9 const data = async () => { 10 const d = await model.findOne({}); 11 const weapons = d.Primary[0][d.Categories.random()]; 12 return `${weapons.random()}`; 13 }; 14 const primary_weapon = await data(); 15 const primary = primary_weapon.replace(/[ -]/g, "_").replace(/\./g, ""); 16 const slots = shuffle(Object.keys(Attachments[primary][0])); 17 const slot_1 = slots.next().value, 18 slot_2 = slots.next().value, 19 slot_3 = slots.next().value, 20 slot_4 = slots.next().value, 21 slot_5 = slots.next().value; 22 const result = new EmbedBuilder() 23 .setColor(client.color) 24 .setTitle(`🎲 A Randomly Generated Class for ${primary_weapon} 🎲`) 25 .setDescription( 26 `**Attachments**\n**${getAttachment( 27 primary, 28 slot_1 29 )}**\n**${getAttachment(primary, slot_2)}**\n**${getAttachment( 30 primary, 31 slot_3 32 )}**\n**${getAttachment(primary, slot_4)}**\n**${getAttachment( 33 primary, 34 slot_5 35 )}**` 36 ) 37 .setURL(client.web) 38 .setFooter({ 39 text: `Made by ${client.author}`, 40 iconURL: client.user.displayAvatarURL({ dynamic: true }), 41 }) 42 .setTimestamp(); 43 interaction.followUp({ embeds: [result] }); 44 function* shuffle(array) { 45 let i = array.length; 46 while (i--) { 47 yield array.splice(Math.floor(Math.random() * (i + 1)), 1)[0]; 48 } 49 } 50 function getAttachment(gun, slot) { 51 const ca = Attachments[gun][0][slot]; 52 return ca.random(); 53 } 54 }, 55 };