From 04fad613b6826ed52ebe23ffe54fe152f014ca66 Mon Sep 17 00:00:00 2001 From: ethanf Date: Thu, 30 Nov 2023 18:10:22 -0600 Subject: [PATCH] feat: only picking or captains allowed to /class --- config.json | 5 +++-- index.js | 57 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/config.json b/config.json index 941e0c6..6ebe2b7 100644 --- a/config.json +++ b/config.json @@ -7,5 +7,6 @@ "PICKING_ID": "1175649967935856680", "BLU_ID": "1175649793943552010", "RED_ID": "1175649777648680971", - "FK_ID": "1176396207183106078" -} \ No newline at end of file + "FK_ID": "1176396207183106078", + "CAPTAIN_ID": "1178475124563919018" +} diff --git a/index.js b/index.js index 8bbcf0e..0b10cd0 100644 --- a/index.js +++ b/index.js @@ -7,13 +7,14 @@ const { BLU_ID, RED_ID, FK_ID, + CAPTAIN_ID, } = require("./config.json"); const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, - GatewayIntentBits.GuildVoiceStates + GatewayIntentBits.GuildVoiceStates, ], }); @@ -38,33 +39,49 @@ client.on("interactionCreate", async (interaction) => { command === "sniper" || command === "spy" ) { - await interaction.deferReply(); - - // get voice channel + // get voice channels const picking = interaction.guild.channels.cache.find( (channel) => channel.name === "picking" || channel.id === PICKING_ID ); if (!picking) return console.error("Can't find channel 'picking'!"); + const captain = interaction.guild.channels.cache.find( + (channel) => channel.name === "captains" || channel.id === CAPTAIN_ID + ); + if (!captain) return console.error("Can't find channel 'captains'!"); - // set role name - let roleName = command; - if (command === "demoman") roleName = "demo"; - if (command === "engi") roleName = "engineer"; + // make sure user is in picking or captain channel + if ( + !picking.members.has(interaction.user.id) && + !captain.members.has(interaction.user.id) + ) { + await interaction.reply({ + content: "must be in picking or captains channel to use this command", + ephemeral: true, + }); + return; + } else { + await interaction.deferReply(); - // check each member in picking channel for role - let str = "In picking:"; - for (const member of picking.members.values()) { - if (member.roles.cache.find((role) => role.name === roleName)) { - if (str !== "In picking:") str += ","; - str += " " + member.user.globalName; + // set role name + let roleName = command; + if (command === "demoman") roleName = "demo"; + if (command === "engi") roleName = "engineer"; + + // check each member in picking channel for role + let str = "In picking:"; + for (const member of picking.members.values()) { + if (member.roles.cache.find((role) => role.name === roleName)) { + if (str !== "In picking:") str += ","; + str += " " + member.user.globalName; + } } - } - if (str === "In picking:") str = "¯\\_(ツ)_/¯"; + if (str === "In picking:") str = "None found ¯\\_(ツ)_/¯"; - // respond - return await interaction.editReply({ - content: str, - }); + // respond + return await interaction.editReply({ + content: str, + }); + } } if (interaction.channelId !== COMMAND_CHANNEL_ID) {