-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
message.go
168 lines (130 loc) · 4.37 KB
/
message.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package discord
import "github.com/diamondburned/arikawa/utils/json/enum"
type Message struct {
ID Snowflake `json:"id,string"`
Type MessageType `json:"type"`
ChannelID Snowflake `json:"channel_id,string"`
GuildID Snowflake `json:"guild_id,string,omitempty"`
// The author object follows the structure of the user object, but is only
// a valid user in the case where the message is generated by a user or bot
// user. If the message is generated by a webhook, the author object
// corresponds to the webhook's id, username, and avatar. You can tell if a
// message is generated by a webhook by checking for the webhook_id on the
// message object.
Author User `json:"author"`
Content string `json:"content"`
Timestamp Timestamp `json:"timestamp,omitempty"`
EditedTimestamp Timestamp `json:"edited_timestamp,omitempty"`
TTS bool `json:"tts"`
Pinned bool `json:"pinned"`
// The user objects in the mentions array will only have the partial
// member field present in MESSAGE_CREATE and MESSAGE_UPDATE events from
// text-based guild channels.
Mentions []GuildUser `json:"mentions"`
MentionRoleIDs []Snowflake `json:"mention_roles"`
MentionEveryone bool `json:"mention_everyone"`
// Not all channel mentions in a message will appear in mention_channels.
MentionChannels []ChannelMention `json:"mention_channels,omitempty"`
Attachments []Attachment `json:"attachments"`
Embeds []Embed `json:"embeds"`
Reactions []Reaction `json:"reactions,omitempty"`
// Used for validating a message was sent
Nonce string `json:"nonce,omitempty"`
WebhookID Snowflake `json:"webhook_id,string,omitempty"`
Activity *MessageActivity `json:"activity,omitempty"`
Application *MessageApplication `json:"application,omitempty"`
Reference *MessageReference `json:"message_reference,omitempty"`
Flags MessageFlags `json:"flags"`
}
// URL generates a Discord client URL to the message. If the message doesn't
// have a GuildID, it will generate a URL with the guild "@me".
func (m Message) URL() string {
var head = "https://discordapp.com/channels/"
var tail = "/" + m.ChannelID.String() + "/" + m.ID.String()
if !m.GuildID.Valid() {
return head + "@me" + tail
}
return head + m.GuildID.String() + tail
}
type MessageType uint8
const (
DefaultMessage MessageType = iota
RecipientAddMessage
RecipientRemoveMessage
CallMessage
ChannelNameChangeMessage
ChannelIconChangeMessage
ChannelPinnedMessage
GuildMemberJoinMessage
NitroBoostMessage
NitroTier1Message
NitroTier2Message
NitroTier3Message
ChannelFollowAddMessage
GuildDiscoveryDisqualifiedMessage
GuildDiscoveryRequalifiedMessage
)
type MessageFlags enum.Enum
var (
NullMessage MessageFlags = enum.Null
CrosspostedMessage MessageFlags = 1
MessageIsCrosspost MessageFlags = 2
SuppressEmbeds MessageFlags = 4
SourceMessageDeleted MessageFlags = 8
UrgentMessage MessageFlags = 16
)
type ChannelMention struct {
ChannelID Snowflake `json:"id,string"`
GuildID Snowflake `json:"guild_id,string"`
ChannelType ChannelType `json:"type"`
ChannelName string `json:"name"`
}
type GuildUser struct {
User
Member *Member `json:"member,omitempty"`
}
//
type MessageActivity struct {
Type MessageActivityType `json:"type"`
// From a Rich Presence event
PartyID string `json:"party_id,omitempty"`
}
type MessageActivityType uint8
const (
JoinMessage MessageActivityType = iota + 1
SpectateMessage
ListenMessage
JoinRequestMessage
)
//
type MessageApplication struct {
ID Snowflake `json:"id,string"`
CoverID string `json:"cover_image,omitempty"`
Description string `json:"description"`
Icon string `json:"icon"`
Name string `json:"name"`
}
//
type MessageReference struct {
ChannelID Snowflake `json:"channel_id,string"`
// Field might not be provided
MessageID Snowflake `json:"message_id,string,omitempty"`
GuildID Snowflake `json:"guild_id,string,omitempty"`
}
//
type Attachment struct {
ID Snowflake `json:"id,string"`
Filename string `json:"filename"`
Size uint64 `json:"size"`
URL URL `json:"url"`
Proxy URL `json:"proxy_url"`
// Only if Image
Height uint `json:"height,omitempty"`
Width uint `json:"width,omitempty"`
}
//
type Reaction struct {
Count int `json:"count"`
Me bool `json:"me"` // for current user
Emoji Emoji `json:"emoji"`
}