Add a method on Message to replace mentions with usernames.

This commit is contained in:
Chris Rhodes 2015-12-31 18:20:48 -08:00
parent 50bf4c7bac
commit ce0d4e5ee3

View file

@ -13,7 +13,9 @@ package discordgo
import ( import (
"encoding/json" "encoding/json"
"fmt"
"net" "net"
"strings"
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
@ -97,6 +99,16 @@ type Message struct {
ChannelID string `json:"channel_id"` ChannelID string `json:"channel_id"`
} }
// ContentWithMentionsReplaced will replace all @<id> 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. // An Attachment stores data for message attachments.
type Attachment struct { //TODO figure this out type Attachment struct { //TODO figure this out
} }