Skip to content

Commit

Permalink
[MM-414] Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
raghavaggarwal2308 committed Apr 25, 2024
1 parent 3611e2f commit 0472206
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions server/welcomebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,22 @@ func (p *Plugin) processActionMessage(messageTemplate MessageTemplate, action *A
}

func (p *Plugin) joinChannel(action *Action, channelName string) {
user, appErr := p.API.GetUser(action.Context.UserID)
if appErr != nil {
p.API.LogError("Couldn't get user details. UserID: `%s` Error: `%s`", action.Context.UserID, appErr.Error())
user, err := p.client.User.Get(action.Context.UserID)
if err != nil {
p.client.Log.Error("Couldn't get user details", "user_id", action.Context.UserID, "error", err.Error())
return
}
if user.IsBot {
p.API.LogInfo("Skipping adding this user to the channel since it is a bot. UserID: `%s`", action.Context.UserID)
p.client.Log.Info("Skipping adding this user to the channel since it is a bot.", "user_id", action.Context.UserID)
return
}

if channel, err := p.API.GetChannelByName(action.Context.TeamID, channelName, false); err == nil {
if _, err := p.API.AddChannelMember(channel.Id, action.Context.UserID); err != nil {
p.API.LogError("Couldn't add user to the channel, continuing to next channel. UserID: `%s` ChannelID: `%s`", action.Context.UserID, channel.Id)
if channel, err := p.client.Channel.GetByName(action.Context.TeamID, channelName, false); err == nil {
if _, err = p.client.Channel.AddMember(channel.Id, action.Context.UserID); err != nil {
p.client.Log.Error("Couldn't add user to the channel, continuing to the next channel", "user_id", action.Context.UserID, "channel_id", channel.Id, "error", err.Error())
return
}
} else {
p.API.LogError("Failed to get channel, continuing to the next channel. ChannelName: `%s` UserID: `%s`", channelName, action.Context.UserID)
p.client.Log.Error("Failed to get the channel, continuing to the next channel.", "channel_name", channelName, "user_id", action.Context.UserID, "error", err.Error())
}
}

0 comments on commit 0472206

Please sign in to comment.