From 67299820cba06b45f710d742cec81cc601c5d838 Mon Sep 17 00:00:00 2001 From: "Chapman, Christopher" Date: Wed, 24 May 2017 23:22:02 -0700 Subject: [PATCH 1/3] Initial fix --- src/bot.coffee | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bot.coffee b/src/bot.coffee index 10a67f5a..3925a4ae 100644 --- a/src/bot.coffee +++ b/src/bot.coffee @@ -35,6 +35,10 @@ class SlackBot extends Adapter constructor: (@robot, @options) -> @client = new SlackClient(@options, @robot) + ### + Slackbot reload users timeout (reloads every 1 hour) + ### + setLastTimeUsersUpdated: (@lastTimeUsersUpdated) -> ### Slackbot initialization @@ -54,8 +58,12 @@ class SlackBot extends Adapter @client.on 'user_change', @userChange @client.web.users.list @loadUsers + @robot.brain.on 'loaded', () => - @client.web.users.list @loadUsers + if not @lastTimeUsersUpdated or (((new Date) - @lastTimeUsersUpdated) > (60 * 60 * 1000)) + @client.web.users.list @loadUsers + this.setLastTimeUpdated(new Date) + # Start logging in @client.connect() From 115f00e37705e9b5137988890e9002252985d72a Mon Sep 17 00:00:00 2001 From: "Chapman, Christopher" Date: Sun, 6 Aug 2017 16:53:01 -0700 Subject: [PATCH 2/3] Updating pull request --- src/bot.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bot.coffee b/src/bot.coffee index 3925a4ae..448407fc 100644 --- a/src/bot.coffee +++ b/src/bot.coffee @@ -38,7 +38,7 @@ class SlackBot extends Adapter ### Slackbot reload users timeout (reloads every 1 hour) ### - setLastTimeUsersUpdated: (@lastTimeUsersUpdated) -> + setIsLoaded: (@isLoaded) -> ### Slackbot initialization @@ -60,9 +60,9 @@ class SlackBot extends Adapter @client.web.users.list @loadUsers @robot.brain.on 'loaded', () => - if not @lastTimeUsersUpdated or (((new Date) - @lastTimeUsersUpdated) > (60 * 60 * 1000)) + if not @isLoaded @client.web.users.list @loadUsers - this.setLastTimeUpdated(new Date) + this.setIsLoaded(true) # Start logging in From 5a1753a7b06f5acf724958b872eec1ff794a2a59 Mon Sep 17 00:00:00 2001 From: Ankur Oberoi Date: Mon, 21 Aug 2017 16:09:43 -0700 Subject: [PATCH 3/3] fix/add comments --- src/bot.coffee | 4 +++- src/client.coffee | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bot.coffee b/src/bot.coffee index 24acebc2..f99096b1 100644 --- a/src/bot.coffee +++ b/src/bot.coffee @@ -37,7 +37,9 @@ class SlackBot extends Adapter @client = new SlackClient(@options, @robot) ### - Slackbot reload users timeout (reloads every 1 hour) + Slackbot loads full user list on the first brain load + QUESTION: why do brain adapters trigger a brain 'loaded' event each time a key + is set? ### setIsLoaded: (@isLoaded) -> diff --git a/src/client.coffee b/src/client.coffee index 729354fc..86611c46 100644 --- a/src/client.coffee +++ b/src/client.coffee @@ -31,6 +31,7 @@ class SlackClient Open connection to the Slack RTM API ### connect: -> + # QUESTION: why do we throw away the login data? @rtm.login()