diff --git a/lib/bot.js b/lib/bot.js index 13f1922..b384b3c 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -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, @@ -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); } });