SkyTech6 / INATBot

The Automated Moderation Bot for the r/INAT Community.
3 stars 1 forks source link

MMO Triggered on Word Partial #14

Closed SkyTech6 closed 3 years ago

SkyTech6 commented 3 years ago

Words like "accommodate" would trigger the includes conditional. Will need to change to something like this

let x = "accommodate";
let res =  x.split(/[\s,\?\,\.!]+/).some(f=> f === 'mmo');
console.log(res);
SkyTech6 commented 3 years ago
const checkWords = (str, word) => {
        return str.split(/[\s,\?\,\.!]+/).some(f => word.test(f));
}

let x = "mmorpg are hype";
console.log(checkWords(x, /[mmo|mmos|mmorpg]/));
SkyTech6 commented 3 years ago

Ended up going with a specified regex expression due to partial matches with the above function returning true. Plus the compute time is only a 3% difference.