@zygout/eris 0.19.0 → 0.19.2

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.
Files changed (88) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +71 -80
  3. package/esm.mjs +72 -72
  4. package/index.d.ts +4407 -4397
  5. package/index.js +75 -75
  6. package/lib/Client.js +4708 -4683
  7. package/lib/Constants.d.ts +990 -988
  8. package/lib/Constants.js +1163 -1161
  9. package/lib/command/Command.js +552 -552
  10. package/lib/command/CommandClient.js +460 -460
  11. package/lib/errors/DiscordHTTPError.js +63 -63
  12. package/lib/errors/DiscordRESTError.js +77 -77
  13. package/lib/gateway/Shard.js +3029 -3029
  14. package/lib/gateway/ShardManager.js +164 -164
  15. package/lib/rest/Endpoints.js +172 -172
  16. package/lib/rest/RequestHandler.js +459 -459
  17. package/lib/structures/ApplicationCommand.js +125 -125
  18. package/lib/structures/AutoModerationRule.js +143 -143
  19. package/lib/structures/AutocompleteInteraction.js +80 -80
  20. package/lib/structures/Base.js +81 -81
  21. package/lib/structures/CategoryChannel.js +77 -77
  22. package/lib/structures/Channel.js +98 -98
  23. package/lib/structures/CommandInteraction.js +473 -473
  24. package/lib/structures/ComponentInteraction.js +538 -538
  25. package/lib/structures/DMChannel.js +278 -278
  26. package/lib/structures/Entitlement.js +77 -77
  27. package/lib/structures/ExtendedUser.js +46 -46
  28. package/lib/structures/ForumChannel.js +24 -24
  29. package/lib/structures/GroupChannel.js +106 -106
  30. package/lib/structures/Guild.js +1677 -1677
  31. package/lib/structures/GuildAuditLogEntry.js +190 -190
  32. package/lib/structures/GuildChannel.js +128 -128
  33. package/lib/structures/GuildIntegration.js +99 -99
  34. package/lib/structures/GuildPreview.js +97 -97
  35. package/lib/structures/GuildScheduledEvent.js +176 -176
  36. package/lib/structures/GuildTemplate.js +76 -76
  37. package/lib/structures/GuildTextableChannel.js +260 -260
  38. package/lib/structures/Interaction.js +133 -133
  39. package/lib/structures/Invite.js +143 -143
  40. package/lib/structures/Lobby.js +108 -108
  41. package/lib/structures/LobbyMember.js +59 -59
  42. package/lib/structures/MediaChannel.js +216 -216
  43. package/lib/structures/Member.js +371 -371
  44. package/lib/structures/Message.js +708 -708
  45. package/lib/structures/ModalSubmitInteraction.js +478 -478
  46. package/lib/structures/NewsChannel.js +34 -34
  47. package/lib/structures/NewsThreadChannel.js +12 -12
  48. package/lib/structures/Permission.js +80 -80
  49. package/lib/structures/PermissionOverwrite.js +32 -32
  50. package/lib/structures/PingInteraction.js +39 -39
  51. package/lib/structures/PrivateThreadChannel.js +25 -25
  52. package/lib/structures/PublicThreadChannel.js +26 -26
  53. package/lib/structures/Role.js +163 -163
  54. package/lib/structures/SKU.js +80 -80
  55. package/lib/structures/SoundboardSound.js +79 -79
  56. package/lib/structures/StageChannel.js +59 -59
  57. package/lib/structures/StageInstance.js +55 -55
  58. package/lib/structures/Subscription.js +69 -69
  59. package/lib/structures/TextChannel.js +202 -202
  60. package/lib/structures/ThreadChannel.js +143 -143
  61. package/lib/structures/ThreadMember.js +59 -59
  62. package/lib/structures/UnavailableGuild.js +26 -26
  63. package/lib/structures/UnknownInteraction.js +502 -502
  64. package/lib/structures/User.js +296 -296
  65. package/lib/structures/VoiceChannel.js +166 -166
  66. package/lib/structures/VoiceState.js +84 -84
  67. package/lib/util/BrowserWebSocket.js +76 -76
  68. package/lib/util/Bucket.js +89 -89
  69. package/lib/util/Collection.js +202 -202
  70. package/lib/util/MultipartData.js +70 -70
  71. package/lib/util/Opus.js +33 -33
  72. package/lib/util/SequentialBucket.js +83 -83
  73. package/lib/util/emitDeprecation.js +26 -26
  74. package/lib/voice/Piper.js +300 -300
  75. package/lib/voice/SharedStream.js +238 -238
  76. package/lib/voice/VoiceConnection.js +1440 -1440
  77. package/lib/voice/VoiceConnectionManager.js +151 -151
  78. package/lib/voice/VoiceDataStream.js +22 -22
  79. package/lib/voice/streams/BaseTransformer.js +40 -40
  80. package/lib/voice/streams/DCAOpusTransformer.js +78 -78
  81. package/lib/voice/streams/FFmpegDuplex.js +192 -192
  82. package/lib/voice/streams/FFmpegOggTransformer.js +35 -35
  83. package/lib/voice/streams/FFmpegPCMTransformer.js +26 -26
  84. package/lib/voice/streams/OggOpusTransformer.js +108 -108
  85. package/lib/voice/streams/PCMOpusTransformer.js +61 -61
  86. package/lib/voice/streams/VolumeTransformer.js +50 -50
  87. package/lib/voice/streams/WebmOpusTransformer.js +258 -258
  88. package/package.json +83 -82
@@ -1,164 +1,164 @@
1
- "use strict";
2
-
3
- const Base = require("../structures/Base");
4
- const Collection = require("../util/Collection");
5
- const Shard = require("./Shard");
6
-
7
- class ShardManager extends Collection {
8
- constructor(client, options = {}) {
9
- super(Shard);
10
- this._client = client;
11
-
12
- this.options = Object.assign({
13
- concurrency: 1,
14
- }, options);
15
-
16
- this.buckets = new Map();
17
- this.connectQueue = [];
18
- this.connectTimeout = null;
19
- }
20
-
21
- connect(shard) {
22
- this.connectQueue.push(shard);
23
- this.tryConnect();
24
- }
25
-
26
- setConcurrency(concurrency) {
27
- this.options.concurrency = concurrency;
28
- }
29
-
30
- spawn(id) {
31
- let shard = this.get(id);
32
- if (!shard) {
33
- shard = this.add(new Shard(id, this._client));
34
- shard.on("ready", () => {
35
- /**
36
- * Fired when a shard turns ready
37
- * @event Client#shardReady
38
- * @prop {Number} id The ID of the shard
39
- */
40
- this._client.emit("shardReady", shard.id);
41
- if (this._client.ready) {
42
- return;
43
- }
44
- for (const other of this.values()) {
45
- if (!other.ready) {
46
- return;
47
- }
48
- }
49
- this._client.ready = true;
50
- this._client.startTime = Date.now();
51
- /**
52
- * Fired when all shards turn ready
53
- * @event Client#ready
54
- */
55
- this._client.emit("ready");
56
- }).on("resume", () => {
57
- /**
58
- * Fired when a shard resumes
59
- * @event Client#shardResume
60
- * @prop {Number} id The ID of the shard
61
- */
62
- this._client.emit("shardResume", shard.id);
63
- if (this._client.ready) {
64
- return;
65
- }
66
- for (const other of this.values()) {
67
- if (!other.ready) {
68
- return;
69
- }
70
- }
71
- this._client.ready = true;
72
- this._client.startTime = Date.now();
73
- this._client.emit("ready");
74
- }).on("disconnect", (error) => {
75
- /**
76
- * Fired when a shard disconnects
77
- * @event Client#shardDisconnect
78
- * @prop {Error?} error The error, if any
79
- * @prop {Number} id The ID of the shard
80
- */
81
- this._client.emit("shardDisconnect", error, shard.id);
82
- for (const other of this.values()) {
83
- if (other.ready) {
84
- return;
85
- }
86
- }
87
- this._client.ready = false;
88
- this._client.startTime = 0;
89
- /**
90
- * Fired when all shards disconnect
91
- * @event Client#disconnect
92
- */
93
- this._client.emit("disconnect");
94
- });
95
- }
96
- if (shard.status === "disconnected") {
97
- return this.connect(shard);
98
- }
99
- }
100
-
101
- tryConnect() {
102
- // nothing in queue
103
- if (this.connectQueue.length === 0) {
104
- return;
105
- }
106
-
107
- // loop over the connectQueue
108
- for (const shard of this.connectQueue) {
109
- // find the bucket for our shard
110
- const rateLimitKey = (shard.id % this.options.concurrency) || 0;
111
- const lastConnect = this.buckets.get(rateLimitKey) || 0;
112
-
113
- // has enough time passed since the last connect for this bucket (5s/bucket)?
114
- // alternatively if we have a sessionID, we can skip this check
115
- if (!shard.sessionID && Date.now() - lastConnect < 5000) {
116
- continue;
117
- }
118
-
119
- // Are there any connecting shards in the same bucket we should wait on?
120
- if (this.some((s) => s.connecting && ((s.id % this.options.concurrency) || 0) === rateLimitKey)) {
121
- continue;
122
- }
123
-
124
- // connect the shard
125
- shard.connect();
126
- this.buckets.set(rateLimitKey, Date.now());
127
-
128
- // remove the shard from the queue
129
- const index = this.connectQueue.findIndex((s) => s.id === shard.id);
130
- this.connectQueue.splice(index, 1);
131
- }
132
-
133
- // set the next timeout if we have more shards to connect
134
- if (!this.connectTimeout && this.connectQueue.length > 0) {
135
- this.connectTimeout = setTimeout(() => {
136
- this.connectTimeout = null;
137
- this.tryConnect();
138
- }, 500);
139
- }
140
- }
141
-
142
- _readyPacketCB(shardID) {
143
- const rateLimitKey = (shardID % this.options.concurrency) || 0;
144
- this.buckets.set(rateLimitKey, Date.now());
145
-
146
- this.tryConnect();
147
- }
148
-
149
- toString() {
150
- return `[ShardManager ${this.size}]`;
151
- }
152
-
153
- toJSON(props = []) {
154
- return Base.prototype.toJSON.call(this, [
155
- "buckets",
156
- "connectQueue",
157
- "connectTimeout",
158
- "options",
159
- ...props,
160
- ]);
161
- }
162
- }
163
-
164
- module.exports = ShardManager;
1
+ "use strict";
2
+
3
+ const Base = require("../structures/Base");
4
+ const Collection = require("../util/Collection");
5
+ const Shard = require("./Shard");
6
+
7
+ class ShardManager extends Collection {
8
+ constructor(client, options = {}) {
9
+ super(Shard);
10
+ this._client = client;
11
+
12
+ this.options = Object.assign({
13
+ concurrency: 1,
14
+ }, options);
15
+
16
+ this.buckets = new Map();
17
+ this.connectQueue = [];
18
+ this.connectTimeout = null;
19
+ }
20
+
21
+ connect(shard) {
22
+ this.connectQueue.push(shard);
23
+ this.tryConnect();
24
+ }
25
+
26
+ setConcurrency(concurrency) {
27
+ this.options.concurrency = concurrency;
28
+ }
29
+
30
+ spawn(id) {
31
+ let shard = this.get(id);
32
+ if (!shard) {
33
+ shard = this.add(new Shard(id, this._client));
34
+ shard.on("ready", () => {
35
+ /**
36
+ * Fired when a shard turns ready
37
+ * @event Client#shardReady
38
+ * @prop {Number} id The ID of the shard
39
+ */
40
+ this._client.emit("shardReady", shard.id);
41
+ if (this._client.ready) {
42
+ return;
43
+ }
44
+ for (const other of this.values()) {
45
+ if (!other.ready) {
46
+ return;
47
+ }
48
+ }
49
+ this._client.ready = true;
50
+ this._client.startTime = Date.now();
51
+ /**
52
+ * Fired when all shards turn ready
53
+ * @event Client#ready
54
+ */
55
+ this._client.emit("ready");
56
+ }).on("resume", () => {
57
+ /**
58
+ * Fired when a shard resumes
59
+ * @event Client#shardResume
60
+ * @prop {Number} id The ID of the shard
61
+ */
62
+ this._client.emit("shardResume", shard.id);
63
+ if (this._client.ready) {
64
+ return;
65
+ }
66
+ for (const other of this.values()) {
67
+ if (!other.ready) {
68
+ return;
69
+ }
70
+ }
71
+ this._client.ready = true;
72
+ this._client.startTime = Date.now();
73
+ this._client.emit("ready");
74
+ }).on("disconnect", (error) => {
75
+ /**
76
+ * Fired when a shard disconnects
77
+ * @event Client#shardDisconnect
78
+ * @prop {Error?} error The error, if any
79
+ * @prop {Number} id The ID of the shard
80
+ */
81
+ this._client.emit("shardDisconnect", error, shard.id);
82
+ for (const other of this.values()) {
83
+ if (other.ready) {
84
+ return;
85
+ }
86
+ }
87
+ this._client.ready = false;
88
+ this._client.startTime = 0;
89
+ /**
90
+ * Fired when all shards disconnect
91
+ * @event Client#disconnect
92
+ */
93
+ this._client.emit("disconnect");
94
+ });
95
+ }
96
+ if (shard.status === "disconnected") {
97
+ return this.connect(shard);
98
+ }
99
+ }
100
+
101
+ tryConnect() {
102
+ // nothing in queue
103
+ if (this.connectQueue.length === 0) {
104
+ return;
105
+ }
106
+
107
+ // loop over the connectQueue
108
+ for (const shard of this.connectQueue) {
109
+ // find the bucket for our shard
110
+ const rateLimitKey = (shard.id % this.options.concurrency) || 0;
111
+ const lastConnect = this.buckets.get(rateLimitKey) || 0;
112
+
113
+ // has enough time passed since the last connect for this bucket (5s/bucket)?
114
+ // alternatively if we have a sessionID, we can skip this check
115
+ if (!shard.sessionID && Date.now() - lastConnect < 5000) {
116
+ continue;
117
+ }
118
+
119
+ // Are there any connecting shards in the same bucket we should wait on?
120
+ if (this.some((s) => s.connecting && ((s.id % this.options.concurrency) || 0) === rateLimitKey)) {
121
+ continue;
122
+ }
123
+
124
+ // connect the shard
125
+ shard.connect();
126
+ this.buckets.set(rateLimitKey, Date.now());
127
+
128
+ // remove the shard from the queue
129
+ const index = this.connectQueue.findIndex((s) => s.id === shard.id);
130
+ this.connectQueue.splice(index, 1);
131
+ }
132
+
133
+ // set the next timeout if we have more shards to connect
134
+ if (!this.connectTimeout && this.connectQueue.length > 0) {
135
+ this.connectTimeout = setTimeout(() => {
136
+ this.connectTimeout = null;
137
+ this.tryConnect();
138
+ }, 500);
139
+ }
140
+ }
141
+
142
+ _readyPacketCB(shardID) {
143
+ const rateLimitKey = (shardID % this.options.concurrency) || 0;
144
+ this.buckets.set(rateLimitKey, Date.now());
145
+
146
+ this.tryConnect();
147
+ }
148
+
149
+ toString() {
150
+ return `[ShardManager ${this.size}]`;
151
+ }
152
+
153
+ toJSON(props = []) {
154
+ return Base.prototype.toJSON.call(this, [
155
+ "buckets",
156
+ "connectQueue",
157
+ "connectTimeout",
158
+ "options",
159
+ ...props,
160
+ ]);
161
+ }
162
+ }
163
+
164
+ module.exports = ShardManager;