From 42487f22b68fddd2b94b431c6cbb75a2d0979121 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 1 Jul 2024 02:05:12 -0600 Subject: [PATCH 01/44] Guh --- index.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index abdce84..db9f7c1 100644 --- a/index.js +++ b/index.js @@ -85,7 +85,17 @@ const getUniqueChannels = function () { if (err) { console.error(err.message); } - resolve(rows.length); + // Go through channels. and get number of unique guilds + const guilds = []; + rows.forEach((row) => { + const channel = discord.channels.cache.get(row.channelid); + if (!channel) return; + if (!guilds.includes(channel.guild.id)) { + guilds.push(channel.guild.id); + } + }); + + resolve({ channels: rows.length, guilds: guilds.length }); }); }); } @@ -891,7 +901,8 @@ discord.on("interactionCreate", async (interaction) => { channels = row.count await getUniqueChannels().then((unique) => { - uniques = unique; + uniques = unique.channels; + guilds = unique.guilds; }); discord.users.fetch("289884287765839882").then((chrisUser) => { const embed = { @@ -916,12 +927,12 @@ discord.on("interactionCreate", async (interaction) => { }, { name: "Subscribed Rooms", - value: channels.toLocaleString(), + value: `${channels.toLocaleString()}`, inline: true }, { name: "Unique Channels", - value: uniques.toLocaleString(), + value: `${uniques.toLocaleString()} in ${guilds} guilds.`, inline: true } ], -- 2.43.5 From 928cb4b958122a67c54faa080824dbc5bd7cf1e8 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 2 Jul 2024 17:50:47 -0600 Subject: [PATCH 02/44] Use djs 14.14.1 (Weird issue with entitlements?) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b812e6..12f4929 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@xmpp/client": "^0.13.1", "@xmpp/debug": "^0.13.0", "colors": "^1.4.0", - "discord.js": "^14.15.2", + "discord.js": "14.14.1", "geolib": "^3.3.4", "html-entities": "^2.5.2", "jimp": "^0.22.12", -- 2.43.5 From 6b9438ed10e12d9079c1be13336d0057c3e0cf1e Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Fri, 5 Jul 2024 15:59:44 -0600 Subject: [PATCH 03/44] Add TERMS.md For discorf --- TERMS.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 TERMS.md diff --git a/TERMS.md b/TERMS.md new file mode 100644 index 0000000..d578ee4 --- /dev/null +++ b/TERMS.md @@ -0,0 +1,5 @@ +# Terms of Service +## This is mostly here to comply with Discord verified bot stuff + +Other than complying with the GPL-3.0 License when contributing/using the code of this project, this bot is NOT to be used as an emergency alerting system, and should NOT be trusted with life/property under any circumstances. +Chris Chrome and any other contributors are not to be held liable should this not work in an emergency, as you shouldn't be using it for emergency alerts. \ No newline at end of file -- 2.43.5 From c223eabc6202fc0ec9d23ea1fbe1fbd47c43e508 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Fri, 5 Jul 2024 16:01:56 -0600 Subject: [PATCH 04/44] Add PRIVACY.md Discorf --- PRIVACY.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 PRIVACY.md diff --git a/PRIVACY.md b/PRIVACY.md new file mode 100644 index 0000000..8d436aa --- /dev/null +++ b/PRIVACY.md @@ -0,0 +1,7 @@ +# Privacy Policy + +Just to make this simple, heres a list of whats stored and how it's used +- Discord channel/user IDs of subscribed channels/DMs - Should be obvious, in case it's not, we need these to know where to send alerts. +- IEM rooms and filters - Should also be obvious, but again, we need to know which rooms you subscribed to + +Other than that, occasional debug logging may be enabled to fix bugs, and any logs gathered from debugging will be erased immidiately. \ No newline at end of file -- 2.43.5 From 7a12ed05d3883fe13a87e1b3d1213913d60cfb2a Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 15 Jul 2024 20:03:01 -0600 Subject: [PATCH 05/44] G U H --- .vscode/settings.json | 1 + data/sattelites.json | 209 ++++++++++++++++++++++++++++++++----- index.js | 236 ++++++++++++++++++++++++++++++------------ 3 files changed, 353 insertions(+), 93 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/data/sattelites.json b/data/sattelites.json index 94cda82..c82967e 100644 --- a/data/sattelites.json +++ b/data/sattelites.json @@ -1,30 +1,187 @@ { - "GOES-16": [ - { - "name": "GeoColor", - "url": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/GEOCOLOR/latest.jpg" - }, - { - "name": "Infrared", - "url": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/13/latest.jpg" - }, - { - "name": "FullDisk", - "url": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/FD/GEOCOLOR/678x678.jpg" + "GOES-16": { + "products": { + "Full Disk": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/FD/GEOCOLOR/1808x1808.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/FD/AirMass/1808x1808.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/FD/13/1808x1808.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/FD/10/1808x1808.jpg" + }, + "Floater 1": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/MESO/M1/GEOCOLOR/1000x1000.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/MESO/M1/13/1000x1000.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/MESO/M1/10/1000x1000.jpg" + }, + "Floater 2": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/MESO/M2/GEOCOLOR/1000x1000.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/MESO/M2/13/1000x1000.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/MESO/M2/10/1000x1000.jpg" + }, + "United States": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/GEOCOLOR/2500x1500.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/AirMass/2500x1500.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/13/2500x1500.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/10/2500x1500.jpg" + }, + "Canada": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/can/GEOCOLOR/2250x1125.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/can/AirMass/2250x1125.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/can/13/2250x1125.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/can/10/2250x1125.jpg" + }, + "Mexico": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/mex/GEOCOLOR/1000x1000.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/mex/AirMass/1000x1000.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/mex/13/1000x1000.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/mex/10/1000x1000.jpg" + }, + "US East Coast": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/eus/GEOCOLOR/1000x1000.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/eus/AirMass/1000x1000.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/eus/13/1000x1000.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/eus/10/1000x1000.jpg" + }, + "Gulf of Mexico": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/gm/GEOCOLOR/1000x1000.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/gm/AirMass/1000x1000.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/gm/13/1000x1000.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/gm/10/1000x1000.jpg" + }, + "Puerto Rico": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/pr/GEOCOLOR/1200x1200.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/pr/AirMass/1200x1200.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/pr/13/1200x1200.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/pr/10/1200x1200.jpg" + } } - ], - "GOES-18": [ - { - "name": "GeoColor", - "url": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/CONUS/GEOCOLOR/latest.jpg" - }, - { - "name": "Infrared", - "url": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/CONUS/13/latest.jpg" - }, - { - "name": "FullDisk", - "url": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/FD/GEOCOLOR/678x678.jpg" + }, + "GOES-18": { + "products": { + "Full Disk": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/FD/GEOCOLOR/1808x1808.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/FD/AirMass/1808x1808.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/FD/13/1808x1808.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/FD/10/1808x1808.jpg" + }, + "Floater 1": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/MESO/M1/GEOCOLOR/1000x1000.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/MESO/M1/13/1000x1000.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/MESO/M1/10/1000x1000.jpg" + }, + "Floater 2": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/MESO/M2/GEOCOLOR/1000x1000.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/MESO/M2/13/1000x1000.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/MESO/M2/10/1000x1000.jpg" + }, + "US West Coast": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/wus/GEOCOLOR/1000x1000.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/wus/AirMass/1000x1000.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/wus/13/1000x1000.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/wus/10/1000x1000.jpg" + }, + "Hawaii": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/SECTOR/hi/GEOCOLOR/1200x1200.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/SECTOR/hi/AirMass/1200x1200.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/SECTOR/hi/13/1200x1200.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/SECTOR/hi/10/1200x1200.jpg" + }, + "Alaska": { + "Visible": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/SECTOR/ak/GEOCOLOR/1000x1000.jpg", + "Airmass": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/SECTOR/ak/AirMass/1000x1000.jpg", + "Infrared": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/SECTOR/ak/13/1000x1000.jpg", + "Water Vapor": "https://cdn.star.nesdis.noaa.gov/GOES18/ABI/SECTOR/ak/10/1000x1000.jpg" + } } - ] + }, + "Himawari": { + "products": { + "Full Disk": { + "Visible": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/full_disk_ahi_true_color.jpg", + "Airmass": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/full_disk_ahi_rgb_airmass.jpg", + "Infrared": "https://www.ssec.wisc.edu/data/geo/images/himawari09/latest-himawari09_11_fd.gif", + "Water Vapor": "https://www.ssec.wisc.edu/data/geo/images/himawari09/latest-himawari09_10_fd.gif" + }, + "Floater 1": { + "Visible": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest/himawari-8/floater_02_geocolor.pngv", + "Airmass": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest/himawari-8/floater_02_rgb_airmass.png" + }, + "American Samoa": { + "Visible": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/american_samoa_ahi_natural_color.png", + "Airmass": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/american_samoa_ahi_rgb_airmass.png" + }, + "Australia": { + "Visible": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest/himawari-8/australia_true_color.jpg", + "Airmass": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/australia_ahi_rgb_airmass.png" + }, + "New Zealand": { + "Visible": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/new_zealand_ahi_natural_color.png", + "Airmass": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/new_zealand_ahi_rgb_airmass.png" + }, + "Guam": { + "Visible": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/guam_ahi_natural_color.png", + "Airmass": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/guam_ahi_rgb_airmass.png" + }, + "Hawaii": { + "Visible": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/hawaii_ahi_natural_color.png" + }, + "Japan": { + "Visible": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/japan_ahi_natural_color.png", + "Airmass": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/japan_ahi_rgb_airmass.png" + }, + "Russia": { + "Visible": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest/himawari-8/eastern_russia_true_color.jpg" + }, + "China": { + "Visible": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/eastern_china_ahi_natural_color.png", + "Airmass": "https://rammb.cira.colostate.edu/ramsdis/online/images/latest_hi_res/himawari-8/eastern_china_ahi_rgb_airmass.png" + } + } + }, + "EWS-G2": { + "products": { + "Full Disk": { + "Visible": "https://www.ssec.wisc.edu/data/geo/images/ews-g1/latest_ews-g1_01_fd.gif", + "Water Vapor": "https://www.ssec.wisc.edu/data/geo/images/ews-g1/latest_ews-g1_03_fd.gif" + } + } + }, + "FY-2G": { + "products": { + "Full Disk": { + "Visible": "https://www.ssec.wisc.edu/data/geo/images/fy2g/latest_fy2g_01_fd.gif", + "Infrared": "https://www.ssec.wisc.edu/data/geo/images/fy2g/latest_fy2g_02_fd.gif", + "Water Vapor": "https://www.ssec.wisc.edu/data/geo/images/fy2g/latest_fy2g_04_fd.gif" + } + } + }, + "GK-2A": { + "products": { + "Full Disk": { + "Infrared": "https://kiwiweather.com/gk-2a/FD_sanchez.jpg" + } + } + }, + "Meteosat 9": { + "products": { + "Full Disk": { + "Visible": "https://www.ssec.wisc.edu/data/geo/images/met-iodc/latest_met-iodc_01_fd.jpg", + "Infrared": "https://www.ssec.wisc.edu/data/geo/images/met-iodc/latest_met-iodc_04_fd.jpg", + "Water Vapor": "https://www.ssec.wisc.edu/data/geo/images/met-iodc/latest_met-iodc_06_fd.jpg" + } + } + }, + "Meteosat 10": { + "products": { + "Full Disk": { + "Visible": "https://www.ssec.wisc.edu/data/geo/images/met-prime/latest_met-prime_01_fd.gif", + "Infrared": "https://www.ssec.wisc.edu/data/geo/images/met-prime/latest_met-prime_04_fd.gif", + "Water Vapor": "https://www.ssec.wisc.edu/data/geo/images/met-prime/latest_met-prime_06_fd.gif" + }, + "Europe": { + "Visible": "https://www.ssec.wisc.edu/data/geo/images/met-prime/latest_met-prime_01_euro.gif", + "Infrared": "https://www.ssec.wisc.edu/data/geo/images/met-prime/latest_met-prime_04_euro.gif", + "Water Vapor": "https://www.ssec.wisc.edu/data/geo/images/met-prime/latest_met-prime_06_euro.gif" + } + } + } } \ No newline at end of file diff --git a/index.js b/index.js index db9f7c1..383c9df 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,9 @@ const Discord = require("discord.js"); const dVC = require("@discordjs/voice"); const colors = require("colors"); const sqlite3 = require("sqlite3").verbose(); + +satMessages = {}; + // Setup Discord const discord = new Discord.Client({ intents: [ @@ -402,7 +405,7 @@ xmpp.on("stanza", (stanza) => { { type: 2, style: 1, - custom_id: product_id_raw, + custom_id: `product|${product_id_raw}`, label: "Product Text", emoji: { name: "📄" @@ -605,10 +608,11 @@ discord.on('ready', async () => { "required": true, "choices": [] } - ] + ], + "integration_types": [0,1], + "contexts": [0, 1, 2] } for (const key in sattelites) { - // Push the key to the choices array satCommand.options[0].choices.push({ "name": key, "value": key @@ -1252,44 +1256,38 @@ discord.on("interactionCreate", async (interaction) => { sat = interaction.options.getString("sattelite"); if (!sattelites[sat]) return interaction.reply({ content: "Invalid satellite", ephemeral: true }); // Fetch all the images - await interaction.deferReply(); - imageBuffers = {}; - embeds = []; - files = []; - sattelites[sat].forEach(async (imgData) => { - // Get a buffer for the data, and put that in imageBuffers with the "name" as the key - fetch(imgData.url).then((res) => { - if (res.status !== 200) { - interaction.editReply({ content: "Failed to get satellite images", ephemeral: true }); - return; - } - res.buffer().then((buffer) => { - imageBuffers[imgData.name] = buffer; - files.push({ - attachment: buffer, - name: `${imgData.name}.jpg` - }); - embeds.push({ - title: `${sat} ${imgData.name}`, - image: { - url: `attachment://${imgData.name}.jpg` + productOptions = [] + await (() => { + for (const key in sattelites[sat].products) { + // make a discord customid safe id for the product name, add it to the sattelites object + sattelites[sat].products[key].customid = key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(); + productOptions.push({ + label: key, + value: sattelites[sat].products[key].customid + }) + } + console.log(JSON.stringify(productOptions, null, 2)) + })(); + satMessages[interaction.id] = { + sat + } + await interaction.reply({ + content: "Choose a product", + components: [ + { + type: 1, + components: [ + { + type: 3, + custom_id: `satproduct|${interaction.id}`, + label: "Product", + // map options to product names + options: productOptions } - }); - // Check if we have all the images - if (Object.keys(imageBuffers).length === sattelites[sat].length) { - // Send the images - interaction.editReply({ - embeds, - files - }); - } - }); - }).catch((err) => { - interaction.editReply({ content: "Failed to get satellite images", ephemeral: true }); - console.log(`${colors.red("[ERROR]")} Failed to get satellite images: ${err.message}`); - console.error(err); - }); - }); + ] + } + ] + }) break; case "forecast": @@ -1310,36 +1308,140 @@ discord.on("interactionCreate", async (interaction) => { } case Discord.InteractionType.MessageComponent: - if (interaction.customId) { - const product_id = interaction.customId; - url = `https://mesonet.agron.iastate.edu/api/1/nwstext/${product_id}`; - await interaction.deferReply({ ephemeral: true }); - fetch(url).then((res) => { - if (res.status !== 200) { - interaction.reply({ content: "Failed to get product text", ephemeral: true }); - return; + if (!interaction.customId) return; + switch (interaction.customId.split("|")[0]) { + case "product": + if (interaction.customId) { + const product_id = interaction.customId.split("|")[1]; + url = `https://mesonet.agron.iastate.edu/api/1/nwstext/${product_id}`; + await interaction.deferReply({ ephemeral: true }); + fetch(url).then((res) => { + if (res.status !== 200) { + interaction.reply({ content: "Failed to get product text", ephemeral: true }); + return; + } + // Retruns raw text, paginate it into multiple embeds if needed + res.text().then(async (text) => { + const pages = text.match(/[\s\S]{1,1900}(?=\n|$)/g); + // const embeds = pages.map((page, ind) => ({ + // title: `Product Text for ${product_id} Pg ${ind + 1}/${pages.length}`, + // description: `\`\`\`${page}\`\`\``, + // color: 0x00ff00 + // })); + const messages = pages.map((page, ind) => { + return `\`\`\`${page}\`\`\`` + }) + messages.forEach(async (message) => { + interaction.followUp({ content: message, ephemeral: true }); + }) + }); + }).catch((err) => { + interaction.reply({ content: "Failed to get product text", ephemeral: true }); + console.log(`${colors.red("[ERROR]")} Failed to get product text: ${err.message}`); + }); } - // Retruns raw text, paginate it into multiple embeds if needed - res.text().then(async (text) => { - const pages = text.match(/[\s\S]{1,1900}(?=\n|$)/g); - // const embeds = pages.map((page, ind) => ({ - // title: `Product Text for ${product_id} Pg ${ind + 1}/${pages.length}`, - // description: `\`\`\`${page}\`\`\``, - // color: 0x00ff00 - // })); - const messages = pages.map((page, ind) => { - return `\`\`\`${page}\`\`\`` - }) - messages.forEach(async (message) => { - interaction.followUp({ content: message, ephemeral: true }); - }) + break; + case "satproduct": + satData = satMessages[interaction.customId.split("|")[1]]; + sat = satData.sat + product = interaction.values[0]; + // find the original product name + product_name = Object.keys(sattelites[sat].products).find(key => sattelites[sat].products[key].customid === product); + imageOptions = [] + satMessages[interaction.customId.split("|")[1]] = { + sat, + product, + product_name, + images: {} + } + await (() => { + // for key, value in sattelites[sat].products[product_name] + console.log(product_name) + for (const key in sattelites[sat].products[product_name]) { + // make a discord customid safe id for the product name, add it to the sattelites object + //console.log(sattelites[sat].products[product_name]) + if (key === "customid") continue; + satMessages[interaction.customId.split("|")[1]].images[key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()] = sattelites[sat].products[product_name][key]; + imageOptions.push({ + label: key, + value: key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase() + }) + } + })(); + interaction.deferReply(); + await interaction.message.edit({ + content: "Choose an image to view", + components: [ + { + type: 1, + components: [ + { + type: 3, + custom_id: `satproduct2|${interaction.customId.split("|")[1]}`, + label: "Image", + // map options to product names + options: imageOptions + } + ] + } + ] + }).then(() => { + interaction.deleteReply(); }); - }).catch((err) => { - interaction.reply({ content: "Failed to get product text", ephemeral: true }); - console.log(`${colors.red("[ERROR]")} Failed to get product text: ${err.message}`); - }); + break; + case "satproduct2": + satData = satMessages[interaction.customId.split("|")[1]]; + sat = satData.sat; + product = satData.product; + product_name = satData.product_name; + image = interaction.values[0]; + url = satData.images[image]; + // get filename from url + filename = url.split("/").pop(); + interaction.deferReply(); + // Get the image + fetch(url).then((res) => { + if (res.status !== 200) { + interaction.message.edit({ content: "Failed to get image", ephemeral: true }).then(() => { + interaction.deleteReply(); + }); + return; + } + embeds = []; + files = []; + + res.buffer().then(async (buffer) => { + files.push({ + attachment: buffer, + name: filename + }) + embeds.push({ + title: `${sat}/${product_name}/${image}`, + image: { + url: `attachment://${filename}` + }, + color: 0x00ff00 + }); + interaction.message.edit({ + embeds, + files, + components: [], + content: null + }).then(() => { + interaction.deleteReply(); + }); + } + ); + }).catch((err) => { + interaction.message.edit({ content: "Failed to get image", ephemeral: true }).then(() => { + interaction.deleteReply(); + }); + console.log(`${colors.red("[ERROR]")} Failed to get image: ${err.stack}`); + }); + break; } break; + } @@ -1379,7 +1481,7 @@ discord.on("guildDelete", (guild) => { }) process.on("unhandledRejection", (error, promise) => { - console.log(`${colors.red("[ERROR]")} Unhandled Rejection @ ${promise}: ${error}`); + console.log(`${colors.red("[ERROR]")} Unhandled Rejection @ ${promise}: ${error.stack}`); // create errors folder if it doesnt exist if (!fs.existsSync("./error")) { fs.mkdirSync("./error"); -- 2.43.5 From aac14209646f90448c19d23f9c0cd34be4480352 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 15 Jul 2024 20:05:50 -0600 Subject: [PATCH 06/44] guess it cant be a dm thing --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 383c9df..8681a1e 100644 --- a/index.js +++ b/index.js @@ -608,9 +608,7 @@ discord.on('ready', async () => { "required": true, "choices": [] } - ], - "integration_types": [0,1], - "contexts": [0, 1, 2] + ] } for (const key in sattelites) { satCommand.options[0].choices.push({ -- 2.43.5 From 98673be5c7c096a2d45cdf7992c2e4a6198001a8 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 16 Jul 2024 21:51:11 -0600 Subject: [PATCH 07/44] # Major Bug Fix - "You had it set to 'W' for Wumbo, when you should've had it set to 'M' for mini." Fixed a small issue involving capitalization. TL;DR Fixed evtFilter for guild channels :) --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 8681a1e..d4aaf67 100644 --- a/index.js +++ b/index.js @@ -423,14 +423,14 @@ xmpp.on("stanza", (stanza) => { if (!rows) return; // No channels to alert rows.forEach((row) => { // Get Filters as arrays - if (!row.filterEvt) row.filterEvt = ""; + if (!row.filterevt) row.filterevt = ""; if (!row.filter) row.filter = ""; - let filterEvt = row.filterEvt.toLowerCase().split(","); + let filterevt = row.filterevt.toLowerCase().split(","); let filters = row.filter.toLowerCase().split(","); if (evt.priority < row.minPriority) return; - // If the event type is not in th filter, ignore it. Make sure filterEvt isnt null - if (!filterEvt[0]) filterEvt = []; - if (!filterEvt.includes(evt.code.toLowerCase()) && !filterEvt.length == 0) return; + // If the event type is not in th filter, ignore it. Make sure filterevt isnt null + if (!filterevt[0]) filterevt = []; + if (!filterevt.includes(evt.code.toLowerCase()) && !filterevt.length == 0) return; let channel = discord.channels.cache.get(row.channelid); if (!channel) return console.log(`${colors.red("[ERROR]")} Channel ${row.channelid} not found`); -- 2.43.5 From 70c30420fc00959106c34c94471a8374b28657c2 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Wed, 31 Jul 2024 20:57:49 -0600 Subject: [PATCH 08/44] uh --- index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index d4aaf67..9a9bca6 100644 --- a/index.js +++ b/index.js @@ -43,8 +43,9 @@ const db = new sqlite3.Database("channels.db", (err) => { } console.log(`${colors.cyan("[INFO]")} Connected to the database`); // Create tables if they dont exist - db.run(`CREATE TABLE IF NOT EXISTS channels (channelid TEXT, iemchannel TEXT, custommessage TEXT, minPriority INTEGER, "filter" TEXT, filterevt TEXT);`); + db.run(`CREATE TABLE IF NOT EXISTS channels (channelid TEXT, iemchannel TEXT, custommessage TEXT, minPriority INTEGER, "filter" TEXT, filterEvt TEXT);`); db.run(`CREATE TABLE IF NOT EXISTS userAlerts (userid TEXT, iemchannel TEXT, filter TEXT, filterEvt TEXT, minPriority INT, custommessage TEXT);`); + db.run(`ALTER TABLE channels RENAME COLUMN filterevt TO filterEvt;`) }); @@ -423,14 +424,14 @@ xmpp.on("stanza", (stanza) => { if (!rows) return; // No channels to alert rows.forEach((row) => { // Get Filters as arrays - if (!row.filterevt) row.filterevt = ""; + if (!row.filterEvt) row.filterEvt = ""; if (!row.filter) row.filter = ""; - let filterevt = row.filterevt.toLowerCase().split(","); + let filterEvt = row.filterEvt.toLowerCase().split(","); let filters = row.filter.toLowerCase().split(","); if (evt.priority < row.minPriority) return; - // If the event type is not in th filter, ignore it. Make sure filterevt isnt null - if (!filterevt[0]) filterevt = []; - if (!filterevt.includes(evt.code.toLowerCase()) && !filterevt.length == 0) return; + // If the event type is not in th filter, ignore it. Make sure filterEvt isnt null + if (!filterEvt[0]) filterEvt = []; + if (!filterEvt.includes(evt.code.toLowerCase()) && !filterEvt.length == 0) return; let channel = discord.channels.cache.get(row.channelid); if (!channel) return console.log(`${colors.red("[ERROR]")} Channel ${row.channelid} not found`); @@ -700,7 +701,7 @@ discord.on('ready', async () => { await (async () => { try { //Global - if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} Registering global commands: ${JSON.stringify(commands, null, 2)}`); + if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} Registering global commands`); await rest.put(Routes.applicationCommands(discord.user.id), { body: commands }) } catch (error) { console.error(error); @@ -772,7 +773,7 @@ discord.on("interactionCreate", async (interaction) => { } else if (row) { return interaction.reply({ content: `Already subscribed to \`${getWFOByRoom(room).location}\`\nIf you want to update a subscribtion, please unsubscribe and resubscribe. This will be made a command eventually.`, ephemeral: true }); } - db.run(`INSERT INTO channels (channelid, iemchannel, custommessage, filter, filterevt, minPriority) VALUES (?, ?, ?, ? ,? ,?)`, [interaction.channel.id, room, message, filter, filterEvt, minPriority], (err) => { + db.run(`INSERT INTO channels (channelid, iemchannel, custommessage, filter, filterEvt, minPriority) VALUES (?, ?, ?, ? ,? ,?)`, [interaction.channel.id, room, message, filter, filterEvt, minPriority], (err) => { if (err) { console.error(err.message); interaction.reply({ content: "Failed to subscribe to room", ephemeral: true }); -- 2.43.5 From 845fead37ae4de39f16784cbcc8301f382cd441c Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Thu, 15 Aug 2024 22:33:18 -0600 Subject: [PATCH 09/44] Backend Update - Send a message to the user who added the bot to a guild with support link --- index.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 9a9bca6..707b06d 100644 --- a/index.js +++ b/index.js @@ -1442,20 +1442,48 @@ discord.on("interactionCreate", async (interaction) => { break; } - - }); -discord.on("guildCreate", (guild) => { +discord.on("guildCreate", async (guild) => { + let logs = await guild.fetchAuditLogs() + logs = logs.entries.filter(e => e.action === Discord.AuditLogEvent.BotAdd) + let user = logs.find(l => l.target?.id === discord.user.id)?.executor // Get the main guild const myGuild = discord.guilds.cache.get(config.discord.mainGuild); // Get the log channel const channel = myGuild.channels.cache.get(config.discord.logChannel); // Send a message to the log channel + let invite = await discord.guilds.cache.get(config.discord.mainGuild).channels.cache.get(config.discord.inviteChannel).createInvite(); + user.send({ + embeds: [{ + description: `Thanks for adding ${discord.user.username}!\nIf you have **ANY** questions, comments, suggestions, bug reports, etc, please feel free to throw it by us in our support server!\n\nTo get started use \`/subscribe\` to get alerts!`, + color: 0x00ff00 + }], + components: [ + { + type: Discord.ComponentType.ActionRow, + components: [ + { + type: Discord.ComponentType.Button, + url: `https://discord.gg/${invite.code}`, + style: Discord.ButtonStyle.Link, + emoji: "ℹ", + label: "IEM Alerter Support Server" + } + ] + } + ] + }) channel.send({ embeds: [ { description: `I joined \`${guild.name}\``, + fields: [ + { + "name": "User", + "value": `<@${user.id}> (@${user.username}) ${user.displayName}` + } + ], color: 0x00ff00 } ] -- 2.43.5 From 662e0e775c2767fa80b46d793aba3e11536aee71 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Thu, 15 Aug 2024 22:35:44 -0600 Subject: [PATCH 10/44] Fix - Restart after 10 minutes of inactivity from weather.im --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index 707b06d..7d207a6 100644 --- a/index.js +++ b/index.js @@ -290,6 +290,8 @@ xmpp.on("offline", () => { }) }); +var restartTimer = null; + xmpp.on("stanza", (stanza) => { // Debug stuff if (config.debug >= 2) console.log(`${colors.magenta("[DEBUG]")} Stanza: ${stanza.toString()}`); @@ -315,6 +317,11 @@ xmpp.on("stanza", (stanza) => { } // Get new messages and log them, ignore old messages if (stanza.is("message") && stanza.attrs.type === "groupchat") { + clearTimeout(restartTimer) + restartTimer = setTimeout(() => { + console.log(`${colors.red("[FATAL]")} No messages from weather.im in 10 minutes, restarting!!!!!!!!!!!`) + process.exit(1) + }, 600000) // Stops spam from getting old messages if (startup) return; // Get channel name -- 2.43.5 From d48fe3085ae36123c9000f13a89c4bbaca4e42b1 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Thu, 15 Aug 2024 23:09:16 -0600 Subject: [PATCH 11/44] Update - Make NWRplay use new GWES icecast server! --- index.js | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 7d207a6..2af4e02 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,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 nwrstreams = {callsigns:{}}; const Jimp = require("jimp"); const { client, xml } = require("@xmpp/client"); const fetch = require("node-fetch"); @@ -264,6 +264,24 @@ var errCount = 0; const curUUID = generateUUID(); +// nwrstreams setup +// get icecast json data http://ingest.wxr.gwes-cdn.net/status-json.xsl +const fetchNWRstreams = () => { + fetch("http://ingest.wxr.gwes-cdn.net/status-json.xsl").then((res) => { + res.json().then((json) => { + json.icestats.source.forEach((source) => { + nwrstreams.callsigns[source.server_name] = source.listenurl; + }); + }); + console.log(`${colors.cyan("[INFO]")} Fetched NWR streams`); + }).catch((err) => { + console.error(err); + }); +} + +fetchNWRstreams(); +setInterval(fetchNWRstreams, 5 * 60 * 1000); // Every 5 minutes + const xmpp = client({ service: "xmpp://conference.weather.im", domain: "weather.im", @@ -693,16 +711,10 @@ discord.on('ready', async () => { "description": "The URL of the stream to play", "type": 3, "required": true, - "choices": [] + "autocomplete": true } ] } - for (const key in nwrstreams.callsigns) { - nwrplayCommand.options[0].choices.push({ - "name": key, - "value": key - }); - } commands.push(nwrplayCommand); } await (async () => { @@ -1448,6 +1460,19 @@ discord.on("interactionCreate", async (interaction) => { } break; + case Discord.InteractionType.ApplicationCommandAutocomplete: + //map nwrstreams + if (interaction.commandName === "nwrplay") { + let callsignSearch = interaction.options.getString("callsign"); + let callsigns = Object.keys(nwrstreams.callsigns); + let results = callsigns.filter((callsign) => callsign.toLowerCase().includes(callsignSearch.toLowerCase())); + if (results.length > 25) { + results = results.slice(0, 25); + } + interaction.respond(results.map((callsign) => ({ name: callsign, value: callsign }))); + } + break; + } }); -- 2.43.5 From aa8fe9498fc3bac03b3871f12ad11fc946ae05a0 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Fri, 16 Aug 2024 03:11:16 -0600 Subject: [PATCH 12/44] Update - Use cached URL for nwrstreams --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2af4e02..096b028 100644 --- a/index.js +++ b/index.js @@ -265,9 +265,9 @@ const curUUID = generateUUID(); // nwrstreams setup -// get icecast json data http://ingest.wxr.gwes-cdn.net/status-json.xsl +// get icecast json data const fetchNWRstreams = () => { - fetch("http://ingest.wxr.gwes-cdn.net/status-json.xsl").then((res) => { + fetch("https://icestats.weatherradio.org/").then((res) => { res.json().then((json) => { json.icestats.source.forEach((source) => { nwrstreams.callsigns[source.server_name] = source.listenurl; -- 2.43.5 From b10308ef3688d4fd722a8625ed182ac1bb4b5057 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Thu, 26 Sep 2024 07:57:25 -0600 Subject: [PATCH 13/44] Update data/events.json Fixed Hurricane Warnings and Tropical Storm Warnings that Show at lowest level. Now set to High instead of Lowest --- data/events.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/events.json b/data/events.json index 8422c4c..7fefc90 100644 --- a/data/events.json +++ b/data/events.json @@ -1160,11 +1160,11 @@ "text": "Tropical Cyclone Update" }, "TCV": { - "priority": 1, + "priority": 4, "text": "Tropical Cyclone Watch/Warning Break Points" }, "TIB": { - "priority": 3, + "priority": 4, "text": "Tsunami Bulletin" }, "TID": { -- 2.43.5 From f6acab4d2041b7bd8cddedadc3e23550e65f7ffe Mon Sep 17 00:00:00 2001 From: MoSiren Date: Fri, 27 Sep 2024 12:41:01 -0600 Subject: [PATCH 14/44] Update data/events.json NPW 3 --- data/events.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/events.json b/data/events.json index 7fefc90..483ff8c 100644 --- a/data/events.json +++ b/data/events.json @@ -680,7 +680,7 @@ "text": "Data Mgt Message" }, "NPW": { - "priority": 1, + "priority": 3, "text": "Non-Precipitation Warnings / Watches / Advisories" }, "NSH": { -- 2.43.5 From 9afdd5626eade9b9457833075f85573f0a4e3112 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Fri, 27 Sep 2024 13:48:25 -0600 Subject: [PATCH 15/44] Update data/events.json --- data/events.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/events.json b/data/events.json index 483ff8c..5001fec 100644 --- a/data/events.json +++ b/data/events.json @@ -217,7 +217,7 @@ }, "DSW": { "text": "Dust Storm Warning", - "priority": 5 + "priority": 4 }, "EFP": { "priority": 1, @@ -385,7 +385,7 @@ }, "FRW": { "text": "Fire Warning", - "priority": 4 + "priority": 3 }, "FSH": { "priority": 1, -- 2.43.5 From 73e42e2288baab313b1be3824f39c23171ad4111 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Thu, 21 Nov 2024 17:26:34 -0700 Subject: [PATCH 16/44] Updated WSW. --- data/events.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/events.json b/data/events.json index 5001fec..001f1b5 100644 --- a/data/events.json +++ b/data/events.json @@ -1345,7 +1345,7 @@ }, "WSW": { "text": "Winter Storm Warning", - "priority": 5 + "priority": 4 }, "WWA": { "priority": 1, -- 2.43.5 From ae63a0d52d7186a3eacbaa0474bb9b7a8e6cad5a Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 02:31:17 -0700 Subject: [PATCH 17/44] Add .catch to sending discord messages. Hopefully this will fix the log flooding lol --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 096b028..8db1200 100644 --- a/index.js +++ b/index.js @@ -473,6 +473,8 @@ xmpp.on("stanza", (stanza) => { console.error(err); }).then((msg) => { if (msg.channel.type === Discord.ChannelType.GuildAnnouncement) msg.crosspost(); + }).catch((err) => { + console.log(`${colors.orange("[WARN]")} Failed to send message to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id}): ${err}`); }); }); }).catch((err) => { -- 2.43.5 From b5bf06a38d8ec852785832496e66adcf052e0376 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 02:36:44 -0700 Subject: [PATCH 18/44] Fix that --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8db1200..ebc3b95 100644 --- a/index.js +++ b/index.js @@ -474,7 +474,7 @@ xmpp.on("stanza", (stanza) => { }).then((msg) => { if (msg.channel.type === Discord.ChannelType.GuildAnnouncement) msg.crosspost(); }).catch((err) => { - console.log(`${colors.orange("[WARN]")} Failed to send message to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id}): ${err}`); + console.log(`${colors.yellow("[WARN]")} Failed to send message to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id}): ${err}`); }); }); }).catch((err) => { -- 2.43.5 From d653bc3e909ea28942001a1bdad4f76da4324d87 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 02:41:40 -0700 Subject: [PATCH 19/44] Add discord error logs --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index ebc3b95..77c59e4 100644 --- a/index.js +++ b/index.js @@ -21,6 +21,7 @@ satMessages = {}; // Setup Discord const discord = new Discord.Client({ + intents: [ "Guilds", "GuildVoiceStates", @@ -35,6 +36,9 @@ const rest = new REST({ version: '10' }).setToken(config.discord.token); +discord.on("error", (err) => { + console.log(`${colors.red("[ERROR]")} Discord error: ${err}`); +}) // Setup SQlite DB const db = new sqlite3.Database("channels.db", (err) => { -- 2.43.5 From 8b94e7e3f8876b88b13a9b3d162c7f25a9e71a9a Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 02:50:54 -0700 Subject: [PATCH 20/44] Possibly notify of bad perms? --- index.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 77c59e4..2caf226 100644 --- a/index.js +++ b/index.js @@ -36,10 +36,6 @@ const rest = new REST({ version: '10' }).setToken(config.discord.token); -discord.on("error", (err) => { - console.log(`${colors.red("[ERROR]")} Discord error: ${err}`); -}) - // Setup SQlite DB const db = new sqlite3.Database("channels.db", (err) => { if (err) { @@ -451,7 +447,7 @@ xmpp.on("stanza", (stanza) => { console.log(`${colors.red("[ERROR]")} ${err.message}`); } if (!rows) return; // No channels to alert - rows.forEach((row) => { + rows.forEach(async (row) => { // Get Filters as arrays if (!row.filterEvt) row.filterEvt = ""; if (!row.filter) row.filter = ""; @@ -464,7 +460,14 @@ xmpp.on("stanza", (stanza) => { let channel = discord.channels.cache.get(row.channelid); if (!channel) return console.log(`${colors.red("[ERROR]")} Channel ${row.channelid} not found`); - + if (!channel.permissionsFor(discord.user).has("SEND_MESSAGES")) { + const logs = await channel.guild.fetchAuditLogs({ type: Discord.AuditLogEvent.BotAdd }); + const user = logs.entries.find(entry => entry.target.id === discord.user.id)?.executor; + if (user) { + user.send(`I don't have permission to send messages in the channel ${channel.name} (${channel.id}) in the guild ${channel.guild.name} (${channel.guild.id}). Please update my permissions.`); + } + return; + } // fetch the product text trySend = () => { fetch(`https://mesonet.agron.iastate.edu/api/1/nwstext/${product_id_raw}`).then((res) => { @@ -478,7 +481,7 @@ xmpp.on("stanza", (stanza) => { }).then((msg) => { if (msg.channel.type === Discord.ChannelType.GuildAnnouncement) msg.crosspost(); }).catch((err) => { - console.log(`${colors.yellow("[WARN]")} Failed to send message to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id}): ${err}`); + console.log(`${colors.yellow("[WARN]")} Failed to send message to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id})`); }); }); }).catch((err) => { -- 2.43.5 From d88188182c16d7e2cfe17ef68f98c5bafbc257b0 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 02:52:16 -0700 Subject: [PATCH 21/44] Bwuh --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2caf226..c406145 100644 --- a/index.js +++ b/index.js @@ -460,7 +460,7 @@ xmpp.on("stanza", (stanza) => { let channel = discord.channels.cache.get(row.channelid); if (!channel) return console.log(`${colors.red("[ERROR]")} Channel ${row.channelid} not found`); - if (!channel.permissionsFor(discord.user).has("SEND_MESSAGES")) { + if (!channel.permissionsFor(discord.user).has(Discord.PermissionFlagsBits.SendMessages)) { const logs = await channel.guild.fetchAuditLogs({ type: Discord.AuditLogEvent.BotAdd }); const user = logs.entries.find(entry => entry.target.id === discord.user.id)?.executor; if (user) { -- 2.43.5 From f763a95472b5f4f1ac2f671f08f622ca23932424 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 02:54:21 -0700 Subject: [PATCH 22/44] bwuuuuh --- index.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/index.js b/index.js index c406145..2ac90a7 100644 --- a/index.js +++ b/index.js @@ -460,14 +460,7 @@ xmpp.on("stanza", (stanza) => { let channel = discord.channels.cache.get(row.channelid); if (!channel) return console.log(`${colors.red("[ERROR]")} Channel ${row.channelid} not found`); - if (!channel.permissionsFor(discord.user).has(Discord.PermissionFlagsBits.SendMessages)) { - const logs = await channel.guild.fetchAuditLogs({ type: Discord.AuditLogEvent.BotAdd }); - const user = logs.entries.find(entry => entry.target.id === discord.user.id)?.executor; - if (user) { - user.send(`I don't have permission to send messages in the channel ${channel.name} (${channel.id}) in the guild ${channel.guild.name} (${channel.guild.id}). Please update my permissions.`); - } - return; - } + // fetch the product text trySend = () => { fetch(`https://mesonet.agron.iastate.edu/api/1/nwstext/${product_id_raw}`).then((res) => { -- 2.43.5 From cbb18421008cb3eb0cf18608cf30b23183fdd36f Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 03:00:31 -0700 Subject: [PATCH 23/44] Add message to log channel about failed sends --- index.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/index.js b/index.js index 2ac90a7..c7ceccc 100644 --- a/index.js +++ b/index.js @@ -475,6 +475,50 @@ xmpp.on("stanza", (stanza) => { if (msg.channel.type === Discord.ChannelType.GuildAnnouncement) msg.crosspost(); }).catch((err) => { console.log(`${colors.yellow("[WARN]")} Failed to send message to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id})`); + const logChannel = discord.guilds.cache.get(config.discord.mainGuild).channels.cache.get(config.discord.logChannel); + logChannel.send({ + embeds: [ + { + title: "Failed to send message", + description: `There is likely an issue with permissions. Please notify the server owner if possible.`, + fields: [ + { + name: "Guild", + value: `${channel.guild.name} (\`${channel.guild.id}\`)` + }, + { + name: "Channel", + value: `<#${channel.id}> (\`${channel.id}\`)` + }, + { + name: "Guild Owner", + value: `<@${channel.guild.ownerId}> (\`${channel.guild.ownerId}\`)` + }, + { + name: "Subscribed Room", + value: `\`${fromChannel}\`` + }, + { + name: "Custom Message", + value: row.custommessage || "None" + }, + { + name: "Filter", + value: row.filter || "None" + }, + { + name: "Event Filter", + value: row.filterEvt || "None" + }, + { + name: "Minimum Priority", + value: row.minPriority.toString() + } + ], + color: 0x00ff00 + } + ] + }); }); }); }).catch((err) => { -- 2.43.5 From 09f3fc957cf75cd28334a027580fa0e497e081fb Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 03:01:17 -0700 Subject: [PATCH 24/44] Fix issue --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index c7ceccc..235c1a5 100644 --- a/index.js +++ b/index.js @@ -512,7 +512,7 @@ xmpp.on("stanza", (stanza) => { }, { name: "Minimum Priority", - value: row.minPriority.toString() + value: row.minPriority.toString() || "None" } ], color: 0x00ff00 -- 2.43.5 From 00f97fd6e638c63dcdce8f6de141f3918daa00e4 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 03:02:13 -0700 Subject: [PATCH 25/44] Damn, busy night lol --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 235c1a5..9ee74e7 100644 --- a/index.js +++ b/index.js @@ -512,7 +512,7 @@ xmpp.on("stanza", (stanza) => { }, { name: "Minimum Priority", - value: row.minPriority.toString() || "None" + value: row.minPriority || "None" } ], color: 0x00ff00 -- 2.43.5 From 96912d325a33bf56fb169cf15876d88de93f6042 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 03:04:09 -0700 Subject: [PATCH 26/44] Make embed smaller --- index.js | 41 +++++------------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index 9ee74e7..52ac0eb 100644 --- a/index.js +++ b/index.js @@ -480,42 +480,11 @@ xmpp.on("stanza", (stanza) => { embeds: [ { title: "Failed to send message", - description: `There is likely an issue with permissions. Please notify the server owner if possible.`, - fields: [ - { - name: "Guild", - value: `${channel.guild.name} (\`${channel.guild.id}\`)` - }, - { - name: "Channel", - value: `<#${channel.id}> (\`${channel.id}\`)` - }, - { - name: "Guild Owner", - value: `<@${channel.guild.ownerId}> (\`${channel.guild.ownerId}\`)` - }, - { - name: "Subscribed Room", - value: `\`${fromChannel}\`` - }, - { - name: "Custom Message", - value: row.custommessage || "None" - }, - { - name: "Filter", - value: row.filter || "None" - }, - { - name: "Event Filter", - value: row.filterEvt || "None" - }, - { - name: "Minimum Priority", - value: row.minPriority || "None" - } - ], - color: 0x00ff00 + description: `There is likely an issue with permissions. Please notify the server owner if possible. + Guild: ${channel.guild.name} (${channel.guild.id}) + Channel: ${channel.name} (${channel.id}) + Guild Owner: ${channel.guild.owner.user.username} (${channel.guild.owner.user.id})`, + color: 0xff0000 } ] }); -- 2.43.5 From d491fda5c88c1e3ffd9d70ff46bdb7728ba074a5 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 03:04:56 -0700 Subject: [PATCH 27/44] Im dumb --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 52ac0eb..138bf3d 100644 --- a/index.js +++ b/index.js @@ -483,7 +483,7 @@ xmpp.on("stanza", (stanza) => { description: `There is likely an issue with permissions. Please notify the server owner if possible. Guild: ${channel.guild.name} (${channel.guild.id}) Channel: ${channel.name} (${channel.id}) - Guild Owner: ${channel.guild.owner.user.username} (${channel.guild.owner.user.id})`, + Guild Owner: ${channel.guild.owner.username} (${channel.guild.owner.id})`, color: 0xff0000 } ] -- 2.43.5 From 9f31d18a6f51c5bf7f37f228e9e3b2db3a5705c1 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 03:06:31 -0700 Subject: [PATCH 28/44] Smol fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 138bf3d..f0e0840 100644 --- a/index.js +++ b/index.js @@ -483,7 +483,7 @@ xmpp.on("stanza", (stanza) => { description: `There is likely an issue with permissions. Please notify the server owner if possible. Guild: ${channel.guild.name} (${channel.guild.id}) Channel: ${channel.name} (${channel.id}) - Guild Owner: ${channel.guild.owner.username} (${channel.guild.owner.id})`, + Guild Owner: <@${channel.guild.ownerId}> (${channel.guild.ownerId})`, color: 0xff0000 } ] -- 2.43.5 From 0227979176c4840ad97f1f94112b81c475d0bfe9 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 03:18:24 -0700 Subject: [PATCH 29/44] Add full sub info to permission errors --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f0e0840..dd1ed07 100644 --- a/index.js +++ b/index.js @@ -483,7 +483,8 @@ xmpp.on("stanza", (stanza) => { description: `There is likely an issue with permissions. Please notify the server owner if possible. Guild: ${channel.guild.name} (${channel.guild.id}) Channel: ${channel.name} (${channel.id}) - Guild Owner: <@${channel.guild.ownerId}> (${channel.guild.ownerId})`, + Guild Owner: <@${channel.guild.ownerId}> (${channel.guild.ownerId}) + Sub Info: \`\`\`json\n${JSON.stringify(row)}\`\`\``, color: 0xff0000 } ] -- 2.43.5 From e952ec60e72e98d416a281463e39b4ef3eb92905 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 Jan 2025 23:36:26 -0700 Subject: [PATCH 30/44] Notify guild owners and remove subs --- index.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/index.js b/index.js index dd1ed07..09868a5 100644 --- a/index.js +++ b/index.js @@ -489,6 +489,37 @@ xmpp.on("stanza", (stanza) => { } ] }); + + discord.users.fetch(channel.guild.ownerId).then((user) => { + user.send({ + embeds: [ + { + title: "Issue with your subscribed channel.", + description: `There is likely an issue with permissions. Please check that I can send messages in <#${channel.id}>\nYour subscription has been removed, and you will need to resubscribe to get alerts.`, + color: 0xff0000, + fields: [ + { + name: "Guild", + value: `${channel.guild.name} (${channel.guild.id})` + }, + { + name: "Channel", + value: `${channel.name} (${channel.id})` + } + ] + } + ] + }).catch((err) => { + console.log(`${colors.red("[ERROR]")} Failed to send message to ${channel.guild.ownerId}`); + }).then(() => { + db.run(`DELETE FROM channels WHERE channelid = ? AND iemchannel = ?`, [channel.id, fromChannel], (err) => { + if (err) { + console.error(err.message); + } + console.log(`${colors.cyan("[INFO]")} Deleted channel ${channel.id} from database`); + }); + }) + }); }); }); }).catch((err) => { -- 2.43.5 From 4bb679cef8afa7993a9fe6636b381cce9da59efe Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 13 Jan 2025 14:24:01 -0700 Subject: [PATCH 31/44] Add perm check to subscribe command --- index.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 09868a5..e60921d 100644 --- a/index.js +++ b/index.js @@ -832,21 +832,26 @@ discord.on("interactionCreate", async (interaction) => { filterEvt = interaction.options.getString("filterevt") || null; message = interaction.options.getString("message") || null; if (interaction.inGuild()) { - db.get(`SELECT * FROM channels WHERE channelid = ? AND iemchannel = ?`, [interaction.channel.id, room], (err, row) => { - if (err) { - console.error(err.message); - interaction.reply({ content: "Failed to subscribe to room", ephemeral: true }); - } else if (row) { - return interaction.reply({ content: `Already subscribed to \`${getWFOByRoom(room).location}\`\nIf you want to update a subscribtion, please unsubscribe and resubscribe. This will be made a command eventually.`, ephemeral: true }); - } - db.run(`INSERT INTO channels (channelid, iemchannel, custommessage, filter, filterEvt, minPriority) VALUES (?, ?, ?, ? ,? ,?)`, [interaction.channel.id, room, message, filter, filterEvt, minPriority], (err) => { + interaction.channel.send("Permission check").then((msg) => { + msg.delete(); + db.get(`SELECT * FROM channels WHERE channelid = ? AND iemchannel = ?`, [interaction.channel.id, room], (err, row) => { if (err) { console.error(err.message); interaction.reply({ content: "Failed to subscribe to room", ephemeral: true }); - } else { - interaction.reply({ content: `Subscribed to \`${getWFOByRoom(room).location}\``, ephemeral: true }); + } else if (row) { + return interaction.reply({ content: `Already subscribed to \`${getWFOByRoom(room).location}\`\nIf you want to update a subscribtion, please unsubscribe and resubscribe. This will be made a command eventually.`, ephemeral: true }); } + db.run(`INSERT INTO channels (channelid, iemchannel, custommessage, filter, filterEvt, minPriority) VALUES (?, ?, ?, ? ,? ,?)`, [interaction.channel.id, room, message, filter, filterEvt, minPriority], (err) => { + if (err) { + console.error(err.message); + interaction.reply({ content: "Failed to subscribe to room", ephemeral: true }); + } else { + interaction.reply({ content: `Subscribed to \`${getWFOByRoom(room).location}\``, ephemeral: true }); + } + }); }); + }).catch((err) => { + interaction.reply({ content: "Failed to subscribe to room. Bot does not have send message permissions here!", ephemeral: true }); }); } else { // We're in a DM db.get(`SELECT * FROM userAlerts WHERE userid = ? AND iemchannel = ?`, [interaction.user.id, room], (err, row) => { -- 2.43.5 From 9b80f79436ee5382ae266520a4577491069ad497 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 13 Jan 2025 14:35:07 -0700 Subject: [PATCH 32/44] Add Pilot Reports to events --- data/blacklist.json | 2 -- data/events.json | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/data/blacklist.json b/data/blacklist.json index c390eb2..f0b3e61 100644 --- a/data/blacklist.json +++ b/data/blacklist.json @@ -91,6 +91,4 @@ "zsechat@conference.weather.im", "zdcchat@conference.weather.im", "znychat@conference.weather.im" - - ] \ No newline at end of file diff --git a/data/events.json b/data/events.json index 001f1b5..5b4fc35 100644 --- a/data/events.json +++ b/data/events.json @@ -1522,6 +1522,9 @@ "REP": { "text": "RECCO Observations (tropical cyclone)", "priority": 3 + }, + "PIR": { + "text": "Pilot Reports", + "priority": 1 } - } -- 2.43.5 From bd275403e9f2278e6c81be333e2ef45d9656374e Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 13 Jan 2025 14:36:08 -0700 Subject: [PATCH 33/44] Add discord message when unknown event type trips --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index e60921d..504fe87 100644 --- a/index.js +++ b/index.js @@ -360,6 +360,16 @@ xmpp.on("stanza", (stanza) => { evt = { name: "Unknown", priority: 3 } console.log(`${colors.red("[ERROR]")} Unknown event type: ${product_id.pil.substring(0, 3)}. Fix me`); console.log(`${colors.magenta("[DEBUG]")} ${bodyData.string}`) + const logChannel = discord.guilds.cache.get(config.discord.mainGuild).channels.cache.get(config.discord.logChannel); + logChannel.send({ + embeds: [ + { + title: "Unknown Event Type", + description: `Unknown event type: ${product_id.pil.substring(0, 3)}. Please check the logs for more details.`, + color: 0xff0000 + } + ] + }); } evt.code = product_id.pil.substring(0, 3); -- 2.43.5 From e02faaab18aa1b2fccd7c9e2da1be8cf302f196f Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 3 Feb 2025 05:04:21 -0700 Subject: [PATCH 34/44] Add bypass to deletion for main guild --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 504fe87..67232d5 100644 --- a/index.js +++ b/index.js @@ -522,6 +522,7 @@ xmpp.on("stanza", (stanza) => { }).catch((err) => { console.log(`${colors.red("[ERROR]")} Failed to send message to ${channel.guild.ownerId}`); }).then(() => { + if (channel.guildId == config.discord.mainGuild) return; db.run(`DELETE FROM channels WHERE channelid = ? AND iemchannel = ?`, [channel.id, fromChannel], (err) => { if (err) { console.error(err.message); -- 2.43.5 From 79ae2f4c25ed2697203b41b8b32b9888324c1dbe Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 9 Feb 2025 10:23:15 -0700 Subject: [PATCH 35/44] Fix sat typo, mb --- data/{sattelites.json => satellites.json} | 0 index.js | 40 ++++++++++++----------- 2 files changed, 21 insertions(+), 19 deletions(-) rename data/{sattelites.json => satellites.json} (100%) diff --git a/data/sattelites.json b/data/satellites.json similarity index 100% rename from data/sattelites.json rename to data/satellites.json diff --git a/index.js b/index.js index 67232d5..6a256c5 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ const wfos = require("./data/wfos.json"); 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 satellites = require("./data/satellites.json"); const nwrstreams = {callsigns:{}}; const Jimp = require("jimp"); const { client, xml } = require("@xmpp/client"); @@ -682,19 +682,19 @@ discord.on('ready', async () => { commands = require("./data/commands.json"); // Add dynamic commands (based on datas files) satCommand = { - "name": "sattelite", - "description": "Get the latest sattelite images from a given sattelite", + "name": "satellite", + "description": "Get the latest satellite images from a given satellite", "options": [ { - "name": "sattelite", - "description": "The sattelite to get images from", + "name": "satellite", + "description": "The satellite to get images from", "type": 3, "required": true, "choices": [] } ] } - for (const key in sattelites) { + for (const key in satellites) { satCommand.options[0].choices.push({ "name": key, "value": key @@ -1333,18 +1333,18 @@ discord.on("interactionCreate", async (interaction) => { console.error(err); }); break; - case "sattelite": // Get satellite images - sat = interaction.options.getString("sattelite"); - if (!sattelites[sat]) return interaction.reply({ content: "Invalid satellite", ephemeral: true }); + case "satellite": // Get satellite images + sat = interaction.options.getString("satellite"); + if (!satellites[sat]) return interaction.reply({ content: "Invalid satellite", ephemeral: true }); // Fetch all the images productOptions = [] await (() => { - for (const key in sattelites[sat].products) { - // make a discord customid safe id for the product name, add it to the sattelites object - sattelites[sat].products[key].customid = key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(); + for (const key in satellites[sat].products) { + // make a discord customid safe id for the product name, add it to the satellites object + satellites[sat].products[key].customid = key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(); productOptions.push({ label: key, - value: sattelites[sat].products[key].customid + value: satellites[sat].products[key].customid }) } console.log(JSON.stringify(productOptions, null, 2)) @@ -1427,7 +1427,7 @@ discord.on("interactionCreate", async (interaction) => { sat = satData.sat product = interaction.values[0]; // find the original product name - product_name = Object.keys(sattelites[sat].products).find(key => sattelites[sat].products[key].customid === product); + product_name = Object.keys(satellites[sat].products).find(key => satellites[sat].products[key].customid === product); imageOptions = [] satMessages[interaction.customId.split("|")[1]] = { sat, @@ -1436,13 +1436,13 @@ discord.on("interactionCreate", async (interaction) => { images: {} } await (() => { - // for key, value in sattelites[sat].products[product_name] + // for key, value in satellites[sat].products[product_name] console.log(product_name) - for (const key in sattelites[sat].products[product_name]) { - // make a discord customid safe id for the product name, add it to the sattelites object - //console.log(sattelites[sat].products[product_name]) + for (const key in satellites[sat].products[product_name]) { + // make a discord customid safe id for the product name, add it to the satellites object + //console.log(satellites[sat].products[product_name]) if (key === "customid") continue; - satMessages[interaction.customId.split("|")[1]].images[key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()] = sattelites[sat].products[product_name][key]; + satMessages[interaction.customId.split("|")[1]].images[key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()] = satellites[sat].products[product_name][key]; imageOptions.push({ label: key, value: key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase() @@ -1646,5 +1646,7 @@ process.on("uncaughtException", (error) => { return; }); + + // Login to discord discord.login(config.discord.token); \ No newline at end of file -- 2.43.5 From ded7a2373cea23fab78fe50680f2ab6750bcdcd5 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 9 Feb 2025 10:29:05 -0700 Subject: [PATCH 36/44] Attempt to not throw error when we cant DM a user! --- index.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6a256c5..7acf665 100644 --- a/index.js +++ b/index.js @@ -576,7 +576,28 @@ xmpp.on("stanza", (stanza) => { thisMsg.content = row.custommessage || null; user.send(thisMsg).catch((err) => { console.error(err); - }); + }).catch((err) => { + console.log(`${colors.yellow("[WARN]")} Failed to send message to ${user.tag} (${user.id})`); + const logChannel = discord.guilds.cache.get(config.discord.mainGuild).channels.cache.get(config.discord.logChannel); + logChannel.send({ + embeds: [ + { + title: "Failed to send DM", + description: `User may have DMs disabled, or bot doesnt' share a server anymore!. + User: ${user.tag} (${user.id}) + Sub Info: \`\`\`json\n${JSON.stringify(row)}\`\`\``, + color: 0xff0000 + } + ] + }).then(() => { + db.run(`DELETE FROM userAlerts WHERE userid = ? AND iemchannel = ?`, [user.id, fromChannel], (err) => { + if (err) { + console.error(err.message); + } + console.log(`${colors.cyan("[INFO]")} Deleted user ${user.id} from database`); + }); + }) + } }); }).catch((err) => { setTimeout(() => { @@ -1568,6 +1589,8 @@ discord.on("guildCreate", async (guild) => { ] } ] + }).catch((err) => { + console.log(`${colors.red("[ERROR]")} Failed to send message to user ${user.id}: ${err.message}`); }) channel.send({ embeds: [ -- 2.43.5 From 770813b4a74b9b116abc7f03c9c52321acc973f7 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 9 Feb 2025 10:30:11 -0700 Subject: [PATCH 37/44] Whooooops --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7acf665..d626bb8 100644 --- a/index.js +++ b/index.js @@ -597,7 +597,7 @@ xmpp.on("stanza", (stanza) => { console.log(`${colors.cyan("[INFO]")} Deleted user ${user.id} from database`); }); }) - } + }); }); }).catch((err) => { setTimeout(() => { -- 2.43.5 From 5b487125aa0e733819c81c1875c66cbba92badf9 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Wed, 12 Feb 2025 07:51:27 -0700 Subject: [PATCH 38/44] Update some logging stuff --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d626bb8..08c1246 100644 --- a/index.js +++ b/index.js @@ -377,13 +377,14 @@ xmpp.on("stanza", (stanza) => { const now = new Date(); const diff = (now - product_id.timestamp) / 1000 / 60; if (diff > 3) return; - if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`); + // if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`); + console.log(`${colors.cyan("[INFO]")} ${getWFO(fromChannel)?.location || fromChannel} issues ${evt.name}`) messages++; // Handle NTFY if (config.ntfy.enabled) { - if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} Sending NTFY for ${config.ntfy.prefix}${fromChannel}`) + //if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} Sending NTFY for ${config.ntfy.prefix}${fromChannel}`) ntfyBody = { "topic": `${config.ntfy.prefix}${fromChannel}`, "message": bodyData.string, @@ -401,7 +402,7 @@ xmpp.on("stanza", (stanza) => { 'Authorization': `Bearer ${config.ntfy.token}` } }).then((res) => { - if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} NTFY sent for ${config.ntfy.prefix}${fromChannel} with status ${res.status} ${res.statusText}`); + //if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} NTFY sent for ${config.ntfy.prefix}${fromChannel} with status ${res.status} ${res.statusText}`); if (res.status !== 200) console.log(`${colors.red("[ERROR]")} NTFY failed for ${config.ntfy.prefix}${fromChannel} with status ${res.status} ${res.statusText}`); -- 2.43.5 From 1a7c1735f40fe9e0df51964ae2ad5a9b5505e447 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Wed, 12 Feb 2025 07:54:59 -0700 Subject: [PATCH 39/44] Fix log? --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 08c1246..796aa10 100644 --- a/index.js +++ b/index.js @@ -378,7 +378,7 @@ xmpp.on("stanza", (stanza) => { const diff = (now - product_id.timestamp) / 1000 / 60; if (diff > 3) return; // if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`); - console.log(`${colors.cyan("[INFO]")} ${getWFO(fromChannel)?.location || fromChannel} issues ${evt.name}`) + console.log(`${colors.cyan("[INFO]")} ${wfo.location || fromChannel} issues ${evt.text}`) messages++; -- 2.43.5 From 1ae72ac979cfc559233e773e79fa9e7724a92a2f Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Wed, 12 Feb 2025 07:56:27 -0700 Subject: [PATCH 40/44] hotfix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 796aa10..65f5ac7 100644 --- a/index.js +++ b/index.js @@ -378,7 +378,7 @@ xmpp.on("stanza", (stanza) => { const diff = (now - product_id.timestamp) / 1000 / 60; if (diff > 3) return; // if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`); - console.log(`${colors.cyan("[INFO]")} ${wfo.location || fromChannel} issues ${evt.text}`) + console.log(`${colors.cyan("[INFO]")} ${getWFOByRoom(fromChannel).location} - ${evt.name} - ${product_id.timestamp}`); messages++; -- 2.43.5 From a543386394dde89c974b9adf101018b4ecd1bee5 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Wed, 12 Feb 2025 07:57:20 -0700 Subject: [PATCH 41/44] Made the same mistake twice, dang --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 65f5ac7..47ee6b2 100644 --- a/index.js +++ b/index.js @@ -378,7 +378,7 @@ xmpp.on("stanza", (stanza) => { const diff = (now - product_id.timestamp) / 1000 / 60; if (diff > 3) return; // if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`); - console.log(`${colors.cyan("[INFO]")} ${getWFOByRoom(fromChannel).location} - ${evt.name} - ${product_id.timestamp}`); + console.log(`${colors.cyan("[INFO]")} ${getWFOByRoom(fromChannel).location} - ${evt.text} - ${product_id.timestamp}`); messages++; -- 2.43.5 From c82ab68c1e005ff2e54b098af1f953b402c8ff0a Mon Sep 17 00:00:00 2001 From: MoSiren Date: Thu, 13 Mar 2025 23:51:03 -0600 Subject: [PATCH 42/44] Nexlabs Outlooks --- data/outlook.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/data/outlook.json b/data/outlook.json index a6450b3..a00c52d 100644 --- a/data/outlook.json +++ b/data/outlook.json @@ -1,13 +1,13 @@ { "convective": [ - "https://www.spc.noaa.gov/products/outlook/day1otlk.gif", - "https://www.spc.noaa.gov/products/outlook/day2otlk.gif", - "https://www.spc.noaa.gov/products/outlook/day3otlk.gif", - "https://www.spc.noaa.gov/products/exper/day4-8/day4prob.gif", - "https://www.spc.noaa.gov/products/exper/day4-8/day5prob.gif", - "https://www.spc.noaa.gov/products/exper/day4-8/day6prob.gif", - "https://www.spc.noaa.gov/products/exper/day4-8/day7prob.gif", - "https://www.spc.noaa.gov/products/exper/day4-8/day8prob.gif" + "https://weather.cod.edu/cdata/text/images/spc/co/day1/categorical/spccoday1.categorical.latest.png", + "https://climate.cod.edu/data/text/images/spc/co/day2/categorical/spccoday2.categorical.latest.png", + "https://climate.cod.edu/data/text/images/spc/co/day3/categorical/spccoday3.categorical.latest.png", + "https://climate.cod.edu/data/text/images/spc/co/day4/severe/spccoday4.severe.latest.png", + "https://climate.cod.edu/data/text/images/spc/co/day5/severe/spccoday5.severe.latest.png", + "https://climate.cod.edu/data/text/images/spc/co/day6/severe/spccoday6.severe.latest.png", + "https://climate.cod.edu/data/text/images/spc/co/day7/severe/spccoday7.severe.latest.png", + "https://climate.cod.edu/data/text/images/spc/co/day8/severe/spccoday8.severe.latest.png" ], "fire": [ "https://www.spc.noaa.gov/products/exper/fire_wx/imgs/day1otlk_fire.gif", -- 2.43.5 From cce9b126451279886a9ed7782154973d3f05ef15 Mon Sep 17 00:00:00 2001 From: MoSiren Date: Fri, 18 Apr 2025 19:30:46 -0600 Subject: [PATCH 43/44] Update data/events.json Flash Flood Warning Is Level 5 --- data/events.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/events.json b/data/events.json index 5b4fc35..b96415b 100644 --- a/data/events.json +++ b/data/events.json @@ -365,7 +365,7 @@ }, "FFW": { "text": "Flash Flood Warning", - "priority": 4 + "priority": 5 }, "FLN": { "priority": 1, -- 2.43.5 From 664e00b7f44ee762e05f807c35bd571530178d5a Mon Sep 17 00:00:00 2001 From: MoSiren Date: Fri, 18 Apr 2025 19:35:53 -0600 Subject: [PATCH 44/44] Update data/events.json updated some pri codes --- data/events.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/data/events.json b/data/events.json index b96415b..d4cbc95 100644 --- a/data/events.json +++ b/data/events.json @@ -1164,7 +1164,7 @@ "text": "Tropical Cyclone Watch/Warning Break Points" }, "TIB": { - "priority": 4, + "priority": 3, "text": "Tsunami Bulletin" }, "TID": { @@ -1308,7 +1308,7 @@ "text": "Routine Space Environment Product Issued Weekly" }, "WOU": { - "priority": 4, + "priority": 5, "text": "Tornado/Severe Thunderstorm Watch" }, "WS1": { @@ -1365,11 +1365,11 @@ }, "CFA": { "text": "Coastal Flood Watch", - "priority": 4 + "priority": 3 }, "FLA": { "text": "Flood Watch", - "priority": 2 + "priority": 3 }, "HWA": { "text": "High Wind Watch", @@ -1389,7 +1389,7 @@ }, "SVA": { "text": "Severe Thunderstorm Watch", - "priority": 4 + "priority": 5 }, "TOA": { "text": "Tornado Watch", @@ -1405,7 +1405,7 @@ }, "TSA": { "text": "Tsunami Watch", - "priority": 4 + "priority": 5 }, "TSW": { "text": "Tsunami Warning", -- 2.43.5