diff --git a/commands/factions.js b/commands/factions.js index 30be8d8..ae0371e 100644 --- a/commands/factions.js +++ b/commands/factions.js @@ -1,4 +1,5 @@ const { EmbedBuilder } = require('discord.js'); +const { Armbands } = require('../config/armbandsdb.js'); module.exports = { name: "factions", @@ -10,7 +11,13 @@ module.exports = { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], }, - options: [], + options: [{ + name: "faction_role", + description: "View a specific faction's armband by role", + value: "faction_role", + type: 8, + required: false, + }], SlashCommand: { /** * @@ -23,24 +30,56 @@ module.exports = { if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) }); - let factions = new EmbedBuilder() - .setColor(client.config.Colors.Default) - .setTitle('Factions & Armbands') + // Return list of factions and their armband. + if (!args) { + + let factions = new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setTitle('Factions & Armbands') + + let description = ''; - let description = ''; - - if (GuildDB.usedArmbands.length == 0) { - description = '> There are no factions that have claimed armbands.'; - } else { - for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) { - if (description == "") description += `> <@&${factionID}> - ${data.armband}`; - else description += `\n> <@&${factionID}> - *${data.armband}*`; + if (GuildDB.usedArmbands.length == 0) { + description = '> There are no factions that have claimed armbands.'; + } else { + for (const [factionID, data] of Object.entries(GuildDB.factionArmbands)) { + if (description == "") description += `> <@&${factionID}> - ${data.armband}`; + else description += `\n> <@&${factionID}> - *${data.armband}*`; + } + } + + factions.setDescription(description); + + return interaction.send({ embeds: [factions] }); + } + + // Else return specific faction and their armband. + if (!GuildDB.factionArmbands[args[0].value]) { + return interaction.send({ + embeds: [ + new EmbedBuilder() + .setColor(client.config.Colors.Yellow) + .setDescription(`**Notice:**\n> The faction <@&${args[0].value}> has not claimed an armband.`) + ], + flags: (1 << 6) + }); + } + + let armbandURL; + + for (let i = 0; i < Armbands.length; i++) { + if (Armbands[i].name == GuildDB.factionArmbands[args[0].value].armband) { + armbandURL = Armbands[i].url; + break; } } - factions.setDescription(description); + const faction = new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setDescription(`> Faction <@&${GuildDB.factionArmbands[args[0].value].faction}> - ***${GuildDB.factionArmbands[args[0].value].armband}***`) + .setImage(armbandURL); - return interaction.send({ embeds: [factions] }); + return interaction.send({ embeds: [faction] }); }, }, Interactions: {} diff --git a/package.json b/package.json index 9342591..c008b18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayz-armbands", - "version": "4.6.2", + "version": "4.7.0", "description": "A Discord Bot to handle DayZ server flags and armbands for in game factions.", "main": "index.js", "nodemonConfig": {