forked from pothtonswer/discordmuffin
Created message.go to store code related to the Message struct.
This commit is contained in:
parent
4f3b4b7a4b
commit
7fc9331e04
2 changed files with 26 additions and 10 deletions
26
message.go
Normal file
26
message.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Discordgo - Discord bindings for Go
|
||||
// Available at https://github.com/bwmarrin/discordgo
|
||||
|
||||
// Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// This file contains code related to the Message struct
|
||||
|
||||
package discordgo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
10
structs.go
10
structs.go
|
@ -116,16 +116,6 @@ 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