Fix lookup bot username (slack). #213

This commit is contained in:
Wim 2017-07-16 14:18:33 +02:00
parent 4abaf2b236
commit 335ddf8db5

View File

@ -226,7 +226,8 @@ func (b *Bslack) handleSlack() {
text = b.replaceURL(text) text = b.replaceURL(text)
text = html.UnescapeString(text) text = html.UnescapeString(text)
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account) flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account)
b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Account: b.Account, Avatar: b.getAvatar(message.Username), UserID: message.UserID} msg := config.Message{Text: text, Username: message.Username, Channel: message.Channel, Account: b.Account, Avatar: b.getAvatar(message.Username), UserID: message.UserID}
b.Remote <- msg
} }
} }
} }
@ -249,24 +250,27 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {
if err != nil { if err != nil {
continue continue
} }
m := &MMMessage{}
if ev.BotID == "" {
user, err := b.rtm.GetUserInfo(ev.User) user, err := b.rtm.GetUserInfo(ev.User)
if err != nil { if err != nil {
continue continue
} }
m := &MMMessage{}
m.UserID = user.ID m.UserID = user.ID
m.Username = user.Name m.Username = user.Name
}
m.Channel = channel.Name m.Channel = channel.Name
m.Text = ev.Text m.Text = ev.Text
m.Raw = ev m.Raw = ev
m.Text = b.replaceMention(m.Text) m.Text = b.replaceMention(m.Text)
if ev.BotID != "" && user.Name == "" { if ev.BotID != "" {
bot, err := b.rtm.GetBotInfo(ev.BotID) bot, err := b.rtm.GetBotInfo(ev.BotID)
if err != nil { if err != nil {
continue continue
} }
if bot.Name != "" { if bot.Name != "" {
m.Username = bot.Name m.Username = bot.Name
m.UserID = bot.ID
} }
} }
mchan <- m mchan <- m