Force all filters to be lowercase, for easier filtering

This commit is contained in:
Christopher Cookman 2024-05-22 12:34:09 -06:00
parent 6dd606209d
commit 54eb401093
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -409,13 +409,13 @@ xmpp.on("stanza", (stanza) => {
// Get Filters as arrays // Get Filters as arrays
if (!row.filterEvt) row.filterEvt = ""; if (!row.filterEvt) row.filterEvt = "";
if (!row.filter) row.filter = ""; if (!row.filter) row.filter = "";
let filterEvt = row.filterEvt.split(","); let filterEvt = row.filterEvt.toLowerCase().split(",");
let filters = row.filter.split(","); let filters = row.filter.toLowerCase().split(",");
if (evt.priority < row.minPriority) return; if (evt.priority < row.minPriority) return;
// If the event type is not in th filter, ignore it. Make sure filterEvt isnt null // If the event type is not in th filter, ignore it. Make sure filterEvt isnt null
if (!filterEvt[0]) filterEvt = []; if (!filterEvt[0]) filterEvt = [];
if (!filterEvt.includes(evt.code) && !filterEvt.length == 0) return; if (!filterEvt.includes(evt.code.toLowerCase()) && !filterEvt.length == 0) return;
let channel = discord.channels.cache.get(row.channelid); let channel = discord.channels.cache.get(row.channelid);
if (!channel) return console.log(`${colors.red("[ERROR]")} Channel ${row.channelid} not found`); if (!channel) return console.log(`${colors.red("[ERROR]")} Channel ${row.channelid} not found`);
@ -424,7 +424,7 @@ xmpp.on("stanza", (stanza) => {
fetch(`https://mesonet.agron.iastate.edu/api/1/nwstext/${product_id_raw}`).then((res) => { fetch(`https://mesonet.agron.iastate.edu/api/1/nwstext/${product_id_raw}`).then((res) => {
// If neither the body nor the product text contains the filter, ignore it // If neither the body nor the product text contains the filter, ignore it
res.text().then((text) => { res.text().then((text) => {
if (!filters.some((filter) => body.includes(filter)) && !filters.some((filter) => text.includes(filter))) return; if (!filters.some((filter) => body.toLowerCase().includes(filter)) && !filters.some((filter) => text.toLowerCase().includes(filter))) return;
thisMsg = JSON.parse(JSON.stringify(discordMsg)); thisMsg = JSON.parse(JSON.stringify(discordMsg));
thisMsg.content = row.custommessage || null; thisMsg.content = row.custommessage || null;
channel.send(thisMsg).catch((err) => { channel.send(thisMsg).catch((err) => {
@ -448,14 +448,14 @@ xmpp.on("stanza", (stanza) => {
// Get Filters as arrays // Get Filters as arrays
if (!row.filterEvt) row.filterEvt = ""; if (!row.filterEvt) row.filterEvt = "";
if (!row.filter) row.filter = ""; if (!row.filter) row.filter = "";
let filterEvt = row.filterEvt.split(","); let filterEvt = row.filterEvt.toLowerCase().split(",");
let filters = row.filter.split(","); let filters = row.filter.toLowerCase().split(",");
// If priority is less than the min priority, ignore it // If priority is less than the min priority, ignore it
if (evt.priority < row.minPriority) return; if (evt.priority < row.minPriority) return;
// If the event type is not in th filter, ignore it. Make sure filterEvt isnt null // If the event type is not in th filter, ignore it. Make sure filterEvt isnt null
if (!filterEvt[0]) filterEvt = []; if (!filterEvt[0]) filterEvt = [];
if (!filterEvt.includes(evt.code) && !filterEvt.length == 0) return; if (!filterEvt.includes(evt.code.toLowerCase()) && !filterEvt.length == 0) return;
let user = discord.users.cache.get(row.userid); let user = discord.users.cache.get(row.userid);
if (!user) return console.log(`${colors.red("[ERROR]")} User ${row.userid} not found`); if (!user) return console.log(`${colors.red("[ERROR]")} User ${row.userid} not found`);
@ -464,7 +464,7 @@ xmpp.on("stanza", (stanza) => {
fetch(`https://mesonet.agron.iastate.edu/api/1/nwstext/${product_id_raw}`).then((res) => { fetch(`https://mesonet.agron.iastate.edu/api/1/nwstext/${product_id_raw}`).then((res) => {
// If neither the body nor the product text contains the filter, ignore it // If neither the body nor the product text contains the filter, ignore it
res.text().then((text) => { res.text().then((text) => {
if (!filters.some((filter) => body.includes(filter)) && !filters.some((filter) => text.includes(filter))) return; if (!filters.some((filter) => body.toLowerCase().includes(filter)) && !filters.some((filter) => text.toLowerCase().includes(filter))) return;
thisMsg = JSON.parse(JSON.stringify(discordMsg)); thisMsg = JSON.parse(JSON.stringify(discordMsg));
thisMsg.content = row.custommessage || null; thisMsg.content = row.custommessage || null;
user.send(thisMsg).catch((err) => { user.send(thisMsg).catch((err) => {