Replace multiple replaces with one regex replace.

This commit is contained in:
Chris Rhodes 2016-05-03 20:51:04 -07:00
parent aede29500f
commit 96bcdc00a5

View file

@ -11,7 +11,7 @@ package discordgo
import (
"fmt"
"strings"
"regexp"
)
// A Message stores all data related to a specific Discord message.
@ -76,10 +76,7 @@ func (m *Message) ContentWithMentionsReplaced() string {
}
content := m.Content
for _, user := range m.Mentions {
content = strings.Replace(content, fmt.Sprintf("<@%s>", user.ID),
fmt.Sprintf("@%s", user.Username), -1)
content = strings.Replace(content, fmt.Sprintf("<@!%s>", user.ID),
fmt.Sprintf("@%s", user.Username), -1)
content = regexp.MustCompile(fmt.Sprintf("<@!?(%s)>", user.ID)).ReplaceAllString(content, "@"+user.Username)
}
return content
}