cloudstorm 0.3.1 → 0.4.1

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/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2018 DasWolke
1
+ Copyright 2022 DasWolke
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -17,9 +17,7 @@ const { Client } = require("cloudstorm");
17
17
  const bot = new Client(token, { intents: ["GUILDS"] });
18
18
  const startup = async () => {
19
19
  await bot.connect();
20
- bot.on("ready", () => {
21
- console.log("Bot received ready event");
22
- });
20
+ bot.on("ready", () => console.log("Bot received ready event"););
23
21
  };
24
22
  startup().catch(e => {
25
23
  console.error("Error on startup!");
@@ -44,7 +42,7 @@ So an event you receive may look like this:
44
42
  "roles": [],
45
43
  "status": "offline",
46
44
  "user": {
47
- "id": "id"
45
+ "id": "id"
48
46
  }
49
47
  }
50
48
  }
@@ -56,6 +54,6 @@ I've written a general whitepaper on the idea of microservice bots, which you ca
56
54
  You can find the docs at [https://daswolke.github.io/CloudStorm/](https://daswolke.github.io/CloudStorm/)
57
55
 
58
56
  ### Installation:
59
- To install CloudStorm, make sure that you have node 8 or higher and npm installed on your computer.
57
+ To install CloudStorm, make sure that you have node 12 or higher and npm installed on your computer.
60
58
 
61
59
  Then run the following command in a terminal `npm install cloudstorm`
package/dist/Client.d.ts CHANGED
@@ -41,8 +41,9 @@ declare class Client extends EventEmitter {
41
41
  endpoint?: string;
42
42
  };
43
43
  shardManager: ShardManager;
44
- version: any;
44
+ version: string;
45
45
  private _restClient;
46
+ static readonly default: typeof Client;
46
47
  /**
47
48
  * Create a new Client to connect to the Discord gateway.
48
49
  * @param token Token received from creating a discord bot user, which will be used to connect to the gateway.
@@ -62,7 +63,11 @@ declare class Client extends EventEmitter {
62
63
  * Get the GatewayData including recommended amount of shards.
63
64
  * @returns Object with url and shards to use to connect to discord.
64
65
  */
65
- getGatewayBot(): Promise<any>;
66
+ getGatewayBot(): Promise<{
67
+ url: string;
68
+ shards: number;
69
+ session_start_limit: import("discord-typings").SessionStartLimit;
70
+ }>;
66
71
  /**
67
72
  * Disconnect the bot gracefully,
68
73
  * you will receive a 'disconnected' event once the ShardManager successfully closes all shard websocket connections.
@@ -83,7 +88,7 @@ declare class Client extends EventEmitter {
83
88
  * client.presenceUpdate({ status: "dnd", game: { name: "Memes are Dreams" } });
84
89
  * });
85
90
  */
86
- presenceUpdate(data: import("./Types").IPresence): Promise<void>;
91
+ presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
87
92
  /**
88
93
  * Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of a single shard facilitated by this client's ShardManager.
89
94
  * @param shardId id of the shard that should update it's status.
@@ -101,7 +106,7 @@ declare class Client extends EventEmitter {
101
106
  * client.shardPresenceUpdate(0, { status: "dnd", game: { name: "Im shard 0" } });
102
107
  * });
103
108
  */
104
- shardStatusUpdate(shardId: number, data: import("./Types").IPresence): Promise<void>;
109
+ shardStatusUpdate(shardId: number, data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
105
110
  /**
106
111
  * Send an OP 4 VOICE_STATE_UPDATE to Discord. this does **not** allow you to send audio with CloudStorm itself,
107
112
  * it just provides the necessary data for another application to send audio data to Discord.
@@ -121,7 +126,10 @@ declare class Client extends EventEmitter {
121
126
  * client.voiceStateUpdate(0, { guild_id: "id", channel_id: "id", self_mute: false, self_deaf: false });
122
127
  * });
123
128
  */
124
- voiceStateUpdate(shardId: number, data: import("./Types").IVoiceStateUpdate): Promise<void>;
129
+ voiceStateUpdate(shardId: number, data: import("discord-typings").VoiceStateUpdatePayload & {
130
+ self_deaf?: boolean;
131
+ self_mute?: boolean;
132
+ }): Promise<void>;
125
133
  /**
126
134
  * Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
127
135
  * @param shardId id of the shard that should send the payload.
@@ -140,7 +148,9 @@ declare class Client extends EventEmitter {
140
148
  * client.requestGuildMembers(0, { guild_id: "id" });
141
149
  * });
142
150
  */
143
- requestGuildMembers(shardId: number, data: import("./Types").IRequestGuildMembers): Promise<void>;
151
+ requestGuildMembers(shardId: number, data: import("discord-typings").GuildRequestMembersPayload & {
152
+ limit?: number;
153
+ }): Promise<void>;
144
154
  /**
145
155
  * Update the endpoint shard websockets will connect to.
146
156
  * @param gatewayUrl Base gateway wss url to update the cached endpoint to.
package/dist/Client.js CHANGED
@@ -4,13 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  const version = require("../package.json").version;
6
6
  const events_1 = require("events");
7
- let Erlpack;
8
- try {
9
- Erlpack = require("erlpack");
10
- }
11
- catch (e) {
12
- Erlpack = null;
13
- }
14
7
  const Constants_1 = __importDefault(require("./Constants"));
15
8
  const snowtransfer_1 = require("snowtransfer");
16
9
  const ShardManager_1 = __importDefault(require("./ShardManager"));
@@ -24,9 +17,8 @@ class Client extends events_1.EventEmitter {
24
17
  */
25
18
  constructor(token, options = {}) {
26
19
  super();
27
- if (!token) {
20
+ if (!token)
28
21
  throw new Error("Missing token!");
29
- }
30
22
  this.options = {
31
23
  largeGuildThreshold: 250,
32
24
  firstShardId: 0,
@@ -37,7 +29,7 @@ class Client extends events_1.EventEmitter {
37
29
  token: "",
38
30
  ws: {
39
31
  compress: true,
40
- socket: undefined
32
+ encoding: "json"
41
33
  }
42
34
  };
43
35
  this._restClient = options.snowtransferInstance ? options.snowtransferInstance : new snowtransfer_1.SnowTransfer(token);
@@ -53,8 +45,8 @@ class Client extends events_1.EventEmitter {
53
45
  * @returns This function returns a promise which is solely used for awaiting the getGateway() method's return value.
54
46
  */
55
47
  async connect() {
56
- const gatewayUrl = await this.getGateway();
57
- this._updateEndpoint(gatewayUrl);
48
+ const gateway = await this.getGateway();
49
+ this._updateEndpoint(gateway);
58
50
  this.shardManager.spawn();
59
51
  }
60
52
  /**
@@ -95,8 +87,7 @@ class Client extends events_1.EventEmitter {
95
87
  * });
96
88
  */
97
89
  async presenceUpdate(data) {
98
- await this.shardManager.presenceUpdate(data);
99
- void undefined;
90
+ return this.shardManager.presenceUpdate(data);
100
91
  }
101
92
  /**
102
93
  * Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of a single shard facilitated by this client's ShardManager.
@@ -159,9 +150,8 @@ class Client extends events_1.EventEmitter {
159
150
  * });
160
151
  */
161
152
  requestGuildMembers(shardId, data) {
162
- if (!data.guild_id) {
153
+ if (!data.guild_id)
163
154
  throw new Error("You need to pass a guild_id");
164
- }
165
155
  return this.shardManager.requestGuildMembers(shardId, data);
166
156
  }
167
157
  /**
@@ -169,8 +159,9 @@ class Client extends events_1.EventEmitter {
169
159
  * @param gatewayUrl Base gateway wss url to update the cached endpoint to.
170
160
  */
171
161
  _updateEndpoint(gatewayUrl) {
172
- var _a;
173
- this.options.endpoint = `${gatewayUrl}?v=${Constants_1.default.GATEWAY_VERSION}&encoding=${Erlpack ? "etf" : "json"}${((_a = this.options.ws) === null || _a === void 0 ? void 0 : _a.compress) ? "&compress=zlib-stream" : ""}`;
162
+ var _a, _b;
163
+ this.options.endpoint = `${gatewayUrl}?v=${Constants_1.default.GATEWAY_VERSION}&encoding=${((_a = this.options.ws) === null || _a === void 0 ? void 0 : _a.encoding) === "etf" ? "etf" : "json"}${((_b = this.options.ws) === null || _b === void 0 ? void 0 : _b.compress) ? "&compress=zlib-stream" : ""}`;
174
164
  }
175
165
  }
166
+ Client.default = Client;
176
167
  module.exports = Client;
@@ -44,54 +44,6 @@ export declare const GATEWAY_OP_CODES: {
44
44
  */
45
45
  HEARTBEAT_ACK: 11;
46
46
  };
47
- export declare const GATEWAY_VERSION = 9;
48
- declare const _default: {
49
- GATEWAY_OP_CODES: {
50
- /**
51
- * Receive.
52
- */
53
- DISPATCH: 0;
54
- /**
55
- * Send/Receive.
56
- */
57
- HEARTBEAT: 1;
58
- /**
59
- * Send.
60
- */
61
- IDENTIFY: 2;
62
- /**
63
- * Send.
64
- */
65
- PRESENCE_UPDATE: 3;
66
- /**
67
- * Send.
68
- */
69
- VOICE_STATE_UPDATE: 4;
70
- /**
71
- * Send.
72
- */
73
- RESUME: 6;
74
- /**
75
- * Receive.
76
- */
77
- RECONNECT: 7;
78
- /**
79
- * Send.
80
- */
81
- REQUEST_GUILD_MEMBERS: 8;
82
- /**
83
- * Receive.
84
- */
85
- INVALID_SESSION: 9;
86
- /**
87
- * Receive.
88
- */
89
- HELLO: 10;
90
- /**
91
- * Receive.
92
- */
93
- HEARTBEAT_ACK: 11;
94
- };
95
- GATEWAY_VERSION: number;
96
- };
47
+ export declare const GATEWAY_VERSION = 10;
48
+ declare const _default: typeof import("./Constants");
97
49
  export default _default;
package/dist/Constants.js CHANGED
@@ -47,5 +47,5 @@ exports.GATEWAY_OP_CODES = {
47
47
  */
48
48
  HEARTBEAT_ACK: 11
49
49
  };
50
- exports.GATEWAY_VERSION = 9;
51
- exports.default = { GATEWAY_OP_CODES: exports.GATEWAY_OP_CODES, GATEWAY_VERSION: exports.GATEWAY_VERSION };
50
+ exports.GATEWAY_VERSION = 10;
51
+ exports.default = exports;
package/dist/Intents.d.ts CHANGED
@@ -1,29 +1,24 @@
1
- /**
2
- * Resolves bitfields to their numeric form.
3
- * @param bit bit(s) to resolve.
4
- */
5
- declare function resolve(bit?: import("./Types").IntentResolvable): number;
6
- declare const _default: {
7
- flags: {
8
- GUILDS: number;
9
- GUILD_MEMBERS: number;
10
- GUILD_BANS: number;
11
- GUILD_EMOJIS_AND_STICKERS: number;
12
- GUILD_INTEGRATIONS: number;
13
- GUILD_WEBHOOKS: number;
14
- GUILD_INVITES: number;
15
- GUILD_VOICE_STATES: number;
16
- GUILD_PRESENCES: number;
17
- GUILD_MESSAGES: number;
18
- GUILD_MESSAGE_REACTIONS: number;
19
- GUILD_MESSAGE_TYPING: number;
20
- DIRECT_MESSAGES: number;
21
- DIRECT_MESSAGE_REACTIONS: number;
22
- DIRECT_MESSAGE_TYPING: number;
23
- };
24
- all: number;
25
- privileged: number;
26
- non_privileged: number;
27
- resolve: typeof resolve;
1
+ export declare const flags: {
2
+ GUILDS: number;
3
+ GUILD_MEMBERS: number;
4
+ GUILD_BANS: number;
5
+ GUILD_EMOJIS_AND_STICKERS: number;
6
+ GUILD_INTEGRATIONS: number;
7
+ GUILD_WEBHOOKS: number;
8
+ GUILD_INVITES: number;
9
+ GUILD_VOICE_STATES: number;
10
+ GUILD_PRESENCES: number;
11
+ GUILD_MESSAGES: number;
12
+ GUILD_MESSAGE_REACTIONS: number;
13
+ GUILD_MESSAGE_TYPING: number;
14
+ DIRECT_MESSAGES: number;
15
+ DIRECT_MESSAGE_REACTIONS: number;
16
+ DIRECT_MESSAGE_TYPING: number;
17
+ MESSAGE_CONTENT: number;
28
18
  };
29
- export = _default;
19
+ export declare const privileged: number;
20
+ export declare const all: number;
21
+ export declare const non_privileged: number;
22
+ export declare function resolve(bit?: import("./Types").IntentResolvable): number;
23
+ declare const _default: typeof import("./Intents");
24
+ export default _default;
package/dist/Intents.js CHANGED
@@ -1,24 +1,7 @@
1
1
  "use strict";
2
- /**
3
- * Numeric websocket intents. All available properties:
4
- * * `GUILDS`
5
- * * `GUILD_MEMBERS`
6
- * * `GUILD_BANS`
7
- * * `GUILD_EMOJIS_AND_STICKERS`
8
- * * `GUILD_INTEGRATIONS`
9
- * * `GUILD_WEBHOOKS`
10
- * * `GUILD_INVITES`
11
- * * `GUILD_VOICE_STATES`
12
- * * `GUILD_PRESENCES`
13
- * * `GUILD_MESSAGES`
14
- * * `GUILD_MESSAGE_REACTIONS`
15
- * * `GUILD_MESSAGE_TYPING`
16
- * * `DIRECT_MESSAGES`
17
- * * `DIRECT_MESSAGE_REACTIONS`
18
- * * `DIRECT_MESSAGE_TYPING`
19
- * @see {@link https://discord.com/developers/docs/topics/gateway#list-of-intents}
20
- */
21
- const flags = {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolve = exports.non_privileged = exports.all = exports.privileged = exports.flags = void 0;
4
+ exports.flags = {
22
5
  GUILDS: 1 << 0,
23
6
  GUILD_MEMBERS: 1 << 1,
24
7
  GUILD_BANS: 1 << 2,
@@ -34,38 +17,19 @@ const flags = {
34
17
  DIRECT_MESSAGES: 1 << 12,
35
18
  DIRECT_MESSAGE_REACTIONS: 1 << 13,
36
19
  DIRECT_MESSAGE_TYPING: 1 << 14,
20
+ MESSAGE_CONTENT: 1 << 15,
37
21
  };
38
- /**
39
- * Bitfield representing all privileged intents.
40
- * @see {@link https://discord.com/developers/docs/topics/gateway#privileged-intents}
41
- */
42
- const privileged = flags.GUILD_MEMBERS | flags.GUILD_PRESENCES;
43
- /**
44
- * Bitfield representing all intents combined.
45
- */
46
- const all = Object.values(flags).reduce((acc, p) => acc | p, 0);
47
- /**
48
- * Bitfield representing all non-privileged intents.
49
- */
50
- const non_privileged = all & ~privileged;
51
- /**
52
- * Resolves bitfields to their numeric form.
53
- * @param bit bit(s) to resolve.
54
- */
22
+ exports.privileged = exports.flags.GUILD_MEMBERS | exports.flags.GUILD_PRESENCES | exports.flags.GUILD_MESSAGES | exports.flags.MESSAGE_CONTENT;
23
+ exports.all = Object.values(exports.flags).reduce((acc, p) => acc | p, 0);
24
+ exports.non_privileged = exports.all & ~exports.privileged;
55
25
  function resolve(bit = 0) {
56
26
  if (typeof bit === "number" && bit >= 0)
57
27
  return bit;
58
- if (typeof bit === "string" && flags[bit])
59
- return flags[bit] | 0;
60
- // @ts-ignore
28
+ if (typeof bit === "string" && exports.flags[bit])
29
+ return exports.flags[bit] | 0;
61
30
  if (Array.isArray(bit))
62
31
  return bit.map((p) => resolve(p)).reduce((prev, p) => prev | p, 0);
63
32
  throw new RangeError("BITFIELD_INVALID");
64
33
  }
65
- module.exports = {
66
- flags,
67
- all,
68
- privileged,
69
- non_privileged,
70
- resolve
71
- };
34
+ exports.resolve = resolve;
35
+ exports.default = exports;
package/dist/Shard.d.ts CHANGED
@@ -3,7 +3,6 @@ import { EventEmitter } from "events";
3
3
  import DiscordConnector from "./connector/DiscordConnector";
4
4
  interface ShardEvents {
5
5
  disconnect: [number, string, boolean];
6
- error: [string];
7
6
  ready: [boolean];
8
7
  queueIdentify: [number];
9
8
  }
@@ -32,6 +31,7 @@ declare class Shard extends EventEmitter {
32
31
  client: import("./Client");
33
32
  ready: boolean;
34
33
  connector: DiscordConnector;
34
+ static readonly default: typeof Shard;
35
35
  /**
36
36
  * Create a new Shard.
37
37
  * @param id id of the shard.
@@ -54,16 +54,21 @@ declare class Shard extends EventEmitter {
54
54
  * Send an OP 3 PRESENCE_UPDATE to Discord.
55
55
  * @param data Data to send.
56
56
  */
57
- presenceUpdate(data: import("./Types").IPresence): Promise<void>;
57
+ presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
58
58
  /**
59
59
  * Send an OP 4 VOICE_STATE_UPDATE to Discord.
60
60
  * @param data Data to send
61
61
  */
62
- voiceStateUpdate(data: import("./Types").IVoiceStateUpdate): Promise<void>;
62
+ voiceStateUpdate(data: import("discord-typings").VoiceStateUpdatePayload & {
63
+ self_deaf?: boolean;
64
+ self_mute?: boolean;
65
+ }): Promise<void>;
63
66
  /**
64
67
  * Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
65
68
  * @param data Data to send.
66
69
  */
67
- requestGuildMembers(data: import("./Types").IRequestGuildMembers): Promise<void>;
70
+ requestGuildMembers(data: import("discord-typings").GuildRequestMembersPayload & {
71
+ limit?: number;
72
+ }): Promise<void>;
68
73
  }
69
74
  export = Shard;
package/dist/Shard.js CHANGED
@@ -40,15 +40,8 @@ class Shard extends events_1.EventEmitter {
40
40
  this.ready = false;
41
41
  this.emit("disconnect", ...args);
42
42
  });
43
- this.connector.on("error", (err) => {
44
- this.emit("error", err);
45
- });
46
- this.connector.on("ready", (resume) => {
47
- this.emit("ready", resume);
48
- });
49
- this.connector.on("queueIdentify", () => {
50
- this.emit("queueIdentify", this.id);
51
- });
43
+ this.connector.on("ready", (resume) => this.emit("ready", resume));
44
+ this.connector.on("queueIdentify", () => this.emit("queueIdentify", this.id));
52
45
  }
53
46
  /**
54
47
  * Time in ms it took for Discord to ackknowledge an OP 1 HEARTBEAT.
@@ -90,4 +83,5 @@ class Shard extends events_1.EventEmitter {
90
83
  return this.connector.requestGuildMembers(data);
91
84
  }
92
85
  }
86
+ Shard.default = Shard;
93
87
  module.exports = Shard;
@@ -17,6 +17,7 @@ declare class ShardManager {
17
17
  }>;
18
18
  lastConnectionAttempt: number | null;
19
19
  connectQueueInterval: NodeJS.Timeout;
20
+ static readonly default: typeof ShardManager;
20
21
  /**
21
22
  * Create a new ShardManager.
22
23
  */
@@ -55,24 +56,29 @@ declare class ShardManager {
55
56
  * Update the status of all currently connected shards which have been spawned by this manager.
56
57
  * @param data Data to send.
57
58
  */
58
- presenceUpdate(data?: import("./Types").IPresence): Promise<void>;
59
+ presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
59
60
  /**
60
61
  * Update the status of a single connected shard which has been spawned by this manager.
61
62
  * @param shardId id of the shard.
62
63
  * @param data Data to send.
63
64
  */
64
- shardPresenceUpdate(shardId: number, data?: import("./Types").IPresence): Promise<void>;
65
+ shardPresenceUpdate(shardId: number, data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
65
66
  /**
66
67
  * Send an OP 4 VOICE_STATE_UPDATE with a certain shard.
67
68
  * @param shardId id of the shard.
68
69
  * @param data Data to send.
69
70
  */
70
- voiceStateUpdate(shardId: number, data: import("./Types").IVoiceStateUpdate): Promise<void>;
71
+ voiceStateUpdate(shardId: number, data: import("discord-typings").VoiceStateUpdatePayload & {
72
+ self_deaf?: boolean;
73
+ self_mute?: boolean;
74
+ }): Promise<void>;
71
75
  /**
72
76
  * Send an OP 8 REQUEST_GUILD_MEMBERS with a certain shard.
73
77
  * @param shardId id of the shard.
74
78
  * @param data Data to send.
75
79
  */
76
- requestGuildMembers(shardId: number, data: import("./Types").IRequestGuildMembers): Promise<void>;
80
+ requestGuildMembers(shardId: number, data: import("discord-typings").GuildRequestMembersPayload & {
81
+ limit?: number;
82
+ }): Promise<void>;
77
83
  }
78
84
  export = ShardManager;
@@ -15,9 +15,8 @@ class ShardManager {
15
15
  constructor(client) {
16
16
  this.client = client;
17
17
  this.options = client.options;
18
- if (!this.options.connectQueueInterval) {
18
+ if (!this.options.connectQueueInterval)
19
19
  this.options.connectQueueInterval = 1000 * 5;
20
- }
21
20
  this.shards = {};
22
21
  this.connectQueue = [];
23
22
  this.lastConnectionAttempt = null;
@@ -92,9 +91,6 @@ class ShardManager {
92
91
  this.client.emit("shardReady", { id: shard.id, ready: !resume });
93
92
  this._checkReady();
94
93
  });
95
- shard.on("error", (error) => {
96
- this.client.emit("error", error);
97
- });
98
94
  shard.on("disconnect", (code, reason, gracefulClose) => {
99
95
  this.client.emit("debug", `Websocket of shard ${shard.id} closed with code ${code} and reason: ${reason ? reason : "None"}`);
100
96
  if (code === 1000 && gracefulClose) {
@@ -117,9 +113,8 @@ class ShardManager {
117
113
  _checkReady() {
118
114
  for (const shardId in this.shards) {
119
115
  if (this.shards[shardId]) {
120
- if (!this.shards[shardId].ready) {
116
+ if (!this.shards[shardId].ready)
121
117
  return;
122
- }
123
118
  }
124
119
  }
125
120
  this.client.emit("ready");
@@ -130,9 +125,8 @@ class ShardManager {
130
125
  _checkDisconnect() {
131
126
  for (const shardId in this.shards) {
132
127
  if (this.shards[shardId]) {
133
- if (this.shards[shardId].connector.status !== "disconnected") {
128
+ if (this.shards[shardId].connector.status !== "disconnected")
134
129
  return;
135
- }
136
130
  }
137
131
  }
138
132
  this.client.emit("disconnected");
@@ -141,7 +135,7 @@ class ShardManager {
141
135
  * Update the status of all currently connected shards which have been spawned by this manager.
142
136
  * @param data Data to send.
143
137
  */
144
- async presenceUpdate(data = {}) {
138
+ async presenceUpdate(data) {
145
139
  for (const shardKey in this.shards) {
146
140
  if (this.shards[shardKey]) {
147
141
  const shard = this.shards[shardKey];
@@ -154,17 +148,13 @@ class ShardManager {
154
148
  * @param shardId id of the shard.
155
149
  * @param data Data to send.
156
150
  */
157
- shardPresenceUpdate(shardId, data = {}) {
151
+ shardPresenceUpdate(shardId, data) {
158
152
  return new Promise((res, rej) => {
159
153
  const shard = this.shards[shardId];
160
- if (!shard) {
154
+ if (!shard)
161
155
  rej(new Error(`Shard ${shardId} does not exist`));
162
- }
163
- if (!shard.ready) {
164
- shard.once("ready", () => {
165
- shard.presenceUpdate(data).then(result => res(result)).catch(e => rej(e));
166
- });
167
- }
156
+ if (!shard.ready)
157
+ shard.once("ready", () => shard.presenceUpdate(data).then(result => res(result)).catch(e => rej(e)));
168
158
  shard.presenceUpdate(data).then(result => res(result)).catch(e => rej(e));
169
159
  });
170
160
  }
@@ -176,14 +166,10 @@ class ShardManager {
176
166
  voiceStateUpdate(shardId, data) {
177
167
  return new Promise((res, rej) => {
178
168
  const shard = this.shards[shardId];
179
- if (!shard) {
169
+ if (!shard)
180
170
  rej(new Error(`Shard ${shardId} does not exist`));
181
- }
182
- if (!shard.ready) {
183
- shard.once("ready", () => {
184
- shard.voiceStateUpdate(data).then(result => res(result)).catch(e => rej(e));
185
- });
186
- }
171
+ if (!shard.ready)
172
+ shard.once("ready", () => shard.voiceStateUpdate(data).then(result => res(result)).catch(e => rej(e)));
187
173
  shard.voiceStateUpdate(data).then(result => res(result)).catch(e => rej(e));
188
174
  });
189
175
  }
@@ -195,16 +181,13 @@ class ShardManager {
195
181
  requestGuildMembers(shardId, data) {
196
182
  return new Promise((res, rej) => {
197
183
  const shard = this.shards[shardId];
198
- if (!shard) {
184
+ if (!shard)
199
185
  rej(new Error(`Shard ${shardId} does not exist`));
200
- }
201
- if (!shard.ready) {
202
- shard.once("ready", () => {
203
- shard.requestGuildMembers(data).then(result => res(result)).catch(e => rej(e));
204
- });
205
- }
186
+ if (!shard.ready)
187
+ shard.once("ready", () => shard.requestGuildMembers(data).then(result => res(result)).catch(e => rej(e)));
206
188
  shard.requestGuildMembers(data).then(result => res(result)).catch(e => rej(e));
207
189
  });
208
190
  }
209
191
  }
192
+ ShardManager.default = ShardManager;
210
193
  module.exports = ShardManager;
package/dist/Types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import Constants from "./Constants";
2
1
  export interface IntentFlags {
3
2
  GUILDS: number;
4
3
  GUILD_MEMBERS: number;
@@ -18,53 +17,27 @@ export interface IntentFlags {
18
17
  }
19
18
  export declare type IntentResolvable = number | Array<number> | keyof IntentFlags | Array<keyof IntentFlags>;
20
19
  export interface IWSMessage {
21
- op: typeof Constants["GATEWAY_OP_CODES"][keyof typeof Constants.GATEWAY_OP_CODES];
20
+ op: import("discord-typings").GatewayOpcode;
22
21
  d?: any;
23
22
  s?: number;
24
- t?: string;
23
+ t?: import("discord-typings").GatewayEvent;
25
24
  }
26
25
  export interface IGatewayMessage extends IWSMessage {
27
26
  shard_id: number;
28
27
  }
29
- export interface IPresenceActivity {
30
- name: string;
31
- type?: 0 | 1 | 2 | 3 | 5;
32
- url?: string;
33
- }
34
- export interface IPresence {
35
- status?: "online" | "idle" | "dnd" | "offline";
36
- afk?: boolean;
37
- since?: boolean;
38
- activities?: Array<IPresenceActivity> | null;
39
- }
40
28
  export interface IClientOptions {
41
29
  largeGuildThreshold?: number;
42
30
  firstShardId?: number;
43
31
  lastShardId?: number;
44
32
  shardAmount?: number;
45
33
  reconnect?: boolean;
46
- initialPresence?: IPresence;
34
+ initialPresence?: import("discord-typings").GatewayPresenceUpdate;
47
35
  intents?: IntentResolvable;
48
36
  connectQueueInterval?: number;
49
37
  snowtransferInstance?: import("snowtransfer").SnowTransfer;
50
38
  ws?: IClientWSOptions;
51
39
  }
52
- export interface IVoiceStateUpdate {
53
- guild_id: string;
54
- channel_id?: string | null;
55
- self_mute?: boolean;
56
- self_deaf?: boolean;
57
- }
58
- export interface IRequestGuildMembers {
59
- guild_id: string;
60
- query?: string | null;
61
- limit?: number;
62
- }
63
- export interface IShardReady {
64
- id: number;
65
- ready: boolean;
66
- }
67
40
  export interface IClientWSOptions {
68
41
  compress?: boolean;
69
- socket?: import("ws").ClientOptions;
42
+ encoding?: "etf" | "json";
70
43
  }