From d266ac622ce5ce9d1b78ff13b80255989d0d3d14 Mon Sep 17 00:00:00 2001 From: ethanf Date: Wed, 29 Nov 2023 01:59:15 -0600 Subject: [PATCH] feat: class role commands --- index.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- register.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 21f188a..8bbcf0e 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,11 @@ const { } = require("./config.json"); const client = new Client({ - intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates], + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMembers, + GatewayIntentBits.GuildVoiceStates + ], }); client.on("ready", () => { @@ -21,6 +25,48 @@ client.on("interactionCreate", async (interaction) => { const command = interaction.commandName; if (!interaction.isChatInputCommand()) return; + if ( + command === "scout" || + command === "soldier" || + command === "pyro" || + command === "demoman" || + command === "demo" || + command === "heavy" || + command === "engineer" || + command === "engi" || + command === "medic" || + command === "sniper" || + command === "spy" + ) { + await interaction.deferReply(); + + // get voice channel + 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'!"); + + // 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 = "¯\\_(ツ)_/¯"; + + // respond + return await interaction.editReply({ + content: str, + }); + } + if (interaction.channelId !== COMMAND_CHANNEL_ID) { await interaction.reply({ content: "wrong channel, or you lack the required permissions", @@ -85,7 +131,7 @@ client.on("interactionCreate", async (interaction) => { return await interaction.editReply({ content: `moved members in ${ command === "resetteams" ? "blu" : "addup, blu," - } and red.${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`, + } and red${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`, }); } } diff --git a/register.js b/register.js index 193fa22..62b97b1 100644 --- a/register.js +++ b/register.js @@ -25,7 +25,51 @@ const commands = [ { name: "fk", description: "Pulls addup channel members into fk channel and lists them", - } + }, + { + name: "scout", + description: "Lists picking channel members with scout role", + }, + { + name: "soldier", + description: "Lists picking channel members with soldier role", + }, + { + name: "pyro", + description: "Lists picking channel members with pyro role", + }, + { + name: "demo", + description: "Lists picking channel members with demo role", + }, + { + name: "demoman", + description: "Alias of /demo", + }, + { + name: "heavy", + description: "Lists picking channel members with heavy role", + }, + { + name: "engineer", + description: "Lists picking channel members with engineer role", + }, + { + name: "engi", + description: "Alias of /engineer", + }, + { + name: "medic", + description: "Lists picking channel members with medic role", + }, + { + name: "sniper", + description: "Lists picking channel members with sniper role", + }, + { + name: "spy", + description: "Lists picking channel members with spy role", + }, ]; const rest = new REST({ version: "10" }).setToken(TOKEN);