From 2ab74a243ade2250d83dd062579294caedf58aff Mon Sep 17 00:00:00 2001 From: lmtierney Date: Wed, 14 Sep 2016 15:38:34 -0500 Subject: [PATCH] Option to set IRC users to away, closes #10 --- lib/bot.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index cdc0d7b..aa3f4e5 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.disconnectOnAway = options.disconnectOnAway || false; this.ircTimeout = options.ircTimeout || 120; // Seconds const ircOptions = { @@ -134,13 +135,20 @@ class Bot { if (event.presence === 'active') { if (client == null) { this.connectNewClient(user); - } else { + } else if (this.disconnectOnAway) { clearTimeout(client.timer); + } else { + client.send('AWAY'); } } else if (client != null) { - client.timer = setTimeout(() => { - this.deleteClient(user, `Slack user ${user.name} went away.`); - }, this.ircTimeout * 1000); + const awayMsg = `Slack user ${user.name} went away`; + if (this.disconnectOnAway) { + client.timer = setTimeout(() => { + this.deleteClient(user, awayMsg); + }, this.ircTimeout * 1000); + } else { + client.send('AWAY', awayMsg); + } } });