disgroove 3.0.0-dev.950983e → 3.0.0-dev.97f3796
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 +0 -2
- package/dist/lib/Client.js +5 -11
- package/dist/lib/gateway/Shard.d.ts +19 -6
- package/dist/lib/gateway/Shard.js +175 -92
- package/dist/package.json +1 -1
- package/package.json +1 -1
- package/dist/lib/gateway/WebSocketManager.d.ts +0 -22
- package/dist/lib/gateway/WebSocketManager.js +0 -93
package/dist/lib/Client.d.ts
CHANGED
|
@@ -41,7 +41,6 @@ export interface GatewayOptions {
|
|
|
41
41
|
export interface ClientOptions {
|
|
42
42
|
shardsCount?: number | "auto";
|
|
43
43
|
auth?: "Bot" | "Bearer";
|
|
44
|
-
reconnect?: boolean;
|
|
45
44
|
gateway?: GatewayOptions;
|
|
46
45
|
ws?: WebSocketOptions;
|
|
47
46
|
}
|
|
@@ -54,7 +53,6 @@ export declare class Client extends EventEmitter {
|
|
|
54
53
|
intents: GatewayIntents | number;
|
|
55
54
|
shardsCount: number | "auto";
|
|
56
55
|
auth: "Bot" | "Bearer";
|
|
57
|
-
reconnect: boolean;
|
|
58
56
|
shards: Map<number, Shard>;
|
|
59
57
|
rest: RequestManager;
|
|
60
58
|
guildShardMap: Map<string, number>;
|
package/dist/lib/Client.js
CHANGED
|
@@ -18,7 +18,6 @@ class Client extends node_events_1.default {
|
|
|
18
18
|
intents;
|
|
19
19
|
shardsCount;
|
|
20
20
|
auth;
|
|
21
|
-
reconnect;
|
|
22
21
|
shards;
|
|
23
22
|
rest;
|
|
24
23
|
guildShardMap;
|
|
@@ -41,7 +40,6 @@ class Client extends node_events_1.default {
|
|
|
41
40
|
: 0;
|
|
42
41
|
this.shardsCount = options?.shardsCount ?? "auto";
|
|
43
42
|
this.auth = options?.auth ?? "Bot";
|
|
44
|
-
this.reconnect = options?.reconnect ?? true;
|
|
45
43
|
this.shards = new Map();
|
|
46
44
|
this.rest = new rest_1.RequestManager(token, this.auth);
|
|
47
45
|
this.guildShardMap = new Map();
|
|
@@ -167,7 +165,7 @@ class Client extends node_events_1.default {
|
|
|
167
165
|
: this.shardsCount;
|
|
168
166
|
for (let i = 0; i < this.shardsCount; i++)
|
|
169
167
|
this.shards.set(i, new gateway_1.Shard(i, this));
|
|
170
|
-
this.shards.forEach((shard) => shard.connect());
|
|
168
|
+
this.shards.forEach((shard) => shard.connect(false));
|
|
171
169
|
}
|
|
172
170
|
/** https://discord.com/developers/docs/resources/entitlement#consume-an-entitlement */
|
|
173
171
|
consumeEntitlement(applicationId, entitlementId) {
|
|
@@ -878,7 +876,7 @@ class Client extends node_events_1.default {
|
|
|
878
876
|
}
|
|
879
877
|
/** https://discord.com/developers/docs/events/gateway#initiating-a-disconnect */
|
|
880
878
|
disconnect() {
|
|
881
|
-
this.shards.forEach((shard) => shard.disconnect(
|
|
879
|
+
this.shards.forEach((shard) => shard.disconnect());
|
|
882
880
|
}
|
|
883
881
|
/** https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule */
|
|
884
882
|
async editAutoModerationRule(guildId, autoModerationRuleId, options, reason) {
|
|
@@ -2363,9 +2361,7 @@ class Client extends node_events_1.default {
|
|
|
2363
2361
|
}
|
|
2364
2362
|
/** https://discord.com/developers/docs/topics/gateway-events#update-voice-state */
|
|
2365
2363
|
joinVoiceChannel(guildId, channelId, options) {
|
|
2366
|
-
this.shards
|
|
2367
|
-
.get(this.guildShardMap.get(guildId))
|
|
2368
|
-
.manager.updateVoiceState({
|
|
2364
|
+
this.shards.get(this.guildShardMap.get(guildId)).updateVoiceState({
|
|
2369
2365
|
guildId,
|
|
2370
2366
|
channelId,
|
|
2371
2367
|
selfMute: !!options?.selfMute,
|
|
@@ -2386,9 +2382,7 @@ class Client extends node_events_1.default {
|
|
|
2386
2382
|
}
|
|
2387
2383
|
/** https://discord.com/developers/docs/topics/gateway-events#update-voice-state */
|
|
2388
2384
|
leaveVoiceChannel(guildId) {
|
|
2389
|
-
this.shards
|
|
2390
|
-
.get(this.guildShardMap.get(guildId))
|
|
2391
|
-
.manager.updateVoiceState({
|
|
2385
|
+
this.shards.get(this.guildShardMap.get(guildId)).updateVoiceState({
|
|
2392
2386
|
guildId,
|
|
2393
2387
|
channelId: null,
|
|
2394
2388
|
selfMute: false,
|
|
@@ -2461,7 +2455,7 @@ class Client extends node_events_1.default {
|
|
|
2461
2455
|
}
|
|
2462
2456
|
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
|
2463
2457
|
setPresence(options) {
|
|
2464
|
-
this.shards.forEach((shard) => shard.
|
|
2458
|
+
this.shards.forEach((shard) => shard.updatePresence(options));
|
|
2465
2459
|
}
|
|
2466
2460
|
/** https://discord.com/developers/docs/resources/guild-template#sync-guild-template */
|
|
2467
2461
|
async syncGuildTemplate(guildId, code) {
|
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
2
|
import { Client } from "../Client";
|
|
3
|
-
import {
|
|
3
|
+
import type { GatewayPresenceUpdate, GatewayVoiceStateUpdate, Identify, RequestGuildMembers, RequestSoundboardSounds, Resume } from "../types/gateway-events";
|
|
4
4
|
export declare class Shard {
|
|
5
5
|
id: number;
|
|
6
6
|
private heartbeatInterval;
|
|
7
7
|
client: Client;
|
|
8
8
|
ws: WebSocket | null;
|
|
9
|
-
manager: WebSocketManager;
|
|
10
9
|
sessionId: string | null;
|
|
11
10
|
resumeGatewayURL: string | null;
|
|
12
11
|
sequence: number | null;
|
|
13
12
|
constructor(id: number, client: Client);
|
|
14
13
|
/** https://discord.com/developers/docs/topics/gateway#connections */
|
|
15
|
-
connect(): void;
|
|
14
|
+
connect(reconnect: boolean): void;
|
|
16
15
|
/** https://discord.com/developers/docs/events/gateway#initiating-a-disconnect */
|
|
17
|
-
disconnect(
|
|
18
|
-
|
|
16
|
+
disconnect(): void;
|
|
17
|
+
/** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
|
|
18
|
+
heartbeat(lastSequence: number | null): void;
|
|
19
|
+
/** https://discord.com/developers/docs/topics/gateway-events#identify */
|
|
20
|
+
identify(options: Identify): void;
|
|
19
21
|
private onDispatch;
|
|
20
22
|
private onWebSocketOpen;
|
|
21
23
|
private onWebSocketMessage;
|
|
22
24
|
private onWebSocketError;
|
|
23
25
|
private onWebSocketClose;
|
|
24
|
-
|
|
26
|
+
/** https://discord.com/developers/docs/events/gateway#resuming */
|
|
27
|
+
reconnect(): void;
|
|
28
|
+
/** https://discord.com/developers/docs/topics/gateway-events#request-guild-members */
|
|
29
|
+
requestGuildMembers(options: RequestGuildMembers): void;
|
|
30
|
+
/** https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds */
|
|
31
|
+
requestSoundboardSounds(options: RequestSoundboardSounds): void;
|
|
32
|
+
/** https://discord.com/developers/docs/topics/gateway-events#resume */
|
|
33
|
+
resume(options: Resume): void;
|
|
34
|
+
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
|
35
|
+
updatePresence(options: Partial<Pick<GatewayPresenceUpdate, "activities" | "status" | "afk">>): void;
|
|
36
|
+
/** https://discord.com/developers/docs/topics/gateway-events#update-voice-state */
|
|
37
|
+
updateVoiceState(options: GatewayVoiceStateUpdate): void;
|
|
25
38
|
}
|
|
@@ -42,13 +42,11 @@ const constants_1 = require("../constants");
|
|
|
42
42
|
const utils_1 = require("../utils");
|
|
43
43
|
const pkg = __importStar(require("../../package.json"));
|
|
44
44
|
const transformers_1 = require("../transformers");
|
|
45
|
-
const WebSocketManager_1 = require("./WebSocketManager");
|
|
46
45
|
class Shard {
|
|
47
46
|
id;
|
|
48
47
|
heartbeatInterval;
|
|
49
48
|
client;
|
|
50
49
|
ws;
|
|
51
|
-
manager;
|
|
52
50
|
sessionId;
|
|
53
51
|
resumeGatewayURL;
|
|
54
52
|
sequence;
|
|
@@ -57,86 +55,62 @@ class Shard {
|
|
|
57
55
|
this.heartbeatInterval = null;
|
|
58
56
|
this.client = client;
|
|
59
57
|
this.ws = new ws_1.default("wss://gateway.discord.gg/?v=10&encoding=json", this.client.ws);
|
|
60
|
-
this.manager = new WebSocketManager_1.WebSocketManager(this.ws);
|
|
61
58
|
this.sessionId = null;
|
|
62
59
|
this.resumeGatewayURL = null;
|
|
63
60
|
this.sequence = null;
|
|
64
61
|
}
|
|
65
62
|
/** https://discord.com/developers/docs/topics/gateway#connections */
|
|
66
|
-
connect() {
|
|
63
|
+
connect(reconnect) {
|
|
67
64
|
if (this.ws) {
|
|
68
|
-
this.ws.on("open", () => this.onWebSocketOpen());
|
|
65
|
+
this.ws.on("open", () => this.onWebSocketOpen(reconnect));
|
|
69
66
|
this.ws.on("message", (data) => this.onWebSocketMessage(data));
|
|
70
67
|
this.ws.on("error", (err) => this.onWebSocketError(err));
|
|
71
68
|
this.ws.on("close", (code, reason) => this.onWebSocketClose(code, reason));
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
/** https://discord.com/developers/docs/events/gateway#initiating-a-disconnect */
|
|
75
|
-
disconnect(
|
|
76
|
-
if (this.heartbeatInterval) {
|
|
77
|
-
clearInterval(this.heartbeatInterval);
|
|
78
|
-
this.heartbeatInterval = null;
|
|
79
|
-
}
|
|
72
|
+
disconnect() {
|
|
80
73
|
if (this.ws) {
|
|
74
|
+
if (this.heartbeatInterval) {
|
|
75
|
+
clearInterval(this.heartbeatInterval);
|
|
76
|
+
this.heartbeatInterval = null;
|
|
77
|
+
}
|
|
81
78
|
if (this.ws.readyState !== ws_1.default.CLOSED) {
|
|
82
79
|
this.ws.removeAllListeners();
|
|
83
|
-
|
|
84
|
-
this.sessionId &&
|
|
85
|
-
this.sequence &&
|
|
86
|
-
this.resumeGatewayURL) {
|
|
87
|
-
if (this.ws.readyState === ws_1.default.OPEN) {
|
|
88
|
-
this.ws.terminate();
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
this.ws.close(1000, "Resume Attempt - Reconnect");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
this.ws.close(1000, "Session Invalidated - Disconnect");
|
|
96
|
-
}
|
|
80
|
+
this.ws.close(1000, "Session Invalidated - Disconnect");
|
|
97
81
|
this.ws = null;
|
|
98
|
-
this.manager = new WebSocketManager_1.WebSocketManager(this.ws);
|
|
99
|
-
}
|
|
100
|
-
if (reconnect &&
|
|
101
|
-
this.sessionId &&
|
|
102
|
-
this.sequence &&
|
|
103
|
-
this.resumeGatewayURL) {
|
|
104
|
-
this.ws = new ws_1.default(this.resumeGatewayURL, this.client.ws);
|
|
105
|
-
this.manager = new WebSocketManager_1.WebSocketManager(this.ws);
|
|
106
|
-
this.connect();
|
|
107
82
|
}
|
|
108
83
|
}
|
|
109
84
|
}
|
|
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
|
-
});
|
|
85
|
+
/** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
|
|
86
|
+
heartbeat(lastSequence) {
|
|
87
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
88
|
+
this.ws.send(JSON.stringify({
|
|
89
|
+
op: constants_1.GatewayOPCodes.Heartbeat,
|
|
90
|
+
d: lastSequence,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** https://discord.com/developers/docs/topics/gateway-events#identify */
|
|
95
|
+
identify(options) {
|
|
96
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
97
|
+
this.ws.send(JSON.stringify({
|
|
98
|
+
op: constants_1.GatewayOPCodes.Identify,
|
|
99
|
+
d: {
|
|
100
|
+
token: options.token,
|
|
101
|
+
properties: {
|
|
102
|
+
os: options.properties.os,
|
|
103
|
+
browser: options.properties.browser,
|
|
104
|
+
device: options.properties.device,
|
|
105
|
+
},
|
|
106
|
+
compress: options.compress,
|
|
107
|
+
large_threshold: options.largeThreshold,
|
|
108
|
+
shard: options.shard,
|
|
109
|
+
presence: options.presence,
|
|
110
|
+
intents: options.intents,
|
|
111
|
+
},
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
140
114
|
}
|
|
141
115
|
onDispatch(packet) {
|
|
142
116
|
this.sequence = packet.s;
|
|
@@ -485,9 +459,9 @@ class Shard {
|
|
|
485
459
|
case constants_1.GatewayEvents.MessageReactionAdd:
|
|
486
460
|
this.client.emit("messageReactionAdd", {
|
|
487
461
|
userId: packet.d.user_id,
|
|
488
|
-
channelId: packet.d.
|
|
489
|
-
messageId: packet.d.
|
|
490
|
-
guildId: packet.d.
|
|
462
|
+
channelId: packet.d.user_id,
|
|
463
|
+
messageId: packet.d.user_id,
|
|
464
|
+
guildId: packet.d.user_id,
|
|
491
465
|
member: packet.d.member !== undefined
|
|
492
466
|
? transformers_1.Guilds.guildMemberFromRaw(packet.d.member)
|
|
493
467
|
: undefined,
|
|
@@ -501,9 +475,9 @@ class Shard {
|
|
|
501
475
|
case constants_1.GatewayEvents.MessageReactionRemove:
|
|
502
476
|
this.client.emit("messageReactionRemove", {
|
|
503
477
|
userId: packet.d.user_id,
|
|
504
|
-
channelId: packet.d.
|
|
505
|
-
messageId: packet.d.
|
|
506
|
-
guildId: packet.d.
|
|
478
|
+
channelId: packet.d.user_id,
|
|
479
|
+
messageId: packet.d.user_id,
|
|
480
|
+
guildId: packet.d.user_id,
|
|
507
481
|
emoji: transformers_1.Emojis.emojiFromRaw(packet.d.emoji),
|
|
508
482
|
burst: packet.d.burst,
|
|
509
483
|
type: packet.d.type,
|
|
@@ -608,7 +582,46 @@ class Shard {
|
|
|
608
582
|
break;
|
|
609
583
|
}
|
|
610
584
|
}
|
|
611
|
-
onWebSocketOpen() {
|
|
585
|
+
onWebSocketOpen(reconnect) {
|
|
586
|
+
if (reconnect) {
|
|
587
|
+
this.resume({
|
|
588
|
+
token: this.client.token,
|
|
589
|
+
sessionId: this.sessionId,
|
|
590
|
+
seq: this.sequence,
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
this.identify({
|
|
595
|
+
token: this.client.token,
|
|
596
|
+
properties: {
|
|
597
|
+
os: this.client.properties?.os ?? process.platform,
|
|
598
|
+
browser: this.client.properties?.browser ?? pkg.name,
|
|
599
|
+
device: this.client.properties?.device ?? pkg.name,
|
|
600
|
+
},
|
|
601
|
+
compress: this.client.compress,
|
|
602
|
+
largeThreshold: this.client.largeThreshold,
|
|
603
|
+
shard: [this.id, this.client.shardsCount],
|
|
604
|
+
presence: this.client.presence !== undefined
|
|
605
|
+
? {
|
|
606
|
+
since: this.client.presence.status === constants_1.StatusTypes.Idle
|
|
607
|
+
? Date.now()
|
|
608
|
+
: null,
|
|
609
|
+
activities: this.client.presence.activities?.map((activity) => ({
|
|
610
|
+
name: activity.type === constants_1.ActivityType.Custom
|
|
611
|
+
? "Custom Status"
|
|
612
|
+
: activity.name,
|
|
613
|
+
type: activity.type,
|
|
614
|
+
url: activity.url,
|
|
615
|
+
state: activity.state,
|
|
616
|
+
})),
|
|
617
|
+
status: this.client.presence.status ?? constants_1.StatusTypes.Online,
|
|
618
|
+
afk: !!this.client.presence.afk,
|
|
619
|
+
}
|
|
620
|
+
: undefined,
|
|
621
|
+
intents: this.client.intents,
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
612
625
|
onWebSocketMessage(data) {
|
|
613
626
|
const packet = JSON.parse(data.toString());
|
|
614
627
|
switch (packet.op) {
|
|
@@ -618,31 +631,25 @@ class Shard {
|
|
|
618
631
|
case constants_1.GatewayOPCodes.Reconnect:
|
|
619
632
|
{
|
|
620
633
|
this.client.emit("reconnect");
|
|
621
|
-
this.
|
|
634
|
+
this.reconnect();
|
|
622
635
|
}
|
|
623
636
|
break;
|
|
624
637
|
case constants_1.GatewayOPCodes.InvalidSession:
|
|
625
638
|
{
|
|
626
639
|
this.client.emit("invalidSession");
|
|
627
640
|
if (packet.d) {
|
|
628
|
-
this.
|
|
641
|
+
this.reconnect();
|
|
629
642
|
}
|
|
630
|
-
else {
|
|
631
|
-
this.
|
|
632
|
-
this.
|
|
633
|
-
this.
|
|
643
|
+
else if (this.ws) {
|
|
644
|
+
this.ws.close(1000, "Invalid Session - Identify required");
|
|
645
|
+
this.ws = new ws_1.default("wss://gateway.discord.gg/?v=10&encoding=json", this.client.ws);
|
|
646
|
+
this.connect(false);
|
|
634
647
|
}
|
|
635
648
|
}
|
|
636
649
|
break;
|
|
637
650
|
case constants_1.GatewayOPCodes.Hello:
|
|
638
651
|
{
|
|
639
|
-
this.heartbeatInterval = setInterval(() => this.
|
|
640
|
-
if (this.sessionId && this.sequence && this.resumeGatewayURL) {
|
|
641
|
-
this.resume();
|
|
642
|
-
}
|
|
643
|
-
else {
|
|
644
|
-
this.identify();
|
|
645
|
-
}
|
|
652
|
+
this.heartbeatInterval = setInterval(() => this.heartbeat(null), packet.d.heartbeat_interval);
|
|
646
653
|
this.client.emit("hello", packet.d.heartbeat_interval, this.id);
|
|
647
654
|
}
|
|
648
655
|
break;
|
|
@@ -655,9 +662,9 @@ class Shard {
|
|
|
655
662
|
throw err;
|
|
656
663
|
}
|
|
657
664
|
onWebSocketClose(code, reason) {
|
|
658
|
-
let reconnect = false;
|
|
659
665
|
switch (code) {
|
|
660
666
|
case 1000:
|
|
667
|
+
this.disconnect();
|
|
661
668
|
break;
|
|
662
669
|
case constants_1.GatewayCloseEventCodes.UnknownError:
|
|
663
670
|
case constants_1.GatewayCloseEventCodes.UnknownOPCode:
|
|
@@ -667,19 +674,95 @@ class Shard {
|
|
|
667
674
|
case constants_1.GatewayCloseEventCodes.InvalidSequence:
|
|
668
675
|
case constants_1.GatewayCloseEventCodes.RateLimited:
|
|
669
676
|
case constants_1.GatewayCloseEventCodes.SessionTimedOut:
|
|
670
|
-
|
|
677
|
+
this.reconnect();
|
|
671
678
|
break;
|
|
672
679
|
default:
|
|
680
|
+
this.disconnect();
|
|
673
681
|
throw new utils_1.GatewayError(code, reason.toString());
|
|
674
682
|
}
|
|
675
|
-
this.disconnect(reconnect);
|
|
676
683
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
684
|
+
/** https://discord.com/developers/docs/events/gateway#resuming */
|
|
685
|
+
reconnect() {
|
|
686
|
+
if (this.ws && this.resumeGatewayURL && this.sessionId && this.sequence) {
|
|
687
|
+
this.ws.close(1000, "Resume Attempt - Reconnect");
|
|
688
|
+
this.ws = new ws_1.default(this.resumeGatewayURL, this.client.ws);
|
|
689
|
+
this.connect(true);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
/** https://discord.com/developers/docs/topics/gateway-events#request-guild-members */
|
|
693
|
+
requestGuildMembers(options) {
|
|
694
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
695
|
+
this.ws.send(JSON.stringify({
|
|
696
|
+
op: constants_1.GatewayOPCodes.RequestGuildMembers,
|
|
697
|
+
d: {
|
|
698
|
+
guild_id: options.guildId,
|
|
699
|
+
query: options.query,
|
|
700
|
+
limit: options.limit,
|
|
701
|
+
presences: options.presences,
|
|
702
|
+
user_ids: options.userIds,
|
|
703
|
+
nonce: options.nonce,
|
|
704
|
+
},
|
|
705
|
+
}));
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
/** https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds */
|
|
709
|
+
requestSoundboardSounds(options) {
|
|
710
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
711
|
+
this.ws.send(JSON.stringify({
|
|
712
|
+
op: constants_1.GatewayOPCodes.RequestSoundboardSounds,
|
|
713
|
+
d: {
|
|
714
|
+
guild_ids: options.guildIds,
|
|
715
|
+
},
|
|
716
|
+
}));
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
/** https://discord.com/developers/docs/topics/gateway-events#resume */
|
|
720
|
+
resume(options) {
|
|
721
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
722
|
+
this.ws.send(JSON.stringify({
|
|
723
|
+
op: constants_1.GatewayOPCodes.Resume,
|
|
724
|
+
d: {
|
|
725
|
+
token: options.token,
|
|
726
|
+
session_id: options.sessionId,
|
|
727
|
+
seq: options.seq,
|
|
728
|
+
},
|
|
729
|
+
}));
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
|
733
|
+
updatePresence(options) {
|
|
734
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
735
|
+
this.ws.send(JSON.stringify({
|
|
736
|
+
op: constants_1.GatewayOPCodes.PresenceUpdate,
|
|
737
|
+
d: {
|
|
738
|
+
since: options.status === constants_1.StatusTypes.Idle ? Date.now() : null,
|
|
739
|
+
activities: options.activities?.map((activity) => ({
|
|
740
|
+
name: activity.type === constants_1.ActivityType.Custom
|
|
741
|
+
? "Custom Status"
|
|
742
|
+
: activity.name,
|
|
743
|
+
type: activity.type,
|
|
744
|
+
url: activity.url,
|
|
745
|
+
state: activity.state,
|
|
746
|
+
})),
|
|
747
|
+
status: options.status ?? constants_1.StatusTypes.Online,
|
|
748
|
+
afk: !!options.afk,
|
|
749
|
+
},
|
|
750
|
+
}));
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
/** https://discord.com/developers/docs/topics/gateway-events#update-voice-state */
|
|
754
|
+
updateVoiceState(options) {
|
|
755
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
756
|
+
this.ws.send(JSON.stringify({
|
|
757
|
+
op: constants_1.GatewayOPCodes.VoiceStateUpdate,
|
|
758
|
+
d: {
|
|
759
|
+
guild_id: options.guildId,
|
|
760
|
+
channel_id: options.channelId,
|
|
761
|
+
self_mute: options.selfMute,
|
|
762
|
+
self_deaf: options.selfDeaf,
|
|
763
|
+
},
|
|
764
|
+
}));
|
|
765
|
+
}
|
|
683
766
|
}
|
|
684
767
|
}
|
|
685
768
|
exports.Shard = Shard;
|
package/dist/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import WebSocket from "ws";
|
|
2
|
-
import { GatewayOPCodes } from "../constants";
|
|
3
|
-
import { GatewayPresenceUpdate, GatewayVoiceStateUpdate, Identify, RequestGuildMembers, RequestSoundboardSounds, Resume } from "../types/gateway-events";
|
|
4
|
-
export declare class WebSocketManager {
|
|
5
|
-
private ws;
|
|
6
|
-
constructor(ws: WebSocket | null);
|
|
7
|
-
send(op: GatewayOPCodes, data: unknown): void;
|
|
8
|
-
/** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
|
|
9
|
-
heartbeat(lastSequence: number | null): void;
|
|
10
|
-
/** https://discord.com/developers/docs/topics/gateway-events#identify */
|
|
11
|
-
identify(options: Identify): void;
|
|
12
|
-
/** https://discord.com/developers/docs/topics/gateway-events#request-guild-members */
|
|
13
|
-
requestGuildMembers(options: RequestGuildMembers): void;
|
|
14
|
-
/** https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds */
|
|
15
|
-
requestSoundboardSounds(options: RequestSoundboardSounds): void;
|
|
16
|
-
/** https://discord.com/developers/docs/topics/gateway-events#resume */
|
|
17
|
-
resume(options: Resume): void;
|
|
18
|
-
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
|
19
|
-
updatePresence(options: Partial<Pick<GatewayPresenceUpdate, "activities" | "status" | "afk">>): void;
|
|
20
|
-
/** https://discord.com/developers/docs/topics/gateway-events#update-voice-state */
|
|
21
|
-
updateVoiceState(options: GatewayVoiceStateUpdate): void;
|
|
22
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WebSocketManager = void 0;
|
|
7
|
-
const ws_1 = __importDefault(require("ws"));
|
|
8
|
-
const constants_1 = require("../constants");
|
|
9
|
-
class WebSocketManager {
|
|
10
|
-
ws;
|
|
11
|
-
constructor(ws) {
|
|
12
|
-
this.ws = ws;
|
|
13
|
-
}
|
|
14
|
-
send(op, data) {
|
|
15
|
-
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
16
|
-
this.ws.send(JSON.stringify({
|
|
17
|
-
op,
|
|
18
|
-
d: data,
|
|
19
|
-
}));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
|
|
23
|
-
heartbeat(lastSequence) {
|
|
24
|
-
this.send(constants_1.GatewayOPCodes.Heartbeat, lastSequence);
|
|
25
|
-
}
|
|
26
|
-
/** https://discord.com/developers/docs/topics/gateway-events#identify */
|
|
27
|
-
identify(options) {
|
|
28
|
-
this.send(constants_1.GatewayOPCodes.Identify, {
|
|
29
|
-
token: options.token,
|
|
30
|
-
properties: {
|
|
31
|
-
os: options.properties.os,
|
|
32
|
-
browser: options.properties.browser,
|
|
33
|
-
device: options.properties.device,
|
|
34
|
-
},
|
|
35
|
-
compress: options.compress,
|
|
36
|
-
large_threshold: options.largeThreshold,
|
|
37
|
-
shard: options.shard,
|
|
38
|
-
presence: options.presence,
|
|
39
|
-
intents: options.intents,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/** https://discord.com/developers/docs/topics/gateway-events#request-guild-members */
|
|
43
|
-
requestGuildMembers(options) {
|
|
44
|
-
this.send(constants_1.GatewayOPCodes.RequestGuildMembers, {
|
|
45
|
-
guild_id: options.guildId,
|
|
46
|
-
query: options.query,
|
|
47
|
-
limit: options.limit,
|
|
48
|
-
presences: options.presences,
|
|
49
|
-
user_ids: options.userIds,
|
|
50
|
-
nonce: options.nonce,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/** https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds */
|
|
54
|
-
requestSoundboardSounds(options) {
|
|
55
|
-
this.send(constants_1.GatewayOPCodes.RequestSoundboardSounds, {
|
|
56
|
-
guild_ids: options.guildIds,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/** https://discord.com/developers/docs/topics/gateway-events#resume */
|
|
60
|
-
resume(options) {
|
|
61
|
-
this.send(constants_1.GatewayOPCodes.Resume, {
|
|
62
|
-
token: options.token,
|
|
63
|
-
session_id: options.sessionId,
|
|
64
|
-
seq: options.seq,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
|
68
|
-
updatePresence(options) {
|
|
69
|
-
this.send(constants_1.GatewayOPCodes.PresenceUpdate, {
|
|
70
|
-
since: options.status === constants_1.StatusTypes.Idle ? Date.now() : null,
|
|
71
|
-
activities: options.activities?.map((activity) => ({
|
|
72
|
-
name: activity.type === constants_1.ActivityType.Custom
|
|
73
|
-
? "Custom Status"
|
|
74
|
-
: activity.name,
|
|
75
|
-
type: activity.type,
|
|
76
|
-
url: activity.url,
|
|
77
|
-
state: activity.state,
|
|
78
|
-
})),
|
|
79
|
-
status: options.status ?? constants_1.StatusTypes.Online,
|
|
80
|
-
afk: !!options.afk,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
/** https://discord.com/developers/docs/topics/gateway-events#update-voice-state */
|
|
84
|
-
updateVoiceState(options) {
|
|
85
|
-
this.send(constants_1.GatewayOPCodes.VoiceStateUpdate, {
|
|
86
|
-
guild_id: options.guildId,
|
|
87
|
-
channel_id: options.channelId,
|
|
88
|
-
self_mute: options.selfMute,
|
|
89
|
-
self_deaf: options.selfDeaf,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.WebSocketManager = WebSocketManager;
|