tmi.js icon indicating copy to clipboard operation
tmi.js copied to clipboard

Messages received after leaving a channel.

Open Felwin opened this issue 8 years ago • 4 comments

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?

Felwin avatar Jan 20 '17 11:01 Felwin

You trying something like this? https://docs.tmijs.org/v1.1.2/Commands.html#part

stachu540 avatar Jan 21 '17 06:01 stachu540

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.

Felwin avatar Jan 22 '17 09:01 Felwin

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
});

AlcaDesign avatar Jan 22 '17 09:01 AlcaDesign

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.

Felwin avatar Jan 22 '17 09:01 Felwin