From e9b206afff9316f8a7f65b3260a7fec83b0c6370 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Wed, 12 Jun 2024 00:03:58 +0000 Subject: [PATCH 1/8] scary --- config.json.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json.template b/config.json.template index 97876e1..d0945de 100644 --- a/config.json.template +++ b/config.json.template @@ -1,5 +1,6 @@ { "debug": 0, + "voice_enabled": true, "priorityColors": { "1": "#00AFFF", "2": "#00FF00", @@ -26,7 +27,6 @@ "username": "YOUR_USERNAME", "password": "YOUR_PASSWORD" }, - "voice_enabled": true, "uptime-kuma": { "enabled": false, -- 2.43.5 From 0a9376d4d7f573fa32c1dd909b6c22e9eb70e126 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Wed, 12 Jun 2024 02:29:12 +0000 Subject: [PATCH 2/8] 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; -- 2.43.5 From e5d9a687d4b7ad031fa8538c630fcfe147503ce1 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Wed, 12 Jun 2024 03:11:58 +0000 Subject: [PATCH 3/8] NWR Play Works --- index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6a81503..7e4a67a 100644 --- a/index.js +++ b/index.js @@ -632,6 +632,7 @@ discord.on('ready', async () => { }, { "name": "play", + "type": 1, "description": "Play a stream", "options": [ { @@ -644,11 +645,12 @@ discord.on('ready', async () => { }, { "name": "nwrplay", - "description": "Play a NWR stream", + "description": "Nwr stream", + "type": 1, "options": [ { - "name": "Callsign", - "description": "Enter a Valid NWR Callsign", + "name": "callsign", + "description": "The URL of the stream to play", "type": 3, "required": true } @@ -1037,6 +1039,7 @@ 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 URL url = interaction.options.getString("url"); + const data2 = JSON.parse(nwrstreams.readFileSync('./data/nwrstreams.json', 'utf8')); // Sanity check URL for funny stuff if (!url.match(/https?:\/\/[^\s]+/)) return interaction.reply({ content: "Invalid URL", ephemeral: true }); // Get the channel @@ -1056,7 +1059,7 @@ discord.on("interactionCreate", async (interaction) => { // Get the callsign const callsign = interaction.options.getString("callsign"); // Read the JSON file - const data = JSON.parse(nwrstreams.readFileSync('./data/nwrstreams.json', 'utf8')); + const data = nwrstreams // Get the URL associated with the callsign const url = data.callsigns[callsign]; // Sanity check URL for funny stuff -- 2.43.5 From 081b4ef261044dcfa3ef709ed536759c803cbc0d Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 11 Jun 2024 22:01:15 -0600 Subject: [PATCH 4/8] 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 -- 2.43.5 From ec176a87c2795bdf5308f832afeef568f400f388 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Wed, 12 Jun 2024 21:28:36 +0000 Subject: [PATCH 5/8] Somewhat of a fix still issues where some commands dont show in certian servers. --- data/nwrstreams.json | 11 ++++++++--- index.js | 32 +++++++++++++++++++------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/data/nwrstreams.json b/data/nwrstreams.json index cccb16b..173c812 100644 --- a/data/nwrstreams.json +++ b/data/nwrstreams.json @@ -1,7 +1,12 @@ { "callsigns": { - "WXL46": "https://icecast.sirenarchive.xyz/NWR/WXL46", - "KZZ30": "https://icecast.sirenarchive.xyz/NWR/KZZ30", - "KGRX": "https://icecast.sirenarchive.xyz/AAC/KGRX" + "WXL46": "http://192.168.2.3:8000/NWR/WXL46", + "KZZ30": "http://192.168.2.3:8000/NWR/KZZ30", + "KZZ57": "https://wxradio.org/IL-Rockford-KZZ57", + "KXI41": "https://wxradio.org/IL-CrystalLake-KXI41", + "KHB34": "https://wxradio.org/FL-Miami-KHB34", + "WNG663": "https://wxradio.org/FL-Princeton-WNG663", + "KEC80": "https://wxradio.org/GA-Atlanta-KEC80", + "KGRX_NOT_NWR": "http://192.168.2.3:8000/AAC/KGRX" } } \ No newline at end of file diff --git a/index.js b/index.js index eb53512..7d327e9 100644 --- a/index.js +++ b/index.js @@ -1047,16 +1047,15 @@ discord.on("interactionCreate", async (interaction) => { case "play": // Play generic stream 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"); - const data2 = JSON.parse(nwrstreams.readFileSync('./data/nwrstreams.json', 'utf8')); - // Sanity check URL for funny stuff - if (!url.match(/https?:\/\/[^\s]+/)) return interaction.reply({ content: "Invalid URL", ephemeral: true }); + // Use local variables & Get the URL + const interactionUrl = interaction.options.getString("url"); // Get the channel - channel = interaction.member.voice.channel; + const channel = interaction.member.voice.channel; + // Check if in 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) + const st = JoinChannel(channel, interactionUrl, .1, interaction); + if (st) { interaction.reply({ content: "Joined, trying to start playing.", ephemeral: true }); } else { @@ -1066,25 +1065,32 @@ discord.on("interactionCreate", async (interaction) => { 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 = nwrstreams + 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 }); + + // Get the voice channel + const voiceChannel = interaction.member.voice.channel; // Use a unique variable name + if (!voiceChannel) 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) { + const streamStatus = JoinChannel(voiceChannel, url, .1, interaction); // Use a unique variable name + if (streamStatus) { 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 }); -- 2.43.5 From 0f495feb557570f2f6531a34934705c62c3185bb Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 18 Jun 2024 00:09:40 -0600 Subject: [PATCH 6/8] Fix anthony's code :P --- data/nwrstreams.json | 22 +++++++++++----------- index.js | 25 +++++++++---------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/data/nwrstreams.json b/data/nwrstreams.json index 173c812..af00e55 100644 --- a/data/nwrstreams.json +++ b/data/nwrstreams.json @@ -1,12 +1,12 @@ { - "callsigns": { - "WXL46": "http://192.168.2.3:8000/NWR/WXL46", - "KZZ30": "http://192.168.2.3:8000/NWR/KZZ30", - "KZZ57": "https://wxradio.org/IL-Rockford-KZZ57", - "KXI41": "https://wxradio.org/IL-CrystalLake-KXI41", - "KHB34": "https://wxradio.org/FL-Miami-KHB34", - "WNG663": "https://wxradio.org/FL-Princeton-WNG663", - "KEC80": "https://wxradio.org/GA-Atlanta-KEC80", - "KGRX_NOT_NWR": "http://192.168.2.3:8000/AAC/KGRX" - } - } \ No newline at end of file + "callsigns": { + "WXL46": "https://icecast.sirenarchive.xyz/NWR/WXL46", + "KZZ30": "https://icecast.sirenarchive.xyz/NWR/KZZ30", + "KZZ57": "https://wxradio.org/IL-Rockford-KZZ57", + "KXI41": "https://wxradio.org/IL-CrystalLake-KXI41", + "KHB34": "https://wxradio.org/FL-Miami-KHB34", + "WNG663": "https://wxradio.org/FL-Princeton-WNG663", + "KEC80": "https://wxradio.org/GA-Atlanta-KEC80", + "KGRX_NOT_NWR": "https://icecast.sirenarchive.xyz/AAC/KGRX" + } +} \ No newline at end of file diff --git a/index.js b/index.js index 7d327e9..a6191a5 100644 --- a/index.js +++ b/index.js @@ -1034,7 +1034,7 @@ discord.on("interactionCreate", async (interaction) => { // Get the stream URL url = `https://${config.broadcastify.username}:${config.broadcastify.password}@audio.broadcastify.com/${streamID}.mp3`; // Get the channel - channel = interaction.member.voice.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 res = JoinChannel(channel, url, .1, interaction) @@ -1048,13 +1048,13 @@ discord.on("interactionCreate", async (interaction) => { case "play": // Play generic stream if (!interaction.inGuild()) return interaction.reply({ content: "This command can only be used in a guild", ephemeral: true }); // Use local variables & Get the URL - const interactionUrl = interaction.options.getString("url"); + interactionUrl = interaction.options.getString("url"); // Get the channel - const channel = interaction.member.voice.channel; + channel = interaction.member.voice?.channel; // Check if in channel if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true }); // Join the channel and play the stream - const st = JoinChannel(channel, interactionUrl, .1, interaction); + st = JoinChannel(channel, interactionUrl, .1, interaction); if (st) { interaction.reply({ content: "Joined, trying to start playing.", ephemeral: true }); @@ -1068,22 +1068,15 @@ discord.on("interactionCreate", async (interaction) => { // 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 }); - + const url = nwrstreams.callsigns[callsign]; + // Get the voice channel - const voiceChannel = interaction.member.voice.channel; // Use a unique variable name - if (!voiceChannel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true }); + channel = interaction.member.voice?.channel; // Use a unique variable name + if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true }); // Join the channel and play the stream - const streamStatus = JoinChannel(voiceChannel, url, .1, interaction); // Use a unique variable name + const streamStatus = JoinChannel(channel, url, .1, interaction); // Use a unique variable name if (streamStatus) { interaction.reply({ content: "Joined, trying to start playing.", ephemeral: true }); } else { -- 2.43.5 From a8aebe683cddd632e1695ade50ec67f158218480 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Tue, 18 Jun 2024 06:45:51 +0000 Subject: [PATCH 7/8] Error With Chris PFP not showing up when not in the discord server. --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index a6191a5..328db2f 100644 --- a/index.js +++ b/index.js @@ -895,7 +895,7 @@ discord.on("interactionCreate", async (interaction) => { const embed = { title: "About Me!", thumbnail: { - url: discord.user.avatarURL() + url: discord.user?.avatarURL() }, description: `I listen to all the weather.im rooms and send them to discord channels.\nI am open source, you can find my code [here!](https://github.com/ChrisChrome/iembot-2.0)\n\nThis bot is not affiliated with NOAA, the National Weather Service, or the IEM project.`, fields: [ @@ -926,7 +926,7 @@ discord.on("interactionCreate", async (interaction) => { color: 0x00ff00, footer: { text: "Made by @chrischrome with <3", - icon_url: discord.users.cache.get("289884287765839882").avatarURL() + icon_url: "https://cdn.discordapp.com/avatars/289884287765839882/2b00063a92adfe08f325353eee29e348.webp?size=1024&format=webp&width=0&height=5" } } interaction.reply({ embeds: [embed] }); @@ -1206,9 +1206,9 @@ discord.on("interactionCreate", async (interaction) => { }); break; case "alertmap": - url = "https://forecast.weather.gov/wwamap/png/US.png" + const alertmapurl = "https://forecast.weather.gov/wwamap/png/US.png" await interaction.deferReply(); - fetch(url).then((res) => { + fetch(alertmapurl).then((res) => { if (res.status !== 200) { interaction.editReply({ content: "Failed to get alert map", ephemeral: true }); return; @@ -1218,7 +1218,7 @@ discord.on("interactionCreate", async (interaction) => { embeds: [{ title: `Alert Map`, image: { - url: `attachment://alerts.png` + alertmapurl: `attachment://alerts.png` }, color: 0x00ff00 }], -- 2.43.5 From 64f4bc676e98d3bd1753a8279c48d5a99a362412 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Tue, 18 Jun 2024 06:47:07 +0000 Subject: [PATCH 8/8] Fix URL --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 328db2f..ad886f9 100644 --- a/index.js +++ b/index.js @@ -926,7 +926,7 @@ discord.on("interactionCreate", async (interaction) => { color: 0x00ff00, footer: { text: "Made by @chrischrome with <3", - icon_url: "https://cdn.discordapp.com/avatars/289884287765839882/2b00063a92adfe08f325353eee29e348.webp?size=1024&format=webp&width=0&height=5" + icon_url: "https://cdn.discordapp.com/avatars/289884287765839882/2b00063a92adfe08f325353eee29e348.webp?size=1024&format=webp&width=0&height=256" } } interaction.reply({ embeds: [embed] }); -- 2.43.5