I'm working on a twitch bot and I'm currently trying to get the bot to welcome people to the stream, problem is, one of the emote is "HeyGuys" and typing this emote alone would trigger him as there is both "hey" and "guys", so I wanted to use regexp to look at the entire word to fix that, but now, it triggers everytime!
here's the code:
var welcomed;
function checkWelcomeMsg(channel, msg, usr) {
welcomed = false;
for(var i = 0; i < welcome.length; i++) {
if(new RegExp('\\b' + welcome[i] + '\\b') && !welcomed) {
for(var i = 0; i < chatNames.length; i++) {
if(new RegExp('\\b' + chatNames[i] + '\\b')) {
console.log(getRandomResponse(greetings)+usr.username+"!");
welcomed = true;
console.log(welcomed);
break;
}
}
}
}
}
and here are the arrays that the code is looking at:
//Welcome; Thanks; Goodbye syntaxes
var welcome = ["hi", "hey", "hello", "o/", "HeyGuys", ];
var chatNames = ["chat", "everybody", "people", "everyone", "guys"];
//Responses
var greetings = ["Hello ", "HeyGuys ", "Hey "];
the code looks at all the messages for one with both a word from "welcome" and "chatNames" and chooses a random answer from "greetings"
putting console.log after the if statements gave me "\bhi\b" and "\bchat\b" everytime I typed something in chat