From 081b4ef261044dcfa3ef709ed536759c803cbc0d Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 11 Jun 2024 22:01:15 -0600 Subject: [PATCH] Autocomplete nwrplay --- index.js | 68 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/index.js b/index.js index 7e4a67a..eb53512 100644 --- a/index.js +++ b/index.js @@ -643,19 +643,6 @@ discord.on('ready', async () => { } ] }, - { - "name": "nwrplay", - "description": "Nwr stream", - "type": 1, - "options": [ - { - "name": "callsign", - "description": "The URL of the stream to play", - "type": 3, - "required": true - } - ] - }, { "name": "pause", "description": "Pause/Unpause the current stream", @@ -674,10 +661,33 @@ discord.on('ready', async () => { ] } ) + + nwrplayCommand = { + "name": "nwrplay", + "description": "Nwr stream", + "type": 1, + "options": [ + { + "name": "callsign", + "description": "The URL of the stream to play", + "type": 3, + "required": true, + "choices": [] + } + ] + } + for (const key in nwrstreams.callsigns) { + nwrplayCommand.options[0].choices.push({ + "name": key, + "value": key + }); + } + commands.push(nwrplayCommand); } await (async () => { try { //Global + if(config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} Registering global commands: ${JSON.stringify(commands, null, 2)}`); await rest.put(Routes.applicationCommands(discord.user.id), { body: commands }) } catch (error) { console.error(error); @@ -1058,22 +1068,22 @@ discord.on("interactionCreate", async (interaction) => { if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); // Get the callsign const callsign = interaction.options.getString("callsign"); - // Read the JSON file - const data = nwrstreams - // Get the URL associated with the callsign - const url = data.callsigns[callsign]; - // Sanity check URL for funny stuff - if (!url.match(/https?:\/\/[^\s]+/)) return interaction.reply({ content: "Invalid URL", ephemeral: true }); - // Get the channel - channel = interaction.member.voice.channel; - if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true }); - // Join the channel and play the stream - st = JoinChannel(channel, url, .1, interaction) - if (st) { - interaction.reply({ content: "Joined, trying to start playing.", ephemeral: true }); - } else { - interaction.reply({ content: `Failed to play stream`, ephemeral: true }); - } + // Read the JSON file + const data = nwrstreams + // Get the URL associated with the callsign + const url = data.callsigns[callsign]; + // Sanity check URL for funny stuff + if (!url.match(/https?:\/\/[^\s]+/)) return interaction.reply({ content: "Invalid URL", ephemeral: true }); + // Get the channel + channel = interaction.member.voice.channel; + if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true }); + // Join the channel and play the stream + st = JoinChannel(channel, url, .1, interaction) + if (st) { + interaction.reply({ content: "Joined, trying to start playing.", ephemeral: true }); + } else { + interaction.reply({ content: `Failed to play stream`, ephemeral: true }); + } break; case "leave": // Leave Channel