From ea484648961ba968854b0d772a977542e3f491be Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 30 Aug 2023 20:24:29 -0700 Subject: [PATCH] feature/admin-claim-armband-for-faction --- commands/admin.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/commands/admin.js b/commands/admin.js index 02644f4..65ed876 100644 --- a/commands/admin.js +++ b/commands/admin.js @@ -43,6 +43,18 @@ module.exports = { type: 6, required: true, }] + }, { + name: "claim-armband", + description: "Claim an armband for a faction", + value: "claim-armband", + type: 1, + options: [{ + name: "faction_role", + description: "Claim an armband for this faction role.", + value: "faction_role", + type: 8, + required: true, + }] }, { name: "bounty-clear", description: "clear a bounty off a player", @@ -195,6 +207,68 @@ module.exports = { return interaction.send({ embeds: [warnGTOverwrite], components: [opt] }); + } else if (args[0].name == 'claim-armband') { + + // Handle invalid roles + if (des) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Notice:**\n> This role has been configured to be excluded to claim an armband.')], flags: (1 << 6) }); + + // If this faction has an existing record in the db + if (GuildDB.factionArmbands[args[0].value]) { + const warnArmbadChange = new EmbedBuilder() + .setColor(client.config.Colors.Yellow) + .setDescription(`**Notice:**\n> The faction <@&${args[0].options[0].value}> already has an armband selected. Are you sure you would like to change this?`) + + const opt = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId(`ChangeArmband-yes-${args[0].options[0].value}-${interaction.member.user.id}`) + .setLabel("Yes") + .setStyle(ButtonStyle.Success), + new ButtonBuilder() + .setCustomId(`ChangeArmband-no-${args[0].options[0].value}-${interaction.member.user.id}`) + .setLabel("No") + .setStyle(ButtonStyle.Secondary) + ) + + return interaction.send({ embeds: [warnArmbadChange], components: [opt] }); + } + + // Any interaction for 'claim-armband' can be handled in + // 'commands/claim.js' Interaction handlers and does not require its own code in this file. + + let available = new SelectMenuBuilder() + .setCustomId(`Claim-${args[0].options[0].value}-1-${interaction.member.user.id}`) + .setPlaceholder('Select an armband from list 1 to claim') + + let availableNext = new SelectMenuBuilder() + .setCustomId(`Claim-${args[0].options[0].value}-2-${interaction.member.user.id}`) + .setPlaceholder('Select an armband from list 2 to claim') + + let tracker = 0; + for (let i = 0; i < Armbands.length; i++) { + if (!GuildDB.usedArmbands.includes(Armbands[i].name)) { + tracker++; + data = { + label: Armbands[i].name, + description: 'Select this armband', + value: Armbands[i].name, + } + if (tracker > 25) availableNext.addOptions(data); + else available.addOptions(data); + } + } + + let compList = [] + let opt = new ActionRowBuilder().addComponents(available); + compList.push(opt) + let opt2 = undefined; + if (tracker > 25) { + opt2 = new ActionRowBuilder().addComponents(availableNext); + compList.push(opt2); + } + + return interaction.send({ components: compList }); + } else if (args[0].name == 'bounty-clear') { let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == args[0].options[0].value); diff --git a/package.json b/package.json index c6f34a4..7decd0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayz-armbands", - "version": "8.7.0", + "version": "8.8.0", "description": "A General Purpose Discord Bot for DayZ Servers.", "main": "index.js", "nodemonConfig": {