This commit is contained in:
Christopher Cookman 2024-10-02 12:22:07 -06:00
parent 9afdd5626e
commit 443c82fcd9
3 changed files with 17 additions and 8 deletions

View file

@ -1522,6 +1522,9 @@
"REP": {
"text": "RECCO Observations (tropical cyclone)",
"priority": 3
},
"PIR": {
"priority": 0,
"_comment": "This is an unknown event type, ignore it for now until we know more info"
}
}

View file

@ -1,4 +1,3 @@
const geolib = require("geolib");
// Use OSM API to get coordinates https://nominatim.openstreetmap.org/search?q=search+query&format=json&limit=1
const getCoordinates = async (location) => {
return new Promise((resolve, reject) => {

View file

@ -356,6 +356,8 @@ xmpp.on("stanza", (stanza) => {
// get product id from "x" tag
var evt = events[product_id.pil.substring(0, 3)];
if (evt.priority === 0) return; // This is an event that we don't care about
if (!evt) {
evt = { name: "Unknown", priority: 3 }
console.log(`${colors.red("[ERROR]")} Unknown event type: ${product_id.pil.substring(0, 3)}. Fix me`);
@ -453,10 +455,12 @@ xmpp.on("stanza", (stanza) => {
if (!row.filter) row.filter = "";
let filterEvt = row.filterEvt.toLowerCase().split(",");
let filters = row.filter.toLowerCase().split(",");
filterEvt = filterEvt.filter(filter => !filter.startsWith('!'));
filters = filters.filter(filter => !filter.startsWith('!'));
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 (filterEvt.some(filter => filter.startsWith('!') ? evt.code.toLowerCase() === filter.substring(1) : !filter.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`);
@ -499,12 +503,15 @@ xmpp.on("stanza", (stanza) => {
if (!row.filter) row.filter = "";
let filterEvt = row.filterEvt.toLowerCase().split(",");
let filters = row.filter.toLowerCase().split(",");
filterEvt = filterEvt.filter(filter => !filter.startsWith('!'));
filters = filters.filter(filter => !filter.startsWith('!'));
// If priority is less than the min priority, ignore it
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 (filterEvt.some(filter => filter.startsWith('!') ? evt.code.toLowerCase() === filter.substring(1) : !filter.includes(evt.code.toLowerCase())) && filterEvt.length > 0) return;
let user = discord.users.cache.get(row.userid);
if (!user) return console.log(`${colors.red("[ERROR]")} User ${row.userid} not found`);
@ -789,9 +796,9 @@ discord.on("interactionCreate", async (interaction) => {
if (err) {
console.error(err.message);
interaction.reply({ content: "Failed to subscribe to room", ephemeral: true });
} else if (row) {
} /*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);
@ -806,9 +813,9 @@ discord.on("interactionCreate", async (interaction) => {
if (err) {
console.error(err.message);
interaction.reply({ content: "Failed to subscribe to room", ephemeral: true });
} else if (row) {
} /*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 userAlerts (userid, iemchannel, custommessage, filter, filterEvt, minPriority) VALUES (?, ?, ?, ? ,?, ?)`, [interaction.user.id, room, message, filter, filterEvt, minPriority], (err) => {
if (err) {
console.error(err.message);