message.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 {
  28. Width int `json:"width"`
  29. URL string `json:"url"`
  30. Size int `json:"size"`
  31. ProxyURL string `json:"proxy_url"`
  32. ID string `json:"id"`
  33. Height int `json:"height"`
  34. Filename string `json:"filename"`
  35. }
  36. // An Embed stores data for message embeds.
  37. type Embed struct { // TODO figure this out
  38. }
  39. // ContentWithMentionsReplaced will replace all @<id> mentions with the
  40. // username of the mention.
  41. func (m *Message) ContentWithMentionsReplaced() string {
  42. content := m.Content
  43. for _, user := range m.Mentions {
  44. content = strings.Replace(content, fmt.Sprintf("<@%s>", user.ID),
  45. fmt.Sprintf("@%s", user.Username), -1)
  46. }
  47. return content
  48. }