Skip to content

Commit

Permalink
Fix username of bot
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbruinsslot committed May 11, 2019
1 parent 9d5e850 commit 609c37c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions service/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,19 +403,25 @@ func (s *SlackService) CreateMessage(message slack.Message, channelID string) co

// Get username from cache
name, ok := s.UserCache[message.User]
name, ok = s.UserCache[message.BotID]

// Name not in cache
if !ok {
if message.BotID != "" {
// Bot, not in cache get bot info
bot, err := s.Client.GetBotInfo(message.BotID)
if err != nil {
name = "unkown"
s.UserCache[message.BotID] = name
} else {
name = bot.Name
s.UserCache[message.BotID] = bot.Name
name, ok = s.UserCache[message.BotID]
if !ok {
if message.Username != "" {
name = message.Username
s.UserCache[message.BotID] = message.Username
} else {
bot, err := s.Client.GetBotInfo(message.BotID)
if err != nil {
name = "unkown"
s.UserCache[message.BotID] = name
} else {
name = bot.Name
s.UserCache[message.BotID] = bot.Name
}
}
}
} else {
// Not a bot, not in cache, get user info
Expand Down

0 comments on commit 609c37c

Please sign in to comment.