Skip to content

Commit

Permalink
Add disconnect timeout to prevent join/leave spam, closes ekmartin#7
Browse files Browse the repository at this point in the history
  • Loading branch information
lmtierney committed Sep 10, 2016
1 parent 2baff0a commit fc24f49
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Bot {
this.muteSlackbot = options.muteSlackbot || false;
this.nickSuffix = options.userNickSuffix || '-sl';
this.nickRegex = new RegExp(`@?(\\S+${this.nickSuffix}\\d?)`, 'g');
this.ircTimeout = options.ircTimeout || 120; // Seconds

const ircOptions = {
userName: this.nickname,
Expand Down Expand Up @@ -129,10 +130,17 @@ class Bot {
const user = dataStore.getUserById(event.user);
logger.debug(`Slack user ${user.name} status changed to ${event.presence}.`);
if (this.isBot(user.id)) return;
const client = this.ircClients[user.id];
if (event.presence === 'active') {
this.connectNewClient(user);
} else {
this.deleteClient(user, `User ${user.name} went away.`);
if (client == null) {
this.connectNewClient(user);
} else {
clearTimeout(client.timer);
}
} else if (client != null) {
this.ircClients[user.id].timer = setTimeout(() => {
this.deleteClient(user, `Slack user ${user.name} went away.`);
}, this.ircTimeout * 1000);
}
});

Expand Down

0 comments on commit fc24f49

Please sign in to comment.