Merge pull request #39 from iopred/mentions
Add a method on Message to replace mentions with usernames.
This commit is contained in:
commit
43bf17c302
1 changed files with 12 additions and 0 deletions
12
structs.go
12
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 @<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.
|
||||
type Attachment struct { //TODO figure this out
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue