message_test.go 869 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package discordgo
  2. import (
  3. "testing"
  4. )
  5. func TestContentWithMoreMentionsReplaced(t *testing.T) {
  6. s := &Session{StateEnabled: true, State: NewState()}
  7. user := &User{
  8. ID: "user",
  9. Username: "User Name",
  10. }
  11. s.State.GuildAdd(&Guild{ID: "guild"})
  12. s.State.RoleAdd("guild", &Role{
  13. ID: "role",
  14. Name: "Role Name",
  15. Mentionable: true,
  16. })
  17. s.State.MemberAdd(&Member{
  18. User: user,
  19. Nick: "User Nick",
  20. GuildID: "guild",
  21. })
  22. s.State.ChannelAdd(&Channel{
  23. Name: "Channel Name",
  24. GuildID: "guild",
  25. ID: "channel",
  26. })
  27. m := &Message{
  28. Content: "<@&role> <@!user> <@user> <#channel>",
  29. ChannelID: "channel",
  30. MentionRoles: []string{"role"},
  31. Mentions: []*User{user},
  32. }
  33. if result, _ := m.ContentWithMoreMentionsReplaced(s); result != "@Role Name @User Nick @User Name #Channel Name" {
  34. t.Error(result)
  35. }
  36. }