Skip to content

Fix IRC quit messages sending to all channels by tracking users #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2017

Conversation

Throne3d
Copy link
Collaborator

@Throne3d Throne3d commented Apr 4, 2017

Keep a list of users in each channel, using the names event in addition to the join/part events, so as to prevent spamming unnecessary channels when the quit event is raised with all channels from a server.

Fixes #213.

I'm not sure if this is a bug with node-irc (the quit event shouldn't be sent for all channels on that server, just the channels the user is in) or if it's intended behavior (the quit event is sent 'for the server', and so for all channels on it). Either way this is a workaround to make the new functionality… less spammy. I might report it there but they don't seem to have very active development.

This also rewrites a test name to make it fit into the syntax ("Bot Events should…") and reflect the new functionality: "should be possible to get the bot to announce itself joining" → "should announce the bot itself when config enabled".

Keep a list of users in each channel, using the names event
in addition to the join/part events, so as to prevent spamming
unnecessary channels when the quit event is raised with all
channels from a server.

Fixes reactiflux#213.
@Throne3d Throne3d self-assigned this Apr 4, 2017
@Throne3d Throne3d requested a review from ekmartin April 4, 2017 16:19
@coveralls
Copy link

coveralls commented Apr 4, 2017

Coverage Status

Coverage increased (+0.1%) to 98.238% when pulling 1c8fa12 on Throne3d:fix/quit-messages-all-channels into 27f9abe on reactiflux:master.

@ekmartin
Copy link
Member

ekmartin commented Apr 5, 2017

I can't think of a better way to fix this either - seems like it's a TODO in the node-irc codebase: https://github.com/martynsmith/node-irc/blob/master/lib/irc.js#L587-L592

I'm not sure if it's strictly worth it, but I think the implementation here is clean enough that we should include it. Maybe use a set instead of an array for the user lists though? That way you can use .add and .delete instead of needing to find the index etc.

@coveralls
Copy link

coveralls commented Apr 5, 2017

Coverage Status

Coverage increased (+0.08%) to 98.222% when pulling cc990d6 on Throne3d:fix/quit-messages-all-channels into 27f9abe on reactiflux:master.

@Throne3d
Copy link
Collaborator Author

Throne3d commented Apr 5, 2017

It doesn't even look like in their code they're trying to match if the user is in that channel – they just delete the user from the channel (whether they were there or not) and proceed to add it to the list, when I think they should be guarding by whether the object's key exists?

I've updated this to use sets – thanks, didn't realize they existed in JavaScript. (Or, well, ECMAScript 6?)

this.sendExactToDiscord(channel, `*${nick}* has left the channel (${reason})`);
});

this.ircClient.on('quit', (nick, reason, channels) => {
if (!this.ircStatusNotices || nick === this.nickname) return;
channels.forEach((channel) => {
if (!this.channelUsers[channel].delete(nick)) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever use of delete's return value :)

@ekmartin
Copy link
Member

ekmartin commented Apr 5, 2017

Ye, it indeed doesn't look like it attempts to find the correct username.
There's a couple of PRs to node-irc for the issue: martynsmith/node-irc#376 and martynsmith/node-irc#359

If they ever get merged we can remove this I guess.

@ekmartin ekmartin merged commit beb1b33 into reactiflux:master Apr 5, 2017
@ekmartin
Copy link
Member

ekmartin commented Apr 5, 2017

Released in 2.3.1 - thanks!

@Throne3d Throne3d deleted the fix/quit-messages-all-channels branch April 5, 2017 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants