message.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Discordgo - Discord bindings for Go
  2. // Available at https://github.com/bwmarrin/discordgo
  3. // Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
  4. // Use of this source code is governed by a BSD-style
  5. // license that can be found in the LICENSE file.
  6. // This file contains code related to the Message struct
  7. package discordgo
  8. import (
  9. "fmt"
  10. "strings"
  11. )
  12. // A Message stores all data related to a specific Discord message.
  13. type Message struct {
  14. ID string `json:"id"`
  15. Author *User `json:"author"`
  16. Content string `json:"content"`
  17. Attachments []*Attachment `json:"attachments"`
  18. Tts bool `json:"tts"`
  19. Embeds []*Embed `json:"embeds"`
  20. Timestamp string `json:"timestamp"`
  21. MentionEveryone bool `json:"mention_everyone"`
  22. EditedTimestamp string `json:"edited_timestamp"`
  23. Mentions []*User `json:"mentions"`
  24. ChannelID string `json:"channel_id"`
  25. }
  26. // An Attachment stores data for message attachments.
  27. type Attachment struct { //TODO figure this out
  28. }
  29. // An Embed stores data for message embeds.
  30. type Embed struct { // TODO figure this out
  31. }
  32. // ContentWithMentionsReplaced will replace all @<id> mentions with the
  33. // username of the mention.
  34. func (m *Message) ContentWithMentionsReplaced() string {
  35. content := m.Content
  36. for _, user := range m.Mentions {
  37. content = strings.Replace(content, fmt.Sprintf("<@%s>", user.ID),
  38. fmt.Sprintf("@%s", user.Username), -1)
  39. }
  40. return content
  41. }