disgroove 3.0.0-dev.72bf12 → 3.0.0-dev.950983e

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.
@@ -41,6 +41,7 @@ export interface GatewayOptions {
41
41
  export interface ClientOptions {
42
42
  shardsCount?: number | "auto";
43
43
  auth?: "Bot" | "Bearer";
44
+ reconnect?: boolean;
44
45
  gateway?: GatewayOptions;
45
46
  ws?: WebSocketOptions;
46
47
  }
@@ -53,9 +54,10 @@ export declare class Client extends EventEmitter {
53
54
  intents: GatewayIntents | number;
54
55
  shardsCount: number | "auto";
55
56
  auth: "Bot" | "Bearer";
57
+ reconnect: boolean;
56
58
  shards: Map<number, Shard>;
57
59
  rest: RequestManager;
58
- guildShardMap: Record<string, number>;
60
+ guildShardMap: Map<string, number>;
59
61
  user: User | null;
60
62
  guilds: Map<string, Guild>;
61
63
  application: Pick<Application, "id" | "flags"> | null;
@@ -18,6 +18,7 @@ class Client extends node_events_1.default {
18
18
  intents;
19
19
  shardsCount;
20
20
  auth;
21
+ reconnect;
21
22
  shards;
22
23
  rest;
23
24
  guildShardMap;
@@ -40,9 +41,10 @@ class Client extends node_events_1.default {
40
41
  : 0;
41
42
  this.shardsCount = options?.shardsCount ?? "auto";
42
43
  this.auth = options?.auth ?? "Bot";
44
+ this.reconnect = options?.reconnect ?? true;
43
45
  this.shards = new Map();
44
46
  this.rest = new rest_1.RequestManager(token, this.auth);
45
- this.guildShardMap = {};
47
+ this.guildShardMap = new Map();
46
48
  this.user = null;
47
49
  this.guilds = new Map();
48
50
  this.application = null;
@@ -165,7 +167,7 @@ class Client extends node_events_1.default {
165
167
  : this.shardsCount;
166
168
  for (let i = 0; i < this.shardsCount; i++)
167
169
  this.shards.set(i, new gateway_1.Shard(i, this));
168
- this.shards.forEach((shard) => shard.connect(false));
170
+ this.shards.forEach((shard) => shard.connect());
169
171
  }
170
172
  /** https://discord.com/developers/docs/resources/entitlement#consume-an-entitlement */
171
173
  consumeEntitlement(applicationId, entitlementId) {
@@ -876,7 +878,7 @@ class Client extends node_events_1.default {
876
878
  }
877
879
  /** https://discord.com/developers/docs/events/gateway#initiating-a-disconnect */
878
880
  disconnect() {
879
- this.shards.forEach((shard) => shard.disconnect());
881
+ this.shards.forEach((shard) => shard.disconnect(false));
880
882
  }
881
883
  /** https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule */
882
884
  async editAutoModerationRule(guildId, autoModerationRuleId, options, reason) {
@@ -2361,7 +2363,9 @@ class Client extends node_events_1.default {
2361
2363
  }
2362
2364
  /** https://discord.com/developers/docs/topics/gateway-events#update-voice-state */
2363
2365
  joinVoiceChannel(guildId, channelId, options) {
2364
- this.shards.get(this.guildShardMap[guildId]).updateVoiceState({
2366
+ this.shards
2367
+ .get(this.guildShardMap.get(guildId))
2368
+ .manager.updateVoiceState({
2365
2369
  guildId,
2366
2370
  channelId,
2367
2371
  selfMute: !!options?.selfMute,
@@ -2382,7 +2386,9 @@ class Client extends node_events_1.default {
2382
2386
  }
2383
2387
  /** https://discord.com/developers/docs/topics/gateway-events#update-voice-state */
2384
2388
  leaveVoiceChannel(guildId) {
2385
- this.shards.get(this.guildShardMap[guildId]).updateVoiceState({
2389
+ this.shards
2390
+ .get(this.guildShardMap.get(guildId))
2391
+ .manager.updateVoiceState({
2386
2392
  guildId,
2387
2393
  channelId: null,
2388
2394
  selfMute: false,
@@ -2455,7 +2461,7 @@ class Client extends node_events_1.default {
2455
2461
  }
2456
2462
  /** https://discord.com/developers/docs/topics/gateway-events#update-presence */
2457
2463
  setPresence(options) {
2458
- this.shards.forEach((shard) => shard.updatePresence(options));
2464
+ this.shards.forEach((shard) => shard.manager.updatePresence(options));
2459
2465
  }
2460
2466
  /** https://discord.com/developers/docs/resources/guild-template#sync-guild-template */
2461
2467
  async syncGuildTemplate(guildId, code) {
@@ -1,38 +1,25 @@
1
1
  import WebSocket from "ws";
2
2
  import { Client } from "../Client";
3
- import type { GatewayPresenceUpdate, GatewayVoiceStateUpdate, Identify, RequestGuildMembers, RequestSoundboardSounds, Resume } from "../types/gateway-events";
3
+ import { WebSocketManager } from "./WebSocketManager";
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;
9
10
  sessionId: string | null;
10
11
  resumeGatewayURL: string | null;
11
12
  sequence: number | null;
12
13
  constructor(id: number, client: Client);
13
14
  /** https://discord.com/developers/docs/topics/gateway#connections */
14
- connect(reconnect: boolean): void;
15
+ connect(): void;
15
16
  /** https://discord.com/developers/docs/events/gateway#initiating-a-disconnect */
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;
17
+ disconnect(reconnect: boolean): void;
18
+ identify(): void;
21
19
  private onDispatch;
22
20
  private onWebSocketOpen;
23
21
  private onWebSocketMessage;
24
22
  private onWebSocketError;
25
23
  private onWebSocketClose;
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;
24
+ resume(): void;
38
25
  }
@@ -42,11 +42,13 @@ 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");
45
46
  class Shard {
46
47
  id;
47
48
  heartbeatInterval;
48
49
  client;
49
50
  ws;
51
+ manager;
50
52
  sessionId;
51
53
  resumeGatewayURL;
52
54
  sequence;
@@ -55,62 +57,86 @@ class Shard {
55
57
  this.heartbeatInterval = null;
56
58
  this.client = client;
57
59
  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);
58
61
  this.sessionId = null;
59
62
  this.resumeGatewayURL = null;
60
63
  this.sequence = null;
61
64
  }
62
65
  /** https://discord.com/developers/docs/topics/gateway#connections */
63
- connect(reconnect) {
66
+ connect() {
64
67
  if (this.ws) {
65
- this.ws.on("open", () => this.onWebSocketOpen(reconnect));
68
+ this.ws.on("open", () => this.onWebSocketOpen());
66
69
  this.ws.on("message", (data) => this.onWebSocketMessage(data));
67
70
  this.ws.on("error", (err) => this.onWebSocketError(err));
68
71
  this.ws.on("close", (code, reason) => this.onWebSocketClose(code, reason));
69
72
  }
70
73
  }
71
74
  /** https://discord.com/developers/docs/events/gateway#initiating-a-disconnect */
72
- disconnect() {
75
+ disconnect(reconnect) {
76
+ if (this.heartbeatInterval) {
77
+ clearInterval(this.heartbeatInterval);
78
+ this.heartbeatInterval = null;
79
+ }
73
80
  if (this.ws) {
74
- if (this.heartbeatInterval) {
75
- clearInterval(this.heartbeatInterval);
76
- this.heartbeatInterval = null;
77
- }
78
81
  if (this.ws.readyState !== ws_1.default.CLOSED) {
79
82
  this.ws.removeAllListeners();
80
- this.ws.close(1000, "Session Invalidated - Disconnect");
83
+ if (reconnect &&
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
+ }
81
97
  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();
82
107
  }
83
108
  }
84
109
  }
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
- }
110
+ identify() {
111
+ this.manager.identify({
112
+ token: this.client.token,
113
+ properties: {
114
+ os: this.client.properties?.os ?? process.platform,
115
+ browser: this.client.properties?.browser ?? pkg.name,
116
+ device: this.client.properties?.device ?? pkg.name,
117
+ },
118
+ compress: this.client.compress,
119
+ largeThreshold: this.client.largeThreshold,
120
+ shard: [this.id, this.client.shardsCount],
121
+ presence: this.client.presence !== undefined
122
+ ? {
123
+ since: this.client.presence.status === constants_1.StatusTypes.Idle
124
+ ? Date.now()
125
+ : null,
126
+ activities: this.client.presence.activities?.map((activity) => ({
127
+ name: activity.type === constants_1.ActivityType.Custom
128
+ ? "Custom Status"
129
+ : activity.name,
130
+ type: activity.type,
131
+ url: activity.url,
132
+ state: activity.state,
133
+ })),
134
+ status: this.client.presence.status ?? constants_1.StatusTypes.Online,
135
+ afk: !!this.client.presence.afk,
136
+ }
137
+ : undefined,
138
+ intents: this.client.intents,
139
+ });
114
140
  }
115
141
  onDispatch(packet) {
116
142
  this.sequence = packet.s;
@@ -241,7 +267,7 @@ class Shard {
241
267
  break;
242
268
  case constants_1.GatewayEvents.GuildCreate:
243
269
  {
244
- this.client.guildShardMap[packet.d.id] = this.id;
270
+ this.client.guildShardMap.set(packet.d.id, this.id);
245
271
  this.client.guilds.set(packet.d.id, transformers_1.Guilds.guildFromRaw(packet.d));
246
272
  this.client.emit("guildCreate", transformers_1.Guilds.guildFromRaw(packet.d));
247
273
  }
@@ -254,7 +280,7 @@ class Shard {
254
280
  break;
255
281
  case constants_1.GatewayEvents.GuildDelete:
256
282
  {
257
- delete this.client.guildShardMap[packet.d.id];
283
+ this.client.guildShardMap.delete(packet.d.id);
258
284
  this.client.guilds.delete(packet.d.id);
259
285
  this.client.emit("guildDelete", {
260
286
  id: packet.d.id,
@@ -459,9 +485,9 @@ class Shard {
459
485
  case constants_1.GatewayEvents.MessageReactionAdd:
460
486
  this.client.emit("messageReactionAdd", {
461
487
  userId: packet.d.user_id,
462
- channelId: packet.d.user_id,
463
- messageId: packet.d.user_id,
464
- guildId: packet.d.user_id,
488
+ channelId: packet.d.channel_id,
489
+ messageId: packet.d.message_id,
490
+ guildId: packet.d.guild_id,
465
491
  member: packet.d.member !== undefined
466
492
  ? transformers_1.Guilds.guildMemberFromRaw(packet.d.member)
467
493
  : undefined,
@@ -475,9 +501,9 @@ class Shard {
475
501
  case constants_1.GatewayEvents.MessageReactionRemove:
476
502
  this.client.emit("messageReactionRemove", {
477
503
  userId: packet.d.user_id,
478
- channelId: packet.d.user_id,
479
- messageId: packet.d.user_id,
480
- guildId: packet.d.user_id,
504
+ channelId: packet.d.channel_id,
505
+ messageId: packet.d.message_id,
506
+ guildId: packet.d.guild_id,
481
507
  emoji: transformers_1.Emojis.emojiFromRaw(packet.d.emoji),
482
508
  burst: packet.d.burst,
483
509
  type: packet.d.type,
@@ -582,46 +608,7 @@ class Shard {
582
608
  break;
583
609
  }
584
610
  }
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
- }
611
+ onWebSocketOpen() { }
625
612
  onWebSocketMessage(data) {
626
613
  const packet = JSON.parse(data.toString());
627
614
  switch (packet.op) {
@@ -631,25 +618,31 @@ class Shard {
631
618
  case constants_1.GatewayOPCodes.Reconnect:
632
619
  {
633
620
  this.client.emit("reconnect");
634
- this.reconnect();
621
+ this.disconnect(this.client.reconnect);
635
622
  }
636
623
  break;
637
624
  case constants_1.GatewayOPCodes.InvalidSession:
638
625
  {
639
626
  this.client.emit("invalidSession");
640
627
  if (packet.d) {
641
- this.reconnect();
628
+ this.resume();
642
629
  }
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);
630
+ else {
631
+ this.sequence = null;
632
+ this.sessionId = null;
633
+ this.identify();
647
634
  }
648
635
  }
649
636
  break;
650
637
  case constants_1.GatewayOPCodes.Hello:
651
638
  {
652
- this.heartbeatInterval = setInterval(() => this.heartbeat(null), packet.d.heartbeat_interval);
639
+ this.heartbeatInterval = setInterval(() => this.manager.heartbeat(this.sequence), packet.d.heartbeat_interval);
640
+ if (this.sessionId && this.sequence && this.resumeGatewayURL) {
641
+ this.resume();
642
+ }
643
+ else {
644
+ this.identify();
645
+ }
653
646
  this.client.emit("hello", packet.d.heartbeat_interval, this.id);
654
647
  }
655
648
  break;
@@ -662,9 +655,9 @@ class Shard {
662
655
  throw err;
663
656
  }
664
657
  onWebSocketClose(code, reason) {
658
+ let reconnect = false;
665
659
  switch (code) {
666
660
  case 1000:
667
- this.disconnect();
668
661
  break;
669
662
  case constants_1.GatewayCloseEventCodes.UnknownError:
670
663
  case constants_1.GatewayCloseEventCodes.UnknownOPCode:
@@ -674,95 +667,19 @@ class Shard {
674
667
  case constants_1.GatewayCloseEventCodes.InvalidSequence:
675
668
  case constants_1.GatewayCloseEventCodes.RateLimited:
676
669
  case constants_1.GatewayCloseEventCodes.SessionTimedOut:
677
- this.reconnect();
670
+ reconnect = this.client.reconnect;
678
671
  break;
679
672
  default:
680
- this.disconnect();
681
673
  throw new utils_1.GatewayError(code, reason.toString());
682
674
  }
675
+ this.disconnect(reconnect);
683
676
  }
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
- }
677
+ resume() {
678
+ this.manager.resume({
679
+ token: this.client.token,
680
+ sessionId: this.sessionId,
681
+ seq: this.sequence,
682
+ });
766
683
  }
767
684
  }
768
685
  exports.Shard = Shard;
@@ -0,0 +1,22 @@
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
+ }
@@ -0,0 +1,93 @@
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;
@@ -1,3 +1,4 @@
1
1
  export * as CDN from "./CDN";
2
2
  export * from "./errors";
3
3
  export * from "./formatters";
4
+ export * from "./permissions";
@@ -40,3 +40,4 @@ exports.CDN = void 0;
40
40
  exports.CDN = __importStar(require("./CDN"));
41
41
  __exportStar(require("./errors"), exports);
42
42
  __exportStar(require("./formatters"), exports);
43
+ __exportStar(require("./permissions"), exports);
@@ -0,0 +1,2 @@
1
+ /** https://discord.com/developers/docs/topics/permissions */
2
+ export declare function hasPermission(userPermissions: string, permission: bigint): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasPermission = hasPermission;
4
+ /** https://discord.com/developers/docs/topics/permissions */
5
+ function hasPermission(userPermissions, permission) {
6
+ return (BigInt(userPermissions) & permission) === permission;
7
+ }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "disgroove",
3
- "version": "3.0.0-dev.72bf12",
3
+ "version": "3.0.0-dev.950983e",
4
4
  "description": "A module to interface with Discord",
5
5
  "main": "./dist/lib/index.js",
6
6
  "types": "./dist/lib/index.d.ts",