diff --git a/structs.go b/structs.go index 0795f49..d51fcf2 100644 --- a/structs.go +++ b/structs.go @@ -13,7 +13,9 @@ package discordgo import ( "encoding/json" + "fmt" "net" + "strings" "time" "github.com/gorilla/websocket" @@ -99,6 +101,16 @@ type Message struct { ChannelID string `json:"channel_id"` } +// ContentWithMentionsReplaced will replace all @ mentions with the +// username of the mention. +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) + } + return content +} + // An Attachment stores data for message attachments. type Attachment struct { //TODO figure this out }