const { SlashCommandBuilder, ChatInputCommandInteraction, EmbedBuilder } = require('discord.js'); const { Alliances } = require('../../index.js'); const generateChoices = (start, end) => { const choices = []; for (let i = start; i <= end; i++) { choices.push({ name: i.toString(), value: i }); } return choices; }; module.exports = { data: new SlashCommandBuilder() .setName('add-alliance') .setDescription('Add your alliance to the database') .addStringOption(option => option.setName('name').setDescription('Alliance name').setRequired(true)) .addStringOption(option => option.setName('tag').setDescription('Alliance tag e.g. [0 my]').setRequired(true)) .addStringOption(option => option.setName('description').setDescription('Alliance description').setRequired(true)) .addIntegerOption(option => option.setName('rating').setDescription('Total alliance rating').setRequired(true)) .addIntegerOption(option => option.setName('war-rating').setDescription('Alliance war rating').setRequired(true)) .addIntegerOption(option => option.setName('prestige').setDescription('Alliance prestige').setRequired(true)) .addStringOption(option => option.setName('war-rank').setDescription('Alliance war rank last season').setRequired(true).addChoices( { name: 'Participation', value: 'Participation' }, { name: 'Stone 3', value: 'Stone 3' }, { name: 'Stone 2', value: 'Stone 2' }, { name: 'Stone 1', value: 'Stone 1' }, { name: 'Bronze 3', value: 'Bronze 3' }, { name: 'Bronze 2', value: 'Bronze 2' }, { name: 'Bronze 1', value: 'Bronze 1' }, { name: 'Silver 3', value: 'Silver 3' }, { name: 'Silver 2', value: 'Silver 2' }, { name: 'Silver 1', value: 'Silver 1' }, { name: 'Gold 3', value: 'Gold 3' }, { name: 'Gold 2', value: 'Gold 2' }, { name: 'Gold 1', value: 'Gold 1' }, { name: 'Platinum 4', value: 'Platinum 4' }, { name: 'Platinum 3', value: 'Platinum 3' }, { name: 'Platinum 2', value: 'Platinum 2' }, { name: 'Platinum 1', value: 'Platinum 1' }, { name: 'Master', value: 'Master' }, )) .addIntegerOption(option => option.setName('aq-battlegroup-1').setDescription('Alliance quest map for battlegroup 1').setRequired(true).addChoices(...generateChoices(0, 8))) .addIntegerOption(option => option.setName('aq-battlegroup-2').setDescription('Alliance quest map for battlegroup 2').setRequired(true).addChoices(...generateChoices(0, 8))) .addIntegerOption(option => option.setName('aq-battlegroup-3').setDescription('Alliance quest map for battlegroup 3').setRequired(true).addChoices(...generateChoices(0, 8))) .addStringOption(option => option.setName('leader').setDescription('Alliance leader').setRequired(true)) .setDMPermission(false), /** * * @param {ChatInputCommandInteraction} interaction */ async execute(interaction) { const name = interaction.options.getString('name'); const tag = interaction.options.getString('tag'); const description = interaction.options.getString('description'); const rating = interaction.options.getInteger('rating').toString(); const warRating = interaction.options.getInteger('war-rating').toString(); const prestige = interaction.options.getInteger('prestige').toString(); const warRank = interaction.options.getString('war-rank'); const aqOne = interaction.options.getInteger('aq-battlegroup-1').toString(); const aqTwo = interaction.options.getInteger('aq-battlegroup-2').toString(); const aqThree = interaction.options.getInteger('aq-battlegroup-3').toString(); const leader = interaction.options.getString('leader'); try { const ally = await Alliances.create( { name: name, tag: tag, description: description, rating: rating, war_rating: warRating, prestige: prestige, leader: leader, war_rank: warRank, aq_maps: `${aqOne}x${aqTwo}x${aqThree}` } ); return interaction.reply(`${ally.name} was successfully added to the database!`); } catch (error) { if (error.name === 'SequelizeUniqueConstraintError') return interaction.reply('That alliance already exists in the database'); return interaction.reply(`There was an error adding the alliance to the database, please contact <@${414405296312549378}>`); } }, };