disgroove 2.2.1-dev.64c7abc → 2.2.1-dev.efad41d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/Client.d.ts +224 -227
- package/dist/lib/Client.js +402 -401
- package/dist/lib/constants.d.ts +5 -4
- package/dist/lib/constants.js +5 -4
- package/dist/lib/gateway/Shard.d.ts +14 -9
- package/dist/lib/gateway/Shard.js +157 -108
- package/dist/lib/rest/CDN.d.ts +20 -20
- package/dist/lib/rest/CDN.js +20 -20
- package/dist/lib/rest/Endpoints.d.ts +81 -81
- package/dist/lib/rest/Endpoints.js +91 -91
- package/dist/lib/types/application-command.d.ts +4 -4
- package/dist/lib/types/application.d.ts +2 -2
- package/dist/lib/types/audit-log.d.ts +5 -5
- package/dist/lib/types/auto-moderation.d.ts +3 -3
- package/dist/lib/types/channel.d.ts +23 -21
- package/dist/lib/types/entitlements.d.ts +6 -6
- package/dist/lib/types/gateway-events.d.ts +151 -67
- package/dist/lib/types/guild-scheduled-event.d.ts +5 -5
- package/dist/lib/types/guild-template.d.ts +2 -2
- package/dist/lib/types/guild.d.ts +17 -17
- package/dist/lib/types/interaction.d.ts +8 -8
- package/dist/lib/types/message-components.d.ts +4 -4
- package/dist/lib/types/poll.d.ts +1 -1
- package/dist/lib/types/role.d.ts +3 -3
- package/dist/lib/types/sku.d.ts +2 -2
- package/dist/lib/types/stage-instance.d.ts +3 -3
- package/dist/lib/types/sticker.d.ts +5 -5
- package/dist/lib/types/team.d.ts +2 -2
- package/dist/lib/types/user.d.ts +1 -1
- package/dist/lib/types/voice.d.ts +4 -4
- package/dist/lib/types/webhook.d.ts +3 -3
- package/dist/lib/utils/Util.d.ts +2 -2
- package/dist/lib/utils/Util.js +195 -193
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/lib/constants.d.ts
CHANGED
@@ -616,6 +616,7 @@ export declare enum StatusTypes {
|
|
616
616
|
}
|
617
617
|
/** https://discord.com/developers/docs/topics/gateway-events#receive-events */
|
618
618
|
export declare enum GatewayEvents {
|
619
|
+
Dispatch = "dispatch",
|
619
620
|
Hello = "hello",
|
620
621
|
Ready = "ready",
|
621
622
|
Resumed = "resumed",
|
@@ -1012,8 +1013,8 @@ export declare enum JSONErrorCodes {
|
|
1012
1013
|
FailedToCreateStageNeededForStageEvent = 180002,
|
1013
1014
|
MessageWasBlockedByAutomaticModeration = 200000,
|
1014
1015
|
TitleWasBlockedByAutomaticModeration = 200001,
|
1015
|
-
|
1016
|
-
|
1016
|
+
WebhooksPostedToForumChannelsMustHaveAThreadNameOrThreadID = 220001,
|
1017
|
+
WebhooksPostedToForumChannelsCannotHaveBothAThreadNameAndThreadID = 220002,
|
1017
1018
|
WebhooksCanOnlyCreateThreadsInForumChannels = 220003,
|
1018
1019
|
WebhookServicesCannotBeUsedInForumChannels = 220004,
|
1019
1020
|
MessageBlockedByHarmfulLinksFilter = 240000,
|
@@ -1037,7 +1038,7 @@ export declare enum RPCErrorCodes {
|
|
1037
1038
|
InvalidEvent = 4004,
|
1038
1039
|
InvalidChannel = 4005,
|
1039
1040
|
InvalidPermissions = 4006,
|
1040
|
-
|
1041
|
+
InvalidClientID = 4007,
|
1041
1042
|
InvalidOrigin = 4008,
|
1042
1043
|
InvalidToken = 4009,
|
1043
1044
|
InvalidUser = 4010,
|
@@ -1049,7 +1050,7 @@ export declare enum RPCErrorCodes {
|
|
1049
1050
|
}
|
1050
1051
|
/** https://discord.com/developers/docs/topics/opcodes-and-status-codes#rpc-rpc-close-event-codes */
|
1051
1052
|
export declare enum RPCCloseEventCodes {
|
1052
|
-
|
1053
|
+
InvalidClientID = 4000,
|
1053
1054
|
InvalidOrigin = 4001,
|
1054
1055
|
RateLimited = 4002,
|
1055
1056
|
TokenRevoked = 4003,
|
package/dist/lib/constants.js
CHANGED
@@ -682,6 +682,7 @@ var StatusTypes;
|
|
682
682
|
/** https://discord.com/developers/docs/topics/gateway-events#receive-events */
|
683
683
|
var GatewayEvents;
|
684
684
|
(function (GatewayEvents) {
|
685
|
+
GatewayEvents["Dispatch"] = "dispatch";
|
685
686
|
GatewayEvents["Hello"] = "hello";
|
686
687
|
GatewayEvents["Ready"] = "ready";
|
687
688
|
GatewayEvents["Resumed"] = "resumed";
|
@@ -1087,8 +1088,8 @@ var JSONErrorCodes;
|
|
1087
1088
|
JSONErrorCodes[JSONErrorCodes["FailedToCreateStageNeededForStageEvent"] = 180002] = "FailedToCreateStageNeededForStageEvent";
|
1088
1089
|
JSONErrorCodes[JSONErrorCodes["MessageWasBlockedByAutomaticModeration"] = 200000] = "MessageWasBlockedByAutomaticModeration";
|
1089
1090
|
JSONErrorCodes[JSONErrorCodes["TitleWasBlockedByAutomaticModeration"] = 200001] = "TitleWasBlockedByAutomaticModeration";
|
1090
|
-
JSONErrorCodes[JSONErrorCodes["
|
1091
|
-
JSONErrorCodes[JSONErrorCodes["
|
1091
|
+
JSONErrorCodes[JSONErrorCodes["WebhooksPostedToForumChannelsMustHaveAThreadNameOrThreadID"] = 220001] = "WebhooksPostedToForumChannelsMustHaveAThreadNameOrThreadID";
|
1092
|
+
JSONErrorCodes[JSONErrorCodes["WebhooksPostedToForumChannelsCannotHaveBothAThreadNameAndThreadID"] = 220002] = "WebhooksPostedToForumChannelsCannotHaveBothAThreadNameAndThreadID";
|
1092
1093
|
JSONErrorCodes[JSONErrorCodes["WebhooksCanOnlyCreateThreadsInForumChannels"] = 220003] = "WebhooksCanOnlyCreateThreadsInForumChannels";
|
1093
1094
|
JSONErrorCodes[JSONErrorCodes["WebhookServicesCannotBeUsedInForumChannels"] = 220004] = "WebhookServicesCannotBeUsedInForumChannels";
|
1094
1095
|
JSONErrorCodes[JSONErrorCodes["MessageBlockedByHarmfulLinksFilter"] = 240000] = "MessageBlockedByHarmfulLinksFilter";
|
@@ -1113,7 +1114,7 @@ var RPCErrorCodes;
|
|
1113
1114
|
RPCErrorCodes[RPCErrorCodes["InvalidEvent"] = 4004] = "InvalidEvent";
|
1114
1115
|
RPCErrorCodes[RPCErrorCodes["InvalidChannel"] = 4005] = "InvalidChannel";
|
1115
1116
|
RPCErrorCodes[RPCErrorCodes["InvalidPermissions"] = 4006] = "InvalidPermissions";
|
1116
|
-
RPCErrorCodes[RPCErrorCodes["
|
1117
|
+
RPCErrorCodes[RPCErrorCodes["InvalidClientID"] = 4007] = "InvalidClientID";
|
1117
1118
|
RPCErrorCodes[RPCErrorCodes["InvalidOrigin"] = 4008] = "InvalidOrigin";
|
1118
1119
|
RPCErrorCodes[RPCErrorCodes["InvalidToken"] = 4009] = "InvalidToken";
|
1119
1120
|
RPCErrorCodes[RPCErrorCodes["InvalidUser"] = 4010] = "InvalidUser";
|
@@ -1126,7 +1127,7 @@ var RPCErrorCodes;
|
|
1126
1127
|
/** https://discord.com/developers/docs/topics/opcodes-and-status-codes#rpc-rpc-close-event-codes */
|
1127
1128
|
var RPCCloseEventCodes;
|
1128
1129
|
(function (RPCCloseEventCodes) {
|
1129
|
-
RPCCloseEventCodes[RPCCloseEventCodes["
|
1130
|
+
RPCCloseEventCodes[RPCCloseEventCodes["InvalidClientID"] = 4000] = "InvalidClientID";
|
1130
1131
|
RPCCloseEventCodes[RPCCloseEventCodes["InvalidOrigin"] = 4001] = "InvalidOrigin";
|
1131
1132
|
RPCCloseEventCodes[RPCCloseEventCodes["RateLimited"] = 4002] = "RateLimited";
|
1132
1133
|
RPCCloseEventCodes[RPCCloseEventCodes["TokenRevoked"] = 4003] = "TokenRevoked";
|
@@ -1,25 +1,30 @@
|
|
1
1
|
import WebSocket from "ws";
|
2
|
-
import { StatusTypes } from "../constants";
|
3
2
|
import { Client } from "../Client";
|
4
|
-
import type {
|
3
|
+
import type { GatewayPresenceUpdate, Identify, RequestGuildMembers, Resume } from "../types/gateway-events";
|
5
4
|
export declare class Shard {
|
6
5
|
id: number;
|
7
6
|
private heartbeatInterval;
|
8
7
|
client: Client;
|
9
8
|
ws: WebSocket;
|
10
|
-
|
9
|
+
sessionID: string;
|
11
10
|
constructor(id: number, client: Client);
|
12
|
-
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
13
|
-
setPresence(options: {
|
14
|
-
activities?: Array<Pick<Activity, "name" | "type" | "url" | "state">>;
|
15
|
-
status?: StatusTypes;
|
16
|
-
afk?: boolean;
|
17
|
-
}): void;
|
18
11
|
/** https://discord.com/developers/docs/topics/gateway#connections */
|
19
12
|
connect(): void;
|
13
|
+
/** https://discord.com/developers/docs/topics/gateway#connections */
|
20
14
|
disconnect(): void;
|
15
|
+
/** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
|
16
|
+
heartbeat(lastSequence: number | null): void;
|
17
|
+
/** https://discord.com/developers/docs/topics/gateway-events#identify */
|
18
|
+
identify(options: Identify): void;
|
19
|
+
private onDispatch;
|
21
20
|
private onWebSocketOpen;
|
22
21
|
private onWebSocketMessage;
|
23
22
|
private onWebSocketError;
|
24
23
|
private onWebSocketClose;
|
24
|
+
/** https://discord.com/developers/docs/topics/gateway-events#request-guild-members */
|
25
|
+
requestGuildMembers(options: RequestGuildMembers): void;
|
26
|
+
/** https://discord.com/developers/docs/topics/gateway-events#resume */
|
27
|
+
resume(options: Resume): void;
|
28
|
+
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
29
|
+
updatePresence(options: Partial<Pick<GatewayPresenceUpdate, "activities" | "status" | "afk">>): void;
|
25
30
|
}
|
@@ -36,24 +36,12 @@ class Shard {
|
|
36
36
|
heartbeatInterval;
|
37
37
|
client;
|
38
38
|
ws;
|
39
|
-
|
39
|
+
sessionID;
|
40
40
|
constructor(id, client) {
|
41
41
|
this.id = id;
|
42
42
|
this.client = client;
|
43
43
|
this.ws = new ws_1.default("wss://gateway.discord.gg/?v=10&encoding=json");
|
44
44
|
}
|
45
|
-
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
46
|
-
setPresence(options) {
|
47
|
-
this.ws.send(JSON.stringify({
|
48
|
-
op: constants_1.GatewayOPCodes.PresenceUpdate,
|
49
|
-
d: {
|
50
|
-
since: options.status === constants_1.StatusTypes.Idle ? Date.now() : null,
|
51
|
-
activities: options.activities,
|
52
|
-
status: options.status ?? constants_1.StatusTypes.Online,
|
53
|
-
afk: !!options.afk,
|
54
|
-
},
|
55
|
-
}));
|
56
|
-
}
|
57
45
|
/** https://discord.com/developers/docs/topics/gateway#connections */
|
58
46
|
connect() {
|
59
47
|
this.ws.on("open", () => this.onWebSocketOpen());
|
@@ -61,54 +49,46 @@ class Shard {
|
|
61
49
|
this.ws.on("error", (err) => this.onWebSocketError(err));
|
62
50
|
this.ws.on("close", (code, reason) => this.onWebSocketClose(code, reason));
|
63
51
|
}
|
52
|
+
/** https://discord.com/developers/docs/topics/gateway#connections */
|
64
53
|
disconnect() {
|
65
54
|
if (this.heartbeatInterval) {
|
66
55
|
clearInterval(this.heartbeatInterval);
|
67
56
|
this.heartbeatInterval = null;
|
68
57
|
}
|
69
58
|
}
|
70
|
-
|
59
|
+
/** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
|
60
|
+
heartbeat(lastSequence) {
|
61
|
+
this.ws.send(JSON.stringify({
|
62
|
+
op: constants_1.GatewayOPCodes.Heartbeat,
|
63
|
+
d: lastSequence,
|
64
|
+
}));
|
65
|
+
}
|
66
|
+
/** https://discord.com/developers/docs/topics/gateway-events#identify */
|
67
|
+
identify(options) {
|
71
68
|
this.ws.send(JSON.stringify({
|
72
69
|
op: constants_1.GatewayOPCodes.Identify,
|
73
70
|
d: {
|
74
|
-
token:
|
75
|
-
shard: [this.id, this.client.shardsCount],
|
76
|
-
intents: this.client.intents,
|
71
|
+
token: options.token,
|
77
72
|
properties: {
|
78
|
-
os:
|
79
|
-
browser:
|
80
|
-
device:
|
73
|
+
os: options.properties.os,
|
74
|
+
browser: options.properties.browser,
|
75
|
+
device: options.properties.device,
|
81
76
|
},
|
77
|
+
compress: options.compress,
|
78
|
+
large_threshold: options.largeThreshold,
|
79
|
+
shard: options.shard,
|
80
|
+
presence: options.presence,
|
81
|
+
intents: options.intents,
|
82
82
|
},
|
83
83
|
}));
|
84
84
|
}
|
85
|
-
|
86
|
-
|
87
|
-
switch (packet.op) {
|
88
|
-
case constants_1.GatewayOPCodes.Reconnect:
|
89
|
-
this.client.emit(constants_1.GatewayEvents.Reconnect);
|
90
|
-
break;
|
91
|
-
case constants_1.GatewayOPCodes.InvalidSession:
|
92
|
-
this.client.emit(constants_1.GatewayEvents.InvalidSession);
|
93
|
-
break;
|
94
|
-
case constants_1.GatewayOPCodes.Hello:
|
95
|
-
{
|
96
|
-
this.heartbeatInterval = setInterval(() => {
|
97
|
-
this.ws.send(JSON.stringify({
|
98
|
-
op: constants_1.GatewayOPCodes.Heartbeat,
|
99
|
-
d: null,
|
100
|
-
}));
|
101
|
-
}, packet.d.heartbeat_interval);
|
102
|
-
this.client.emit(constants_1.GatewayEvents.Hello);
|
103
|
-
}
|
104
|
-
break;
|
105
|
-
}
|
85
|
+
onDispatch(packet) {
|
86
|
+
this.client.emit(constants_1.GatewayEvents.Dispatch, packet);
|
106
87
|
switch (packet.t) {
|
107
88
|
case "READY":
|
108
89
|
{
|
109
|
-
this.
|
90
|
+
this.sessionID = packet.d.session_id;
|
110
91
|
this.client.user = this.client.util.userFromRaw(packet.d.user);
|
111
|
-
this.client.guilds = new Map();
|
112
92
|
this.client.application = packet.d.application;
|
113
93
|
this.client.emit(constants_1.GatewayEvents.Ready);
|
114
94
|
}
|
@@ -130,21 +110,21 @@ class Shard {
|
|
130
110
|
break;
|
131
111
|
case "AUTO_MODERATION_ACTION_EXECUTION":
|
132
112
|
this.client.emit(constants_1.GatewayEvents.AutoModerationActionExecution, {
|
133
|
-
|
113
|
+
guildID: packet.d.guild_id,
|
134
114
|
action: {
|
135
115
|
type: packet.d.action.type,
|
136
116
|
metadata: {
|
137
|
-
|
117
|
+
channelID: packet.d.action.metadata.channel_id,
|
138
118
|
durationSeconds: packet.d.action.metadata.duration_seconds,
|
139
119
|
customMessage: packet.d.action.metadata.custom_message,
|
140
120
|
},
|
141
121
|
},
|
142
|
-
|
122
|
+
ruleID: packet.d.rule_id,
|
143
123
|
ruleTriggerType: packet.d.rule_trigger_type,
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
124
|
+
userID: packet.d.user_id,
|
125
|
+
channelID: packet.d.channel_id,
|
126
|
+
messageID: packet.d.message_id,
|
127
|
+
alertSystemMessageID: packet.d.alert_system_message_id,
|
148
128
|
content: packet.d.content,
|
149
129
|
matchedKeyword: packet.d.matched_keyword,
|
150
130
|
matchedContent: packet.d.matched_content,
|
@@ -161,8 +141,8 @@ class Shard {
|
|
161
141
|
break;
|
162
142
|
case "CHANNEL_PINS_UPDATE":
|
163
143
|
this.client.emit(constants_1.GatewayEvents.ChannelPinsUpdate, {
|
164
|
-
|
165
|
-
|
144
|
+
guildID: packet.d.guild_id,
|
145
|
+
channelID: packet.d.channel_id,
|
166
146
|
lastPinTimestamp: packet.d.last_pin_timestamp,
|
167
147
|
});
|
168
148
|
break;
|
@@ -177,8 +157,8 @@ class Shard {
|
|
177
157
|
break;
|
178
158
|
case "THREAD_LIST_SYNC":
|
179
159
|
this.client.emit(constants_1.GatewayEvents.ThreadListSync, {
|
180
|
-
|
181
|
-
|
160
|
+
guildID: packet.d.guild_id,
|
161
|
+
channelIDs: packet.d.channel_ids,
|
182
162
|
threads: packet.d.threads.map((thread) => this.client.util.channelFromRaw(thread)),
|
183
163
|
members: packet.d.members.map((threadMember) => this.client.util.threadMemberFromRaw(threadMember)),
|
184
164
|
});
|
@@ -186,22 +166,22 @@ class Shard {
|
|
186
166
|
case "THREAD_MEMBER_UPDATE":
|
187
167
|
this.client.emit(constants_1.GatewayEvents.ThreadMemberUpdate, {
|
188
168
|
id: packet.d.id,
|
189
|
-
|
169
|
+
userID: packet.d.user_id,
|
190
170
|
joinTimestamp: packet.d.join_timestamp,
|
191
171
|
flags: packet.d.flags,
|
192
172
|
member: packet.d.member !== undefined
|
193
173
|
? this.client.util.guildMemberFromRaw(packet.d.member)
|
194
174
|
: undefined,
|
195
|
-
|
175
|
+
guildID: packet.d.guild_id,
|
196
176
|
});
|
197
177
|
break;
|
198
178
|
case "THREAD_MEMBERS_UPDATE":
|
199
179
|
this.client.emit(constants_1.GatewayEvents.ThreadMembersUpdate, {
|
200
180
|
id: packet.d.id,
|
201
|
-
|
181
|
+
guildID: packet.d.guild_id,
|
202
182
|
memberCount: packet.d.member_count,
|
203
183
|
addedMembers: packet.d.members.map((threadMember) => this.client.util.threadMemberFromRaw(threadMember)),
|
204
|
-
|
184
|
+
removedMemberIDs: packet.d.removed_member_ids,
|
205
185
|
});
|
206
186
|
break;
|
207
187
|
case "ENTITLEMENT_CREATE":
|
@@ -239,18 +219,18 @@ class Shard {
|
|
239
219
|
case "GUILD_AUDIT_LOG_ENTRY_CREATE":
|
240
220
|
this.client.emit(constants_1.GatewayEvents.GuildAuditLogEntryCreate, {
|
241
221
|
...this.client.util.auditLogEntryFromRaw(packet.d),
|
242
|
-
|
222
|
+
guildID: packet.d.guild_id,
|
243
223
|
});
|
244
224
|
break;
|
245
225
|
case "GUILD_BAN_ADD":
|
246
226
|
this.client.emit(constants_1.GatewayEvents.GuildBanAdd, {
|
247
|
-
|
227
|
+
guildID: packet.d.guild_id,
|
248
228
|
user: this.client.util.userFromRaw(packet.d.user),
|
249
229
|
});
|
250
230
|
break;
|
251
231
|
case "GUILD_BAN_REMOVE":
|
252
232
|
this.client.emit(constants_1.GatewayEvents.GuildBanRemove, {
|
253
|
-
|
233
|
+
guildID: packet.d.guild_id,
|
254
234
|
user: this.client.util.userFromRaw(packet.d.user),
|
255
235
|
});
|
256
236
|
break;
|
@@ -266,18 +246,18 @@ class Shard {
|
|
266
246
|
case "GUILD_MEMBER_ADD":
|
267
247
|
this.client.emit(constants_1.GatewayEvents.GuildMemberAdd, {
|
268
248
|
...this.client.util.guildMemberFromRaw(packet.d),
|
269
|
-
|
249
|
+
guildID: packet.d.guild_id,
|
270
250
|
});
|
271
251
|
break;
|
272
252
|
case "GUILD_MEMBER_REMOVE":
|
273
253
|
this.client.emit(constants_1.GatewayEvents.GuildMemberRemove, {
|
274
|
-
|
254
|
+
guildID: packet.d.guild_id,
|
275
255
|
user: this.client.util.userFromRaw(packet.d.user),
|
276
256
|
});
|
277
257
|
break;
|
278
258
|
case "GUILD_MEMBER_UPDATE":
|
279
259
|
this.client.emit(constants_1.GatewayEvents.GuildMemberUpdate, {
|
280
|
-
|
260
|
+
guildID: packet.d.guild_id,
|
281
261
|
roles: packet.d.roles,
|
282
262
|
user: this.client.util.userFromRaw(packet.d.user),
|
283
263
|
nick: packet.d.nick,
|
@@ -292,14 +272,14 @@ class Shard {
|
|
292
272
|
avatarDecorationData: packet.d.avatar_decoration_data !== undefined
|
293
273
|
? {
|
294
274
|
asset: packet.d.asset,
|
295
|
-
|
275
|
+
skuID: packet.d.sku_id,
|
296
276
|
}
|
297
277
|
: undefined,
|
298
278
|
});
|
299
279
|
break;
|
300
280
|
case "GUILD_MEMBERS_CHUNK":
|
301
281
|
this.client.emit(constants_1.GatewayEvents.GuildMembersChunk, {
|
302
|
-
|
282
|
+
guildID: packet.d.guild_id,
|
303
283
|
members: packet.d.members.map((guildMember) => this.client.util.guildMemberFromRaw(guildMember)),
|
304
284
|
chunkIndex: packet.d.chunk_index,
|
305
285
|
chunkCount: packet.d.chunk_count,
|
@@ -335,20 +315,20 @@ class Shard {
|
|
335
315
|
case "INTEGRATION_CREATE":
|
336
316
|
this.client.emit(constants_1.GatewayEvents.IntegrationCreate, {
|
337
317
|
...this.client.util.integrationFromRaw(packet.d),
|
338
|
-
|
318
|
+
guildID: packet.d.guild_id,
|
339
319
|
});
|
340
320
|
break;
|
341
321
|
case "INTEGRATION_UPDATE":
|
342
322
|
this.client.emit(constants_1.GatewayEvents.IntegrationUpdate, {
|
343
323
|
...this.client.util.integrationFromRaw(packet.d),
|
344
|
-
|
324
|
+
guildID: packet.d.guild_id,
|
345
325
|
});
|
346
326
|
break;
|
347
327
|
case "INTEGRATION_DELETE":
|
348
328
|
this.client.emit(constants_1.GatewayEvents.IntegrationDelete, {
|
349
329
|
id: packet.d.id,
|
350
|
-
|
351
|
-
|
330
|
+
guildID: packet.d.guild_id,
|
331
|
+
applicationID: packet.d.application_id,
|
352
332
|
});
|
353
333
|
break;
|
354
334
|
case "INTERACTION_CREATE":
|
@@ -356,10 +336,10 @@ class Shard {
|
|
356
336
|
break;
|
357
337
|
case "INVITE_CREATE":
|
358
338
|
this.client.emit(constants_1.GatewayEvents.InviteCreate, {
|
359
|
-
|
339
|
+
channelID: packet.d.channel_id,
|
360
340
|
code: packet.d.code,
|
361
341
|
createdAt: packet.d.created_at,
|
362
|
-
|
342
|
+
guildID: packet.d.guild_id,
|
363
343
|
inviter: packet.d.inviter !== undefined
|
364
344
|
? this.client.util.userFromRaw(packet.d.inviter)
|
365
345
|
: undefined,
|
@@ -378,15 +358,15 @@ class Shard {
|
|
378
358
|
break;
|
379
359
|
case "INVITE_DELETE":
|
380
360
|
this.client.emit(constants_1.GatewayEvents.InviteDelete, {
|
381
|
-
|
382
|
-
|
361
|
+
channelID: packet.d.channel_id,
|
362
|
+
guildID: packet.d.guild_id,
|
383
363
|
code: packet.d.code,
|
384
364
|
});
|
385
365
|
break;
|
386
366
|
case "MESSAGE_CREATE":
|
387
367
|
this.client.emit(constants_1.GatewayEvents.MessageCreate, {
|
388
368
|
...this.client.util.messageFromRaw(packet.d),
|
389
|
-
|
369
|
+
guildID: packet.d.guild_id,
|
390
370
|
member: packet.d.member !== undefined
|
391
371
|
? this.client.util.guildMemberFromRaw(packet.d.member)
|
392
372
|
: undefined,
|
@@ -399,28 +379,28 @@ class Shard {
|
|
399
379
|
case "MESSAGE_DELETE":
|
400
380
|
this.client.emit(constants_1.GatewayEvents.MessageDelete, {
|
401
381
|
id: packet.d.id,
|
402
|
-
|
403
|
-
|
382
|
+
channelID: packet.d.channel_id,
|
383
|
+
guildID: packet.d.guild_id,
|
404
384
|
});
|
405
385
|
break;
|
406
386
|
case "MESSAGE_DELETE_BULK":
|
407
387
|
this.client.emit(constants_1.GatewayEvents.MessageDeleteBulk, {
|
408
388
|
ids: packet.d.ids,
|
409
|
-
|
410
|
-
|
389
|
+
channelID: packet.d.channel_id,
|
390
|
+
guildID: packet.d.guild_id,
|
411
391
|
});
|
412
392
|
break;
|
413
393
|
case "MESSAGE_REACTION_ADD":
|
414
394
|
this.client.emit(constants_1.GatewayEvents.MessageReactionAdd, {
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
395
|
+
userID: packet.d.user_id,
|
396
|
+
channelID: packet.d.user_id,
|
397
|
+
messageID: packet.d.user_id,
|
398
|
+
guildID: packet.d.user_id,
|
419
399
|
member: packet.d.member !== undefined
|
420
400
|
? this.client.util.guildMemberFromRaw(packet.d.member)
|
421
401
|
: undefined,
|
422
402
|
emoji: this.client.util.emojiFromRaw(packet.d.emoji),
|
423
|
-
|
403
|
+
messageAuthorID: packet.d.message_author_id,
|
424
404
|
burst: packet.d.burst,
|
425
405
|
burstColors: packet.d.burst_colors,
|
426
406
|
type: packet.d.type,
|
@@ -428,10 +408,10 @@ class Shard {
|
|
428
408
|
break;
|
429
409
|
case "MESSAGE_REACTION_REMOVE":
|
430
410
|
this.client.emit(constants_1.GatewayEvents.MessageReactionRemove, {
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
411
|
+
userID: packet.d.user_id,
|
412
|
+
channelID: packet.d.user_id,
|
413
|
+
messageID: packet.d.user_id,
|
414
|
+
guildID: packet.d.user_id,
|
435
415
|
emoji: this.client.util.emojiFromRaw(packet.d.emoji),
|
436
416
|
burst: packet.d.burst,
|
437
417
|
type: packet.d.type,
|
@@ -439,16 +419,16 @@ class Shard {
|
|
439
419
|
break;
|
440
420
|
case "MESSAGE_REACTION_REMOVE_ALL":
|
441
421
|
this.client.emit(constants_1.GatewayEvents.MessageReactionRemoveAll, {
|
442
|
-
|
443
|
-
|
444
|
-
|
422
|
+
channelID: packet.d.channel_id,
|
423
|
+
messageID: packet.d.message_id,
|
424
|
+
guildID: packet.d.guild_id,
|
445
425
|
});
|
446
426
|
break;
|
447
427
|
case "MESSAGE_REACTION_REMOVE_EMOJI":
|
448
428
|
this.client.emit(constants_1.GatewayEvents.MessageReactionRemoveEmoji, {
|
449
|
-
|
450
|
-
|
451
|
-
|
429
|
+
channelID: packet.d.channel_id,
|
430
|
+
guildID: packet.d.guild_id,
|
431
|
+
messageID: packet.d.message_id,
|
452
432
|
emoji: this.client.util.emojiFromRaw(packet.d.emoji),
|
453
433
|
});
|
454
434
|
break;
|
@@ -466,9 +446,9 @@ class Shard {
|
|
466
446
|
break;
|
467
447
|
case "TYPING_START":
|
468
448
|
this.client.emit(constants_1.GatewayEvents.TypingStart, {
|
469
|
-
|
470
|
-
|
471
|
-
|
449
|
+
channelID: packet.d.channel_id,
|
450
|
+
guildID: packet.d.guild_id,
|
451
|
+
userID: packet.d.user_id,
|
472
452
|
timestamp: packet.d.timestamp,
|
473
453
|
member: packet.d.member !== undefined
|
474
454
|
? this.client.util.guildMemberFromRaw(packet.d.member)
|
@@ -484,7 +464,7 @@ class Shard {
|
|
484
464
|
case "VOICE_SERVER_UPDATE":
|
485
465
|
this.client.emit(constants_1.GatewayEvents.VoiceServerUpdate, {
|
486
466
|
token: packet.d.token,
|
487
|
-
|
467
|
+
guildID: packet.d.guild_id,
|
488
468
|
endpoint: packet.d.endpoint,
|
489
469
|
});
|
490
470
|
break;
|
@@ -493,24 +473,56 @@ class Shard {
|
|
493
473
|
break;
|
494
474
|
case "MESSAGE_POLL_VOTE_ADD":
|
495
475
|
this.client.emit(constants_1.GatewayEvents.MessagePollVoteAdd, {
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
476
|
+
userID: packet.d.user_id,
|
477
|
+
channelID: packet.d.channel_id,
|
478
|
+
messageID: packet.d.message_id,
|
479
|
+
guildID: packet.d.guild_id,
|
480
|
+
answerID: packet.d.answer_id,
|
501
481
|
});
|
502
482
|
break;
|
503
483
|
case "MESSAGE_POLL_VOTE_REMOVE":
|
504
484
|
this.client.emit(constants_1.GatewayEvents.MessagePollVoteRemove, {
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
485
|
+
userID: packet.d.user_id,
|
486
|
+
channelID: packet.d.channel_id,
|
487
|
+
messageID: packet.d.message_id,
|
488
|
+
guildID: packet.d.guild_id,
|
489
|
+
answerID: packet.d.answer_id,
|
510
490
|
});
|
511
491
|
break;
|
512
492
|
}
|
513
493
|
}
|
494
|
+
onWebSocketOpen() {
|
495
|
+
this.identify({
|
496
|
+
token: this.client.token,
|
497
|
+
shard: [this.id, this.client.shardsCount],
|
498
|
+
intents: this.client.intents,
|
499
|
+
properties: {
|
500
|
+
os: process.platform,
|
501
|
+
browser: pkg.name,
|
502
|
+
device: pkg.name,
|
503
|
+
},
|
504
|
+
});
|
505
|
+
}
|
506
|
+
onWebSocketMessage(data) {
|
507
|
+
const packet = JSON.parse(data.toString());
|
508
|
+
switch (packet.op) {
|
509
|
+
case constants_1.GatewayOPCodes.Dispatch:
|
510
|
+
this.onDispatch(packet);
|
511
|
+
break;
|
512
|
+
case constants_1.GatewayOPCodes.Reconnect:
|
513
|
+
this.client.emit(constants_1.GatewayEvents.Reconnect);
|
514
|
+
break;
|
515
|
+
case constants_1.GatewayOPCodes.InvalidSession:
|
516
|
+
this.client.emit(constants_1.GatewayEvents.InvalidSession);
|
517
|
+
break;
|
518
|
+
case constants_1.GatewayOPCodes.Hello:
|
519
|
+
{
|
520
|
+
this.heartbeatInterval = setInterval(() => this.heartbeat(null), packet.d.heartbeat_interval);
|
521
|
+
this.client.emit(constants_1.GatewayEvents.Hello);
|
522
|
+
}
|
523
|
+
break;
|
524
|
+
}
|
525
|
+
}
|
514
526
|
onWebSocketError(err) {
|
515
527
|
throw err;
|
516
528
|
}
|
@@ -519,5 +531,42 @@ class Shard {
|
|
519
531
|
return;
|
520
532
|
throw new utils_1.GatewayError(`[${code}] ${reason}`);
|
521
533
|
}
|
534
|
+
/** https://discord.com/developers/docs/topics/gateway-events#request-guild-members */
|
535
|
+
requestGuildMembers(options) {
|
536
|
+
this.ws.send(JSON.stringify({
|
537
|
+
op: constants_1.GatewayOPCodes.RequestGuildMembers,
|
538
|
+
d: {
|
539
|
+
guild_id: options.guildID,
|
540
|
+
query: options.query,
|
541
|
+
limit: options.limit,
|
542
|
+
presences: options.presences,
|
543
|
+
user_ids: options.userIDs,
|
544
|
+
nonce: options.nonce,
|
545
|
+
},
|
546
|
+
}));
|
547
|
+
}
|
548
|
+
/** https://discord.com/developers/docs/topics/gateway-events#resume */
|
549
|
+
resume(options) {
|
550
|
+
this.ws.send(JSON.stringify({
|
551
|
+
op: constants_1.GatewayOPCodes.Resume,
|
552
|
+
d: {
|
553
|
+
token: options.token,
|
554
|
+
session_id: options.sessionID,
|
555
|
+
seq: options.seq,
|
556
|
+
},
|
557
|
+
}));
|
558
|
+
}
|
559
|
+
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
560
|
+
updatePresence(options) {
|
561
|
+
this.ws.send(JSON.stringify({
|
562
|
+
op: constants_1.GatewayOPCodes.PresenceUpdate,
|
563
|
+
d: {
|
564
|
+
since: options.status === constants_1.StatusTypes.Idle ? Date.now() : null,
|
565
|
+
activities: options.activities,
|
566
|
+
status: options.status ?? constants_1.StatusTypes.Online,
|
567
|
+
afk: !!options.afk,
|
568
|
+
},
|
569
|
+
}));
|
570
|
+
}
|
522
571
|
}
|
523
572
|
exports.Shard = Shard;
|