Skip to content

Commit

Permalink
Handle existing hubot brains with incomplete user data
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhammond committed Dec 17, 2014
1 parent 7284bba commit c9f6870
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/slack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SlackBot extends Adapter
@client.on 'close', @.close
@client.on 'message', @.message
@client.on 'userChange', @.userChange
@robot.brain.on 'loaded', @.brainLoaded

# Start logging in
@client.login()
Expand All @@ -54,6 +55,15 @@ class SlackBot extends Adapter
for id, user of @client.users
@userChange user

brainLoaded: =>
# once the brain has loaded, reload all the users from the client
for id, user of @client.users
@userChange user

# also wipe out any broken users stored under usernames instead of ids
for id, user of @robot.brain.data.users
if id is user.name then delete @robot.brain.data.users[user.id]

userChange: (user) =>
newUser = {name: user.name, email_address: user.profile.email}
if user.id of @robot.brain.data.users
Expand Down

0 comments on commit c9f6870

Please sign in to comment.