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