disgroove 3.0.0-dev.a714eda → 3.0.0-dev.fd521a8

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.
@@ -5,7 +5,7 @@ export declare class Shard {
5
5
  id: number;
6
6
  private heartbeatInterval;
7
7
  client: Client;
8
- ws: WebSocket;
8
+ ws: WebSocket | null;
9
9
  sessionId: string | null;
10
10
  resumeGatewayURL: string | null;
11
11
  sequence: number | null;
@@ -14,6 +14,7 @@ export declare class Shard {
14
14
  connect(reconnect: boolean): void;
15
15
  /** https://discord.com/developers/docs/events/gateway#initiating-a-disconnect */
16
16
  disconnect(): void;
17
+ /** https://discord.com/developers/docs/events/gateway#resuming */
17
18
  reconnect(): void;
18
19
  /** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
19
20
  heartbeat(lastSequence: number | null): void;
@@ -44,13 +44,15 @@ class Shard {
44
44
  this.id = id;
45
45
  this.heartbeatInterval = null;
46
46
  this.client = client;
47
- this.ws = new ws_1.default("wss://gateway.discord.gg/?v=10&encoding=json", client.ws);
47
+ this.ws = new ws_1.default("wss://gateway.discord.gg/?v=10&encoding=json", this.client.ws);
48
48
  this.sessionId = null;
49
49
  this.resumeGatewayURL = null;
50
50
  this.sequence = null;
51
51
  }
52
52
  /** https://discord.com/developers/docs/topics/gateway#connections */
53
53
  connect(reconnect) {
54
+ if (!this.ws)
55
+ return;
54
56
  this.ws.on("open", () => this.onWebSocketOpen(reconnect));
55
57
  this.ws.on("message", (data) => this.onWebSocketMessage(data));
56
58
  this.ws.on("error", (err) => this.onWebSocketError(err));
@@ -58,16 +60,21 @@ class Shard {
58
60
  }
59
61
  /** https://discord.com/developers/docs/events/gateway#initiating-a-disconnect */
60
62
  disconnect() {
63
+ if (!this.ws)
64
+ return;
61
65
  if (this.heartbeatInterval) {
62
66
  clearInterval(this.heartbeatInterval);
63
67
  this.heartbeatInterval = null;
64
68
  }
65
- this.ws.close(1000, "Session Invalidated - Disconnect");
69
+ if (this.ws.readyState !== ws_1.default.CLOSED) {
70
+ this.ws.removeAllListeners();
71
+ this.ws.close(1000, "Session Invalidated - Disconnect");
72
+ this.ws = null;
73
+ }
66
74
  }
75
+ /** https://discord.com/developers/docs/events/gateway#resuming */
67
76
  reconnect() {
68
- if (this.resumeGatewayURL !== null &&
69
- this.sessionId !== null &&
70
- this.sequence !== null) {
77
+ if (this.ws && this.resumeGatewayURL && this.sessionId && this.sequence) {
71
78
  this.ws.close(1000, "Resume Attempt - Reconnect");
72
79
  this.ws = new ws_1.default(this.resumeGatewayURL, this.client.ws);
73
80
  this.connect(true);
@@ -75,6 +82,8 @@ class Shard {
75
82
  }
76
83
  /** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
77
84
  heartbeat(lastSequence) {
85
+ if (!this.ws)
86
+ return;
78
87
  this.ws.send(JSON.stringify({
79
88
  op: constants_1.GatewayOPCodes.Heartbeat,
80
89
  d: lastSequence,
@@ -82,6 +91,8 @@ class Shard {
82
91
  }
83
92
  /** https://discord.com/developers/docs/topics/gateway-events#identify */
84
93
  identify(options) {
94
+ if (!this.ws)
95
+ return;
85
96
  this.ws.send(JSON.stringify({
86
97
  op: constants_1.GatewayOPCodes.Identify,
87
98
  d: {
@@ -627,7 +638,7 @@ class Shard {
627
638
  if (packet.d) {
628
639
  this.reconnect();
629
640
  }
630
- else {
641
+ else if (this.ws) {
631
642
  this.ws.close(1000, "Invalid Session - Identify required");
632
643
  this.ws = new ws_1.default("wss://gateway.discord.gg/?v=10&encoding=json", this.client.ws);
633
644
  this.connect(false);
@@ -668,6 +679,8 @@ class Shard {
668
679
  }
669
680
  /** https://discord.com/developers/docs/topics/gateway-events#request-guild-members */
670
681
  requestGuildMembers(options) {
682
+ if (!this.ws)
683
+ return;
671
684
  this.ws.send(JSON.stringify({
672
685
  op: constants_1.GatewayOPCodes.RequestGuildMembers,
673
686
  d: {
@@ -682,6 +695,8 @@ class Shard {
682
695
  }
683
696
  /** https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds */
684
697
  requestSoundboardSounds(options) {
698
+ if (!this.ws)
699
+ return;
685
700
  this.ws.send(JSON.stringify({
686
701
  op: constants_1.GatewayOPCodes.RequestSoundboardSounds,
687
702
  d: {
@@ -691,6 +706,8 @@ class Shard {
691
706
  }
692
707
  /** https://discord.com/developers/docs/topics/gateway-events#resume */
693
708
  resume(options) {
709
+ if (!this.ws)
710
+ return;
694
711
  this.ws.send(JSON.stringify({
695
712
  op: constants_1.GatewayOPCodes.Resume,
696
713
  d: {
@@ -702,6 +719,8 @@ class Shard {
702
719
  }
703
720
  /** https://discord.com/developers/docs/topics/gateway-events#update-presence */
704
721
  updatePresence(options) {
722
+ if (!this.ws)
723
+ return;
705
724
  this.ws.send(JSON.stringify({
706
725
  op: constants_1.GatewayOPCodes.PresenceUpdate,
707
726
  d: {
@@ -721,6 +740,8 @@ class Shard {
721
740
  }
722
741
  /** https://discord.com/developers/docs/topics/gateway-events#update-voice-state */
723
742
  updateVoiceState(options) {
743
+ if (!this.ws)
744
+ return;
724
745
  this.ws.send(JSON.stringify({
725
746
  op: constants_1.GatewayOPCodes.VoiceStateUpdate,
726
747
  d: {
@@ -2,4 +2,6 @@ import type { RawApplication, Application } from "../types/application";
2
2
  export declare class Applications {
3
3
  static applicationFromRaw(application: RawApplication): Application;
4
4
  static applicationToRaw(application: Application): RawApplication;
5
+ static partialApplicationFromRaw(application: Partial<RawApplication>): Partial<Application>;
6
+ static partialApplicationToRaw(application: Partial<Application>): Partial<RawApplication>;
5
7
  }
@@ -6,6 +6,104 @@ const Teams_1 = require("./Teams");
6
6
  const Users_1 = require("./Users");
7
7
  class Applications {
8
8
  static applicationFromRaw(application) {
9
+ return {
10
+ id: application.id,
11
+ name: application.name,
12
+ icon: application.icon,
13
+ description: application.description,
14
+ rpcOrigins: application.rpc_origins,
15
+ botPublic: application.bot_public,
16
+ botRequireCodeGrant: application.bot_require_code_grant,
17
+ termsOfServiceURL: application.terms_of_service_url,
18
+ privacyPolicyURL: application.privacy_policy_url,
19
+ owner: application.owner !== undefined
20
+ ? Users_1.Users.userFromRaw(application.owner)
21
+ : undefined,
22
+ verifyKey: application.verify_key,
23
+ team: application.team !== null ? Teams_1.Teams.teamFromRaw(application.team) : null,
24
+ guildId: application.guild_id,
25
+ guild: application.guild !== undefined
26
+ ? Guilds_1.Guilds.guildFromRaw(application.guild)
27
+ : undefined,
28
+ primarySKUId: application.primary_sku_id,
29
+ slug: application.slug,
30
+ coverImage: application.cover_image,
31
+ flags: application.flags,
32
+ approximateGuildCount: application.approximate_guild_count,
33
+ approximateUserInstallCount: application.approximate_user_install_count,
34
+ approximateUserAuthorizationCount: application.approximate_user_authorization_count,
35
+ redirectURIs: application.redirect_uris,
36
+ interactionsEndpointURL: application.interactions_endpoint_url,
37
+ roleConnectionsVerificationURL: application.role_connections_verification_url,
38
+ eventWebhooksURL: application.event_webhooks_url,
39
+ eventWebhooksStatus: application.event_webhooks_status,
40
+ eventWebhooksTypes: application.event_webhooks_types,
41
+ tags: application.tags,
42
+ installParams: application.install_params,
43
+ integrationTypesConfig: application.integration_types_config !== undefined
44
+ ? {
45
+ "0": {
46
+ oauth2InstallParams: application.integration_types_config?.[0]
47
+ .oauth2_install_params,
48
+ },
49
+ "1": {
50
+ oauth2InstallParams: application.integration_types_config?.[1]
51
+ .oauth2_install_params,
52
+ },
53
+ }
54
+ : undefined,
55
+ customInstallURL: application.custom_install_url,
56
+ };
57
+ }
58
+ static applicationToRaw(application) {
59
+ return {
60
+ id: application.id,
61
+ name: application.name,
62
+ icon: application.icon,
63
+ description: application.description,
64
+ rpc_origins: application.rpcOrigins,
65
+ bot_public: application.botPublic,
66
+ bot_require_code_grant: application.botRequireCodeGrant,
67
+ terms_of_service_url: application.termsOfServiceURL,
68
+ privacy_policy_url: application.privacyPolicyURL,
69
+ owner: application.owner !== undefined
70
+ ? Users_1.Users.userToRaw(application.owner)
71
+ : undefined,
72
+ verify_key: application.verifyKey,
73
+ team: application.team !== null ? Teams_1.Teams.teamToRaw(application.team) : null,
74
+ guild_id: application.guildId,
75
+ guild: application.guild !== undefined
76
+ ? Guilds_1.Guilds.guildToRaw(application.guild)
77
+ : undefined,
78
+ primary_sku_id: application.primarySKUId,
79
+ slug: application.slug,
80
+ cover_image: application.coverImage,
81
+ flags: application.flags,
82
+ approximate_guild_count: application.approximateGuildCount,
83
+ approximate_user_install_count: application.approximateUserInstallCount,
84
+ approximate_user_authorization_count: application.approximateUserAuthorizationCount,
85
+ redirect_uris: application.redirectURIs,
86
+ interactions_endpoint_url: application.interactionsEndpointURL,
87
+ role_connections_verification_url: application.roleConnectionsVerificationURL,
88
+ event_webhooks_url: application.eventWebhooksURL,
89
+ event_webhooks_status: application.eventWebhooksStatus,
90
+ event_webhooks_types: application.eventWebhooksTypes,
91
+ tags: application.tags,
92
+ install_params: application.installParams,
93
+ integration_types_config: application.integrationTypesConfig !== undefined
94
+ ? {
95
+ "0": {
96
+ oauth2_install_params: application.integrationTypesConfig?.[0].oauth2InstallParams,
97
+ },
98
+ "1": {
99
+ oauth2_install_params: application.integrationTypesConfig?.[1].oauth2InstallParams,
100
+ },
101
+ }
102
+ : undefined,
103
+ custom_install_url: application.customInstallURL,
104
+ };
105
+ }
106
+ static partialApplicationFromRaw(application) {
9
107
  return {
10
108
  id: application.id,
11
109
  name: application.name,
@@ -59,7 +157,7 @@ class Applications {
59
157
  customInstallURL: application.custom_install_url,
60
158
  };
61
159
  }
62
- static applicationToRaw(application) {
160
+ static partialApplicationToRaw(application) {
63
161
  return {
64
162
  id: application.id,
65
163
  name: application.name,
@@ -226,7 +226,7 @@ class Messages {
226
226
  type: message.type,
227
227
  activity: message.activity,
228
228
  application: message.application !== undefined
229
- ? Applications_1.Applications.applicationFromRaw(message.application)
229
+ ? Applications_1.Applications.partialApplicationFromRaw(message.application)
230
230
  : undefined,
231
231
  applicationId: message.application_id,
232
232
  flags: message.flags,
@@ -334,7 +334,7 @@ class Messages {
334
334
  type: message.type,
335
335
  activity: message.activity,
336
336
  application: message.application !== undefined
337
- ? Applications_1.Applications.applicationToRaw(message.application)
337
+ ? Applications_1.Applications.partialApplicationToRaw(message.application)
338
338
  : undefined,
339
339
  application_id: message.applicationId,
340
340
  flags: message.flags,
@@ -16,7 +16,7 @@ export interface RawApplication {
16
16
  privacy_policy_url?: string;
17
17
  owner?: RawUser;
18
18
  verify_key: string;
19
- team?: RawTeam | null;
19
+ team: RawTeam | null;
20
20
  guild_id?: snowflake;
21
21
  guild?: RawGuild;
22
22
  primary_sku_id?: snowflake;
@@ -74,7 +74,7 @@ export interface Application {
74
74
  privacyPolicyURL?: string;
75
75
  owner?: User;
76
76
  verifyKey: string;
77
- team?: Team | null;
77
+ team: Team | null;
78
78
  guildId?: snowflake;
79
79
  guild?: Guild;
80
80
  primarySKUId?: snowflake;
@@ -29,7 +29,7 @@ export interface RawMessage {
29
29
  webhook_id?: snowflake;
30
30
  type: MessageTypes;
31
31
  activity?: RawMessageActivity;
32
- application?: RawApplication;
32
+ application?: Partial<RawApplication>;
33
33
  application_id?: snowflake;
34
34
  flags?: MessageFlags;
35
35
  message_reference?: RawMessageReference;
@@ -228,7 +228,7 @@ export interface Message {
228
228
  webhookId?: snowflake;
229
229
  type: MessageTypes;
230
230
  activity?: MessageActivity;
231
- application?: Application;
231
+ application?: Partial<Application>;
232
232
  applicationId?: snowflake;
233
233
  flags?: MessageFlags;
234
234
  messageReference?: MessageReference;
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "disgroove",
3
- "version": "3.0.0-dev.a714eda",
3
+ "version": "3.0.0-dev.fd521a8",
4
4
  "description": "A module to interface with Discord",
5
5
  "main": "./dist/lib/index.js",
6
6
  "types": "./dist/lib/index.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "disgroove",
3
- "version": "3.0.0-dev.a714eda",
3
+ "version": "3.0.0-dev.fd521a8",
4
4
  "description": "A module to interface with Discord",
5
5
  "main": "./dist/lib/index.js",
6
6
  "types": "./dist/lib/index.d.ts",