Skip to content
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

Bridge IRC join/part/quit messages to Discord #207

Merged
merged 20 commits into from
Mar 30, 2017

Conversation

Throne3d
Copy link
Collaborator

@Throne3d Throne3d commented Mar 26, 2017

As in PR #40, this bridges the join/part/quit messages from IRC to Discord. It builds on that PR (thanks, @Ratismal), rebasing it onto master (and accidentally doing something stupid in the rebase, which a later commit fixes).

This adds two config settings:

  • disableJoinPartMsgs – if set to true, the bot won't announce any ircStatusNotices – if set to true, the bot will announce join/part/quit messages (if not set, overrides below)
  • announceSelfJoin – if set to true, the bot will announce itself (by default it skips any join events involving itself)

There are tests to ensure it works appropriately, and manual testing seems to show it working well. I hope this PR has more of a chance of getting merged?

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.4%) to 95.954% when pulling 6f8e8fb on Throne3d:add/joinpart into 26626e5 on reactiflux:master.

@Throne3d
Copy link
Collaborator Author

Hmm, coverage decreased somewhere. I'll look into fixing that.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 97.11% when pulling 13ef998 on Throne3d:add/joinpart into 26626e5 on reactiflux:master.

@Throne3d
Copy link
Collaborator Author

It looks like the only lines missed now are if (discordChannelName) { (a branch, [[27,1]]) and .filter(c => c.type === 'text'), same as in the regular sendToDiscord function.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 97.093% when pulling 9b4cfa2 on Throne3d:add/joinpart into 26626e5 on reactiflux:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 97.674% when pulling 5c8c57f on Throne3d:add/joinpart into 26626e5 on reactiflux:master.

@Throne3d
Copy link
Collaborator Author

The test description of should not send messages to discord if the channel isn't in the channel mapping was inaccurate, seeing as how "#notinchannel": "#otherIRC" is in fact in the channel mapping. I've updated the test name and created an actual test for a channel not in the mapping (#no-irc). (This has a side benefit of testing getDiscordChannelFor more thoroughly and hence overall increasing coverage.)

lib/bot.js Outdated
@@ -98,6 +100,24 @@ class Bot {
this.sendToDiscord(author, to, `*${text}*`);
});

this.ircClient.on('join', (channel, nick) => {
if (this.disableJoinPartMsgs) return;
if (nick === this.nickname && !this.announceSelfJoin) return;
Copy link
Member

Choose a reason for hiding this comment

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

Didn't know you'd receive join events for yourself. Do we need a configuration option for this though? There's already quite a lot of configuration possible, so maybe it would be better to just keep this off.

Copy link

@RoyCurtis RoyCurtis Mar 29, 2017

Choose a reason for hiding this comment

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

Personally, I found this useful to have on. If the bot had to reconnect for some reason (e.g. config change, lost connection to IRC), the self join message acts as a ping to others in the channel, that the IRC bridge is re-established and ready.

That said, it's currently only half-useful as disconnects are not mentioned in-channel, meaning users won't be aware that the bridge is suddenly unavailable for whatever reason. ^1

Edit: I suppose this could be handled as a separate feature, where the bot can itself announce when the bridge is up or down...


^1 This is not obvious in Discord; users don't think to check that the bot is online in the right sidebar

Copy link
Member

Choose a reason for hiding this comment

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

I see. Could keep it as a non-documented option, but as you're saying I think it might make more sense to print something like The bot has joined the IRC channel. then. Not sure how you'd be able to announce if the bridge is down though, as I think most issues with crashes have been on the Discord side (i.e. timing out and not reconnecting), but I guess you could at least print if the IRC connection goes offline. Seems a bit of an edge case though.

Choose a reason for hiding this comment

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

Indeed; in my edge case, I want to avoid the rare instances where users may start having one-sided conversations into the void. But, so far, that has yet to happen. So maybe it is not a big enough deal :)

Copy link
Member

Choose a reason for hiding this comment

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

In that case, wouldn't it make more sense to save up messages and send them when the IRC connection comes online? Maybe not if it's more than say 10 messages, but in your case I guess it could be a useful feature. Might not be worth the extra code though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure what to do in response to this – should I leave it as is for now, or…?

lib/bot.js Outdated
}

/* Sends a message to Discord exactly as it appears */
sendSpecialToDiscord(channel, text) {
Copy link
Member

Choose a reason for hiding this comment

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

Hm, is there any reason this can't just use sendToDiscord as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was mostly just doing this since the other PR did – should I add a boolean flag to display it differently, or…?

Copy link
Member

Choose a reason for hiding this comment

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

Never mind, I was a bit confused since I forgot that we append usernames to the messages even when sent to discord (slack-irc doesn't). The current approach makes sense. Could maybe call it something like sendExactToDiscord though. Also, getDiscordChannelFor -> findDiscordChannel/getDiscordChannel or something like that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed to sendExactToDiscord and findDiscordChannel.

lib/bot.js Outdated
@@ -32,6 +32,8 @@ class Bot {
this.commandCharacters = options.commandCharacters || [];
this.ircNickColor = options.ircNickColor !== false; // default to true
this.channels = _.values(options.channelMapping);
this.disableJoinPartMsgs = options.disableJoinPartMsgs;
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding a configuration option! I think it would be better to default it to off though, as that's the current behavior. slack-irc uses an object for this, so you can choose to enable joins and leaves selectively:
image

I'm not sure if that's really necessary though, a single option might be more than enough. Maybe just ircStatusNotices: true.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've converted it to a single ircStatusNotices config.

@Throne3d
Copy link
Collaborator Author

(Rebased onto master, rebased to change the config disableJoinPartMsgs → (!)ircStatusNotices everywhere, committed a change for sendSpecialToDiscordsendExactToDiscord and getDiscordChannelForfindDiscordChannel.)

@coveralls
Copy link

coveralls commented Mar 29, 2017

Coverage Status

Coverage increased (+0.2%) to 98.039% when pulling 12ae0fc on Throne3d:add/joinpart into 9915db1 on reactiflux:master.

@ekmartin
Copy link
Member

Looks good! Wanna add a line to the advanced example configuration in the README with ircStatusNotices?

@Throne3d
Copy link
Collaborator Author

Done (and fixed a merge conflict after #204 was merged).

@coveralls
Copy link

coveralls commented Mar 30, 2017

Coverage Status

Coverage increased (+0.2%) to 98.14% when pulling f996405 on Throne3d:add/joinpart into 1a7ea2d on reactiflux:master.

@Throne3d
Copy link
Collaborator Author

Partially solves #92?

@ekmartin ekmartin merged commit c9fa8ba into reactiflux:master Mar 30, 2017
@ekmartin
Copy link
Member

Thanks! I'll publish a release with the recent changes in the next few days.

@Throne3d Throne3d deleted the add/joinpart branch March 30, 2017 23:21
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.

5 participants