Fix username of bot

This commit is contained in:
erroneousboat 2019-05-11 11:47:39 +02:00
parent 9d5e850495
commit 609c37cdfe

View File

@ -403,12 +403,16 @@ 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
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"
@ -417,6 +421,8 @@ func (s *SlackService) CreateMessage(message slack.Message, channelID string) co
name = bot.Name
s.UserCache[message.BotID] = bot.Name
}
}
}
} else {
// Not a bot, not in cache, get user info
user, err := s.Client.GetUserInfo(message.User)