Skip to content

Commit

Permalink
swaps out rtm message subtypes for discreet messages for enter and le…
Browse files Browse the repository at this point in the history
…ave, fixes #296
  • Loading branch information
aoberoi committed Jul 17, 2018
1 parent 9ced7fc commit 8bba532
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SlackBot extends Adapter
@client.loadUsers @usersLoaded
else
@isLoaded = true

# Brain will emit 'loaded' the first time it connects to its storage and then again each time a key is set
@robot.brain.on "loaded", () =>
if not @brainIsLoaded
Expand Down Expand Up @@ -239,16 +239,6 @@ class SlackBot extends Adapter
@receive message
)

# NOTE: channel_join should be replaced with a member_joined_channel event
when "channel_join", "group_join"
@robot.logger.debug "Received enter message for user: #{user.id}, joining: #{channel}"
@receive new EnterMessage user

# NOTE: channel_leave should be replaced with a member_left_channel event
when "channel_leave", "group_leave"
@robot.logger.debug "Received leave message for user: #{user.id}, leaving: #{channel}"
@receive new LeaveMessage user

when "channel_topic", "group_topic"
@robot.logger.debug "Received topic change message in conversation: #{channel}, new topic: #{event.topic}, set by: #{user.id}"
@receive new TopicMessage user, event.topic, event.ts
Expand All @@ -260,6 +250,18 @@ class SlackBot extends Adapter
@receive message
)

else if event.type is "member_joined_channel"
# this event type always has a channel
user.room = channel
@robot.logger.debug "Received enter message for user: #{user.id}, joining: #{channel}"
@receive new EnterMessage user

else if event.type is "member_left_channel"
# this event type always has a channel
user.room = channel
@robot.logger.debug "Received leave message for user: #{user.id}, joining: #{channel}"
@receive new LeaveMessage user

else if event.type is "reaction_added" or event.type is "reaction_removed"

# Once again Hubot expects all user objects to have a room property that is used in the envelope for the message
Expand Down
2 changes: 2 additions & 0 deletions src/client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class SlackClient
@rtm.on "reaction_added", @eventWrapper, this
@rtm.on "reaction_removed", @eventWrapper, this
@rtm.on "presence_change", @eventWrapper, this
@rtm.on "member_joined_channel", @eventWrapper, this
@rtm.on "member_left_channel", @eventWrapper, this
@rtm.on "user_change", @updateUserInBrain, this
@eventHandler = undefined

Expand Down

0 comments on commit 8bba532

Please sign in to comment.