message_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. }
  37. func TestGettingEmojisFromMessage(t *testing.T) {
  38. msg := "test test <:kitty14:811736565172011058> <:kitty4:811736468812595260>"
  39. m := &Message{
  40. Content: msg,
  41. }
  42. emojis := m.GetCustomEmojis()
  43. if len(emojis) < 1 {
  44. t.Error("No emojis found.")
  45. return
  46. }
  47. }