Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
V4NSH4J
GitHub Repository: V4NSH4J/discord-mass-DM-GO
Path: blob/main/instance/protocol.go
310 views
1
// Copyright (C) github.com/dankgrinder & github.com/V4NSH4J
2
//
3
// This source code has been released under the GNU Affero General Public
4
// License v3.0. A copy of this license is available at
5
// https://www.gnu.org/licenses/agpl-3.0.en.html
6
7
package instance
8
9
import "time"
10
11
const (
12
OpcodeDispatch = iota
13
OpcodeHeartbeat
14
OpcodeIdentify
15
OpcodePresenceUpdate
16
OpcodeVoiceStateUpdate
17
OpcodeResume = iota + 1
18
OpcodeReconnect
19
OpcodeRequestGuildMembers
20
OpcodeInvalidSession
21
OpcodeHello
22
OpcodeHeartbeatACK
23
)
24
25
const (
26
EventNameMessageCreate = "MESSAGE_CREATE"
27
EventNameMessageUpdate = "MESSAGE_UPDATE"
28
EventNameReady = "READY"
29
EventNameResumed = "RESUMED"
30
)
31
32
type Intent int
33
34
// Constants for the different bit offsets of intents
35
const (
36
IntentsGuilds Intent = 1 << 0
37
IntentsGuildMembers Intent = 1 << 1
38
IntentsGuildBans Intent = 1 << 2
39
IntentsGuildEmojis Intent = 1 << 3
40
IntentsGuildIntegrations Intent = 1 << 4
41
IntentsGuildWebhooks Intent = 1 << 5
42
IntentsGuildInvites Intent = 1 << 6
43
IntentsGuildVoiceStates Intent = 1 << 7
44
IntentsGuildPresences Intent = 1 << 8
45
IntentsGuildMessages Intent = 1 << 9
46
IntentsGuildMessageReactions Intent = 1 << 10
47
IntentsGuildMessageTyping Intent = 1 << 11
48
IntentsDirectMessages Intent = 1 << 12
49
IntentsDirectMessageReactions Intent = 1 << 13
50
IntentsDirectMessageTyping Intent = 1 << 14
51
52
IntentsAllWithoutPrivileged = IntentsGuilds |
53
IntentsGuildBans |
54
IntentsGuildEmojis |
55
IntentsGuildIntegrations |
56
IntentsGuildWebhooks |
57
IntentsGuildInvites |
58
IntentsGuildVoiceStates |
59
IntentsGuildMessages |
60
IntentsGuildMessageReactions |
61
IntentsGuildMessageTyping |
62
IntentsDirectMessages |
63
IntentsDirectMessageReactions |
64
IntentsDirectMessageTyping
65
IntentsAll = IntentsAllWithoutPrivileged |
66
IntentsGuildMembers |
67
IntentsGuildPresences
68
IntentsNone Intent = 0
69
)
70
71
type Event struct {
72
Op int `json:"op"`
73
Data Data `json:"d,omitempty"`
74
Sequence int `json:"s,omitempty"`
75
EventName string `json:"t,omitempty"`
76
}
77
78
type Data struct {
79
Message
80
Identify
81
PresenceChange
82
ClientState ClientState `json:"client_state,omitempty"`
83
HeartbeatInterval int `json:"heartbeat_interval,omitempty"`
84
SessionID string `json:"session_id,omitempty"`
85
Sequence int `json:"seq,omitempty"` // For sending only
86
GuildId interface{} `json:"guild_id,omitempty"`
87
Channels map[string]interface{} `json:"channels,omitempty"`
88
Ops []Ops `json:"ops,omitempty"`
89
ChannelID string `json:"channel_id,omitempty"`
90
Members []Member `json:"members,omitempty"`
91
Typing bool `json:"typing,omitempty"`
92
Threads bool `json:"threads,omitempty"`
93
Activities bool `json:"activities,omitempty"`
94
ThreadMemberLists interface{} `json:"thread_member_lists,omitempty"`
95
// Emoji React
96
UserID string `json:"user_id,omitempty"`
97
Emoji Emoji `json:"emoji,omitempty"`
98
MessageID string `json:"message_id,omitempty"`
99
}
100
101
type Ops struct {
102
Items []Userinfo `json:"items,omitempty"`
103
Range interface{} `json:"range,omitempty"`
104
Op string `json:"op,omitempty"`
105
}
106
type Userinfo struct {
107
Member Member `json:"member,omitempty"`
108
}
109
type Member struct {
110
User User `json:"user,omitempty"`
111
Roles []string `json:"roles"`
112
PremiumSince interface{} `json:"premium_since"`
113
Pending bool `json:"pending"`
114
Nick string `json:"nick"`
115
Mute bool `json:"mute"`
116
JoinedAt time.Time `json:"joined_at"`
117
Flags int `json:"flags"`
118
Deaf bool `json:"deaf"`
119
CommunicationDisabledUntil interface{} `json:"communication_disabled_until"`
120
Avatar interface{} `json:"avatar"`
121
}
122
type User struct {
123
ID string `json:"id"`
124
Username string `json:"username"`
125
Discriminator string `json:"discriminator"`
126
Avatar string `json:"avatar"`
127
Bot bool `json:"bot"`
128
}
129
130
type Identify struct {
131
Token string `json:"token,omitempty"`
132
Properties Properties `json:"properties,omitempty"`
133
Capabilities int `json:"capabilities,omitempty"`
134
Compress bool `json:"compress,omitempty"`
135
Presence Presence `json:"presence,omitempty"`
136
}
137
138
type Presence struct {
139
Status string `json:"status,omitempty"`
140
Since int `json:"since,omitempty"`
141
Activities []string `json:"activities,omitempty"`
142
AFK bool `json:"afk,omitempty"`
143
}
144
145
type ClientState struct {
146
HighestLastMessageID string `json:"highest_last_message_id,omitempty"`
147
ReadStateVersion int `json:"read_state_version,omitempty"`
148
UserGuildSettingsVersion int `json:"user_guild_settings_version,omitempty"`
149
}
150
151
type Properties struct {
152
OS string `json:"os,omitempty"`
153
Browser string `json:"browser,omitempty"`
154
Device string `json:"device,omitempty"`
155
BrowserUserAgent string `json:"browser_user_agent,omitempty"`
156
BrowserVersion string `json:"browser_version,omitempty"`
157
OSVersion string `json:"os_version,omitempty"`
158
Referrer string `json:"referrer,omitempty"`
159
ReferringDomain string `json:"referring_domain,omitempty"`
160
ReferrerCurrent string `json:"referrer_current,omitempty"`
161
ReferringDomainCurrent string `json:"referring_domain_current,omitempty"`
162
ReleaseChannel string `json:"release_channel,omitempty"`
163
ClientBuildNumber int `json:"client_build_number,omitempty"`
164
}
165
166