Skip to content

Commit

Permalink
Option to set IRC users to away, closes ekmartin#10
Browse files Browse the repository at this point in the history
  • Loading branch information
lmtierney committed Sep 14, 2016
1 parent b8224ff commit 2ab74a2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 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.disconnectOnAway = options.disconnectOnAway || false;
this.ircTimeout = options.ircTimeout || 120; // Seconds

const ircOptions = {
Expand Down Expand Up @@ -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);
}
}
});

Expand Down

0 comments on commit 2ab74a2

Please sign in to comment.