tmi.js
tmi.js copied to clipboard
Messages received after leaving a channel.
Actual behaviour:
I detect that the stream is now offline (kraken API streamById return a null stream object), so a part() command is executed, no error occurred, but a minute later I got a new chat message coming from this channel.
Expected behaviour:
After leaving the channel I am expected to not get messages from it anymore.
Error log:
[10:13] info: Executing command: PART #c9sneaky
[10:13] info: Left #c9sneaky
[10:13] info: [#c9sneaky] <kthxxoxo>: (puke)
[10:14] info: [#c9sneaky] <oskomodo>: anyone here?
You trying something like this? https://docs.tmijs.org/v1.1.2/Commands.html#part
Yes, I am using this exact code to leave the channel. As you can see in the log the command PART is executed, the channel left, there is no other command executed (it would appear in the log) and yet I still got messages after that. This behavior not always happen, but happened more than one time. Every time it was with big busy channels.
I don't know if the module should filter those messages out, but you could do it yourself like this:
let joinedChannels = [];
client.on('join', (channel, username, self) => {
if(self && !joinedChannels.includes(channel)) {
joinedChannels.push(channel);
}
});
client.on('part', (channel, username, self) => {
if(self && joinedChannels.includes(channel)) {
joinedChannels.splice(joinedChannels.indexOf(channel), 1);
}
});
client.on('message', (channel, userstate, message, self) => {
if(self || !joinedChannels.includes(channel)) {
return;
}
// Code here
});
Yep, that's exactly what I am doing for now. :) However I don't think this is a normal behavior, it only happen sometimes with big channels, and I am afraid this could cause some performance issue if monitoring a lot of channels.