github.com/meowstercatel/discordgo@v0.0.0-20250615204139-29b43d676735/message_test.go (about) 1 package discordgo 2 3 import ( 4 "testing" 5 ) 6 7 func TestContentWithMoreMentionsReplaced(t *testing.T) { 8 s := &Session{StateEnabled: true, State: NewState()} 9 10 user := &User{ 11 ID: "user", 12 Username: "User Name", 13 } 14 15 s.State.GuildAdd(&Guild{ID: "guild"}) 16 s.State.RoleAdd("guild", &Role{ 17 ID: "role", 18 Name: "Role Name", 19 Mentionable: true, 20 }) 21 s.State.MemberAdd(&Member{ 22 User: user, 23 Nick: "User Nick", 24 GuildID: "guild", 25 }) 26 s.State.ChannelAdd(&Channel{ 27 Name: "Channel Name", 28 GuildID: "guild", 29 ID: "channel", 30 }) 31 m := &Message{ 32 Content: "<@&role> <@!user> <@user> <#channel>", 33 ChannelID: "channel", 34 MentionRoles: []string{"role"}, 35 Mentions: []*User{user}, 36 } 37 if result, _ := m.ContentWithMoreMentionsReplaced(s); result != "@Role Name @User Nick @User Name #Channel Name" { 38 t.Error(result) 39 } 40 } 41 func TestGettingEmojisFromMessage(t *testing.T) { 42 msg := "test test <:kitty14:811736565172011058> <:kitty4:811736468812595260>" 43 m := &Message{ 44 Content: msg, 45 } 46 emojis := m.GetCustomEmojis() 47 if len(emojis) < 1 { 48 t.Error("No emojis found.") 49 return 50 } 51 52 } 53 54 func TestMessage_Reference(t *testing.T) { 55 m := &Message{ 56 ID: "811736565172011001", 57 GuildID: "811736565172011002", 58 ChannelID: "811736565172011003", 59 } 60 61 ref := m.Reference() 62 63 if ref.Type != 0 { 64 t.Error("Default reference type should be 0") 65 } 66 67 if ref.MessageID != m.ID { 68 t.Error("Message ID should be the same") 69 } 70 71 if ref.GuildID != m.GuildID { 72 t.Error("Guild ID should be the same") 73 } 74 75 if ref.ChannelID != m.ChannelID { 76 t.Error("Channel ID should be the same") 77 } 78 } 79 80 func TestMessage_Forward(t *testing.T) { 81 m := &Message{ 82 ID: "811736565172011001", 83 GuildID: "811736565172011002", 84 ChannelID: "811736565172011003", 85 } 86 87 ref := m.Forward() 88 89 if ref.Type != MessageReferenceTypeForward { 90 t.Error("Reference type should be 1 (forward)") 91 } 92 93 if ref.MessageID != m.ID { 94 t.Error("Message ID should be the same") 95 } 96 97 if ref.GuildID != m.GuildID { 98 t.Error("Guild ID should be the same") 99 } 100 101 if ref.ChannelID != m.ChannelID { 102 t.Error("Channel ID should be the same") 103 } 104 } 105 106 func TestMessageReference_DefaultTypeIsDefault(t *testing.T) { 107 r := MessageReference{} 108 if r.Type != MessageReferenceTypeDefault { 109 t.Error("Default message type should be MessageReferenceTypeDefault") 110 } 111 }