Autocomplete nwrplay

This commit is contained in:
Christopher Cookman 2024-06-11 22:01:15 -06:00
parent e5d9a687d4
commit 081b4ef261
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -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