hey, just getting back into JS after about 4 years and thought a twitch bot would be a fun way to do that.
I am trying to greet a user the first time they chat in a specific channel, i originally got the bot to chat but if the same user went to another channel the bot was on they would not be greeted there. i am having trouble figuring out how to achieve this, code below and im sure there is a better way to go about it than what i am trying. please let me know if i left out any key info
const twitchJs = require('twitch-js');
const options = {
options: {
debug: true,
},
connection: {
cluster: 'aws',
reconnect: true,
},
identity: {
username: 'bot',
password: 'oauth:oathHere'
},
channels: channelList,
};
const client = new twitchJs.client(options);
client.connect();
client.on('connected', (address, port) => {
client.action(this.channelList, 'Hello, bot has connected.');
});
var channelList = ['channel1','channel2', 'channel3', 'channel4'];
const greetings = [' what it do yo, wassup?!', ' hello, welcome to the stream!', ' where have you been all my life?', ' about damn time you showed that beautiful face!'];
//create greeted viewers arrays for each channel
const guByChannel = {};
for (i=0; i<channelList.length; i++) {
guByChannel[i] = {channelName: channelList[i],
greetedUsers: [],
greet: client.on('chat', (channel, user, message, self) => {
if (self) return;
if (this.guByChannel[greetedUsers].indexOf(user.username) === -1) {
client.say(channel, '@' + user.username + greetings[Math.floor(
Math.random() * greetings.length)]);
this.guByChannel[greetedUsers].push(user.username);
console.log(this.greetedUsers);
}
})
}
};
2 things to add/edits: figured out formatting. on chat this throws an error of “greetedUsers is not defined” so i either need a better way (using the api) to access first time chatters, or a JS answer for accessing the greetedUsers property.