From 0a9376d4d7f573fa32c1dd909b6c22e9eb70e126 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Wed, 12 Jun 2024 02:29:12 +0000 Subject: [PATCH] Trial For NWR Streams with own command. --- data/nwrstreams.json | 7 +++++++ index.js | 46 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 data/nwrstreams.json diff --git a/data/nwrstreams.json b/data/nwrstreams.json new file mode 100644 index 0000000..cccb16b --- /dev/null +++ b/data/nwrstreams.json @@ -0,0 +1,7 @@ +{ + "callsigns": { + "WXL46": "https://icecast.sirenarchive.xyz/NWR/WXL46", + "KZZ30": "https://icecast.sirenarchive.xyz/NWR/KZZ30", + "KGRX": "https://icecast.sirenarchive.xyz/AAC/KGRX" + } + } \ No newline at end of file diff --git a/index.js b/index.js index 1dc6ce9..6a81503 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ const blacklist = require("./data/blacklist.json"); const events = require("./data/events.json"); const outlookURLs = require("./data/outlook.json"); const sattelites = require("./data/sattelites.json"); +const nwrstreams = require("./data/nwrstreams.json") const Jimp = require("jimp"); const { client, xml } = require("@xmpp/client"); const fetch = require("node-fetch"); @@ -30,6 +31,7 @@ const rest = new REST({ version: '10' }).setToken(config.discord.token); + // Setup SQlite DB const db = new sqlite3.Database("channels.db", (err) => { if (err) { @@ -640,6 +642,18 @@ discord.on('ready', async () => { } ] }, + { + "name": "nwrplay", + "description": "Play a NWR stream", + "options": [ + { + "name": "Callsign", + "description": "Enter a Valid NWR Callsign", + "type": 3, + "required": true + } + ] + }, { "name": "pause", "description": "Pause/Unpause the current stream", @@ -1000,7 +1014,7 @@ discord.on("interactionCreate", async (interaction) => { break; case "playbcfy": // Play broadcastify stream - if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); + if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); if (!config.broadcastify.enabled) return interaction.reply({ content: "Broadcastify is not enabled", ephemeral: true }); streamID = interaction.options.getString("id"); // Check if the stream ID is valid (up to 10 digit alphanumeric) @@ -1020,7 +1034,7 @@ discord.on("interactionCreate", async (interaction) => { break; case "play": // Play generic stream - if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); + if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); // Get the URL url = interaction.options.getString("url"); // Sanity check URL for funny stuff @@ -1037,7 +1051,29 @@ discord.on("interactionCreate", async (interaction) => { } break; - case "leave": // Leaves Channel + case "nwrplay": // Play NWR stream + 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 = JSON.parse(nwrstreams.readFileSync('./data/nwrstreams.json', 'utf8')); + // 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 if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); channel = interaction.member.voice.channel; if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true }); @@ -1050,7 +1086,7 @@ discord.on("interactionCreate", async (interaction) => { break; case "pause": // Pause/unpause stream - if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); + if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); channel = interaction.member.voice.channel; if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true }); res = toggleVoicePause(channel) @@ -1061,7 +1097,7 @@ discord.on("interactionCreate", async (interaction) => { } break; case "volume": // Set volume - if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); + if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); channel = interaction.member.voice.channel; if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true }); volume = interaction.options.getInteger("volume") / 100;