@zygout/eris 0.0.0-stage → 0.19.0

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 -0
  2. package/README.md +80 -3
  3. package/esm.mjs +72 -0
  4. package/index.d.ts +4397 -0
  5. package/index.js +75 -0
  6. package/lib/Client.js +4683 -0
  7. package/lib/Constants.d.ts +988 -0
  8. package/lib/Constants.js +1161 -0
  9. package/lib/command/Command.js +552 -0
  10. package/lib/command/CommandClient.js +460 -0
  11. package/lib/errors/DiscordHTTPError.js +63 -0
  12. package/lib/errors/DiscordRESTError.js +77 -0
  13. package/lib/gateway/Shard.js +3029 -0
  14. package/lib/gateway/ShardManager.js +164 -0
  15. package/lib/rest/Endpoints.js +172 -0
  16. package/lib/rest/RequestHandler.js +459 -0
  17. package/lib/structures/ApplicationCommand.js +125 -0
  18. package/lib/structures/AutoModerationRule.js +143 -0
  19. package/lib/structures/AutocompleteInteraction.js +80 -0
  20. package/lib/structures/Base.js +81 -0
  21. package/lib/structures/CategoryChannel.js +77 -0
  22. package/lib/structures/Channel.js +98 -0
  23. package/lib/structures/CommandInteraction.js +473 -0
  24. package/lib/structures/ComponentInteraction.js +538 -0
  25. package/lib/structures/DMChannel.js +278 -0
  26. package/lib/structures/Entitlement.js +77 -0
  27. package/lib/structures/ExtendedUser.js +46 -0
  28. package/lib/structures/ForumChannel.js +24 -0
  29. package/lib/structures/GroupChannel.js +106 -0
  30. package/lib/structures/Guild.js +1677 -0
  31. package/lib/structures/GuildAuditLogEntry.js +190 -0
  32. package/lib/structures/GuildChannel.js +128 -0
  33. package/lib/structures/GuildIntegration.js +99 -0
  34. package/lib/structures/GuildPreview.js +97 -0
  35. package/lib/structures/GuildScheduledEvent.js +176 -0
  36. package/lib/structures/GuildTemplate.js +76 -0
  37. package/lib/structures/GuildTextableChannel.js +260 -0
  38. package/lib/structures/Interaction.js +133 -0
  39. package/lib/structures/Invite.js +143 -0
  40. package/lib/structures/Lobby.js +108 -0
  41. package/lib/structures/LobbyMember.js +59 -0
  42. package/lib/structures/MediaChannel.js +216 -0
  43. package/lib/structures/Member.js +371 -0
  44. package/lib/structures/Message.js +708 -0
  45. package/lib/structures/ModalSubmitInteraction.js +478 -0
  46. package/lib/structures/NewsChannel.js +34 -0
  47. package/lib/structures/NewsThreadChannel.js +12 -0
  48. package/lib/structures/Permission.js +80 -0
  49. package/lib/structures/PermissionOverwrite.js +32 -0
  50. package/lib/structures/PingInteraction.js +39 -0
  51. package/lib/structures/PrivateThreadChannel.js +25 -0
  52. package/lib/structures/PublicThreadChannel.js +26 -0
  53. package/lib/structures/Role.js +163 -0
  54. package/lib/structures/SKU.js +80 -0
  55. package/lib/structures/SoundboardSound.js +79 -0
  56. package/lib/structures/StageChannel.js +59 -0
  57. package/lib/structures/StageInstance.js +55 -0
  58. package/lib/structures/Subscription.js +69 -0
  59. package/lib/structures/TextChannel.js +202 -0
  60. package/lib/structures/ThreadChannel.js +143 -0
  61. package/lib/structures/ThreadMember.js +59 -0
  62. package/lib/structures/UnavailableGuild.js +26 -0
  63. package/lib/structures/UnknownInteraction.js +502 -0
  64. package/lib/structures/User.js +296 -0
  65. package/lib/structures/VoiceChannel.js +166 -0
  66. package/lib/structures/VoiceState.js +84 -0
  67. package/lib/util/BrowserWebSocket.js +76 -0
  68. package/lib/util/Bucket.js +89 -0
  69. package/lib/util/Collection.js +202 -0
  70. package/lib/util/MultipartData.js +70 -0
  71. package/lib/util/Opus.js +33 -0
  72. package/lib/util/SequentialBucket.js +83 -0
  73. package/lib/util/emitDeprecation.js +26 -0
  74. package/lib/voice/Piper.js +300 -0
  75. package/lib/voice/SharedStream.js +238 -0
  76. package/lib/voice/VoiceConnection.js +1440 -0
  77. package/lib/voice/VoiceConnectionManager.js +151 -0
  78. package/lib/voice/VoiceDataStream.js +22 -0
  79. package/lib/voice/streams/BaseTransformer.js +40 -0
  80. package/lib/voice/streams/DCAOpusTransformer.js +78 -0
  81. package/lib/voice/streams/FFmpegDuplex.js +192 -0
  82. package/lib/voice/streams/FFmpegOggTransformer.js +35 -0
  83. package/lib/voice/streams/FFmpegPCMTransformer.js +26 -0
  84. package/lib/voice/streams/OggOpusTransformer.js +108 -0
  85. package/lib/voice/streams/PCMOpusTransformer.js +61 -0
  86. package/lib/voice/streams/VolumeTransformer.js +50 -0
  87. package/lib/voice/streams/WebmOpusTransformer.js +258 -0
  88. package/package.json +82 -6
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ const BaseTransformer = require("./BaseTransformer");
4
+
5
+ class PCMOpusTransformer extends BaseTransformer {
6
+ constructor(options = {}) {
7
+ super(options);
8
+
9
+ this.opus = options.opusFactory();
10
+ this.frameSize = options.frameSize || 2880;
11
+ this.pcmSize = options.pcmSize || 11520;
12
+
13
+ this._remainder = null;
14
+ }
15
+
16
+ _destroy(...args) {
17
+ if (this.opus.delete) {
18
+ this.opus.delete();
19
+ }
20
+
21
+ return super._destroy(...args);
22
+ }
23
+
24
+ _flush(cb) {
25
+ if (this._remainder) {
26
+ const buf = Buffer.allocUnsafe(this.pcmSize);
27
+ this._remainder.copy(buf);
28
+ buf.fill(0, this._remainder.length);
29
+ this.push(this.opus.encode(buf, this.frameSize));
30
+ this._remainder = null;
31
+ }
32
+ cb();
33
+ }
34
+
35
+ _transform(chunk, enc, cb) {
36
+ if (this._remainder) {
37
+ chunk = Buffer.concat([this._remainder, chunk]);
38
+ this._remainder = null;
39
+ }
40
+
41
+ if (chunk.length < this.pcmSize) {
42
+ this._remainder = chunk;
43
+ return cb();
44
+ }
45
+
46
+ chunk._index = 0;
47
+
48
+ while (chunk._index + this.pcmSize < chunk.length) {
49
+ chunk._index += this.pcmSize;
50
+ this.push(this.opus.encode(chunk.subarray(chunk._index - this.pcmSize, chunk._index), this.frameSize));
51
+ }
52
+
53
+ if (chunk._index < chunk.length) {
54
+ this._remainder = chunk.subarray(chunk._index);
55
+ }
56
+
57
+ this.setTransformCB(cb);
58
+ }
59
+ }
60
+
61
+ module.exports = PCMOpusTransformer;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ const BaseTransformer = require("./BaseTransformer");
4
+
5
+ class VolumeTransformer extends BaseTransformer {
6
+ constructor(options = {}) {
7
+ super(options);
8
+
9
+ this._remainder = null;
10
+ this.setVolume(1.0);
11
+ }
12
+
13
+ setVolume(volume) {
14
+ if (isNaN(volume) || (volume = +volume) < 0) {
15
+ throw new Error("Invalid volume level: " + volume);
16
+ }
17
+ this.volume = volume;
18
+ this.db = 10 * Math.log(1 + this.volume) / 6.931471805599453;
19
+ }
20
+
21
+ _transform(chunk, enc, cb) {
22
+ if (this._remainder) {
23
+ chunk = Buffer.concat([this._remainder, chunk]);
24
+ this._remainder = null;
25
+ }
26
+
27
+ if (chunk.length < 2) {
28
+ return cb();
29
+ }
30
+
31
+ let buf;
32
+ if (chunk.length & 1) {
33
+ this._remainder = chunk.subarray(chunk.length - 1);
34
+ buf = Buffer.allocUnsafe(chunk.length - 1);
35
+ } else {
36
+ buf = Buffer.allocUnsafe(chunk.length);
37
+ }
38
+
39
+ for (let i = 0, num; i < buf.length - 1; i += 2) {
40
+ // Bind transformed chunk to to 16 bit
41
+ num = ~~(this.db * chunk.readInt16LE(i));
42
+ buf.writeInt16LE(num >= 32767 ? 32767 : num <= -32767 ? -32767 : num, i);
43
+ }
44
+
45
+ this.push(buf);
46
+ this.setTransformCB(cb);
47
+ }
48
+ }
49
+
50
+ module.exports = VolumeTransformer;
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+
3
+ const BaseTransformer = require("./BaseTransformer");
4
+
5
+ // EBML VInt max value is (2 ^ 56 - 2), but JS only supports 2^53
6
+ // 45 = 53 - 8 - check before last 8 bytes
7
+ const MAX_SHIFTED_VINT = Math.pow(2, 45);
8
+
9
+ const STATE_CONTENT = 0;
10
+ const STATE_TAG = 1;
11
+
12
+ const TAG_TYPE_END = 0;
13
+ const TAG_TYPE_START = 1;
14
+ const TAG_TYPE_TAG = 2;
15
+
16
+ const TRACKTYPE_AUDIO = 2; // EBML spec: https://www.matroska.org/technical/specs/index.html#TrackType
17
+
18
+ class WebmOpusTransformer extends BaseTransformer {
19
+ constructor(options = {}) {
20
+ super(options);
21
+
22
+ this._tag_stack = [];
23
+ this._state = STATE_TAG;
24
+ this._total = 0;
25
+ }
26
+
27
+ getVIntLength(buffer, index) {
28
+ let length = 1;
29
+ for (; length <= 8; ++length) {
30
+ if (buffer[index] & (1 << (8 - length))) {
31
+ break;
32
+ }
33
+ }
34
+ if (length > 8) {
35
+ this.emit("debug", new Error(`VInt length ${length} | ${buffer.toString("hex", index, index + length)}`));
36
+ return null;
37
+ }
38
+ if (index + length > buffer.length) {
39
+ return null;
40
+ }
41
+ return length;
42
+ }
43
+
44
+ process(type, info) {
45
+ if (type === TAG_TYPE_TAG) {
46
+ if (info.name === "SimpleBlock" && (info.data.readUInt8(0) & 0xF) === this.firstAudioTrack.TrackNumber) {
47
+ this.push(info.data.subarray(4));
48
+ return;
49
+ }
50
+ if (info.name === "CodecPrivate") {
51
+ const head = info.data.toString("utf8", 0, 8);
52
+ if (head !== "OpusHead") {
53
+ this.emit("error", new Error("Invalid codec: " + head));
54
+ return;
55
+ }
56
+
57
+ this.codecData = {
58
+ version: info.data.readUInt8(8),
59
+ channelCount: info.data.readUInt8(9),
60
+ preSkip: info.data.readUInt16LE(10),
61
+ inputSampleRate: info.data.readUInt32LE(12),
62
+ outputGain: info.data.readUInt16LE(16),
63
+ mappingFamily: info.data.readUInt8(18),
64
+ };
65
+ return;
66
+ }
67
+ }
68
+
69
+ if (!this.firstAudioTrack) {
70
+ if (info.name === "TrackEntry") {
71
+ if (type === TAG_TYPE_START) {
72
+ this.parsingTrack = {};
73
+ } else if (type === TAG_TYPE_END) {
74
+ if (this.parsingTrack.TrackNumber && this.parsingTrack.TrackType === TRACKTYPE_AUDIO) {
75
+ this.firstAudioTrack = this.parsingTrack;
76
+ }
77
+ delete this.parsingTrack;
78
+ }
79
+ return;
80
+ }
81
+ if (this.parsingTrack) {
82
+ if (info.name === "TrackNumber") {
83
+ this.parsingTrack.TrackNumber = info.data[0];
84
+ return;
85
+ }
86
+ if (info.name === "TrackType") {
87
+ this.parsingTrack.TrackType = info.data[0];
88
+ return;
89
+ }
90
+ }
91
+ if (type === TAG_TYPE_END && info.name === "Tracks") {
92
+ this.emit("error", new Error("No audio track"));
93
+ return;
94
+ }
95
+ return;
96
+ }
97
+ }
98
+
99
+ readContent(buffer) {
100
+ const tagObj = this._tag_stack[this._tag_stack.length - 1];
101
+
102
+ if (tagObj.type === "m") {
103
+ this.process(TAG_TYPE_START, tagObj);
104
+ this._state = STATE_TAG;
105
+ return true;
106
+ }
107
+
108
+ if (buffer.length < buffer._index + tagObj.size) {
109
+ return false;
110
+ }
111
+
112
+ tagObj.data = buffer.subarray(buffer._index, buffer._index + tagObj.size);
113
+ buffer._index += tagObj.size;
114
+ this._total += tagObj.size;
115
+ this._state = STATE_TAG;
116
+
117
+ this._tag_stack.pop();
118
+
119
+ this.process(TAG_TYPE_TAG, tagObj);
120
+
121
+ while (this._tag_stack.length > 0) {
122
+ if (this._total < this._tag_stack[this._tag_stack.length - 1].end) {
123
+ break;
124
+ }
125
+ this.process(TAG_TYPE_END, this._tag_stack.pop());
126
+ }
127
+
128
+ return true;
129
+ }
130
+
131
+ readTag(buffer) {
132
+ const tagSize = this.getVIntLength(buffer, buffer._index);
133
+ if (tagSize === null) {
134
+ return false;
135
+ }
136
+
137
+ const size = this.getVIntLength(buffer, buffer._index + tagSize);
138
+ if (size === null) {
139
+ return false;
140
+ }
141
+
142
+ const tagStr = buffer.toString("hex", buffer._index, buffer._index + tagSize);
143
+
144
+ const tagObj = {
145
+ type: "unknown",
146
+ name: "unknown",
147
+ end: this._total + tagSize,
148
+ };
149
+ if (schema[tagStr]) {
150
+ tagObj.type = schema[tagStr].type;
151
+ tagObj.name = schema[tagStr].name;
152
+ }
153
+
154
+ buffer._index += tagSize;
155
+
156
+ let value = buffer[buffer._index] & (1 << (8 - size)) - 1;
157
+ for (let i = 1; i < size; ++i) {
158
+ if (i === 7 && value >= MAX_SHIFTED_VINT && buffer[buffer._index + 7] > 0) {
159
+ tagObj.end = -1; // Special livestreaming int 0x1FFFFFFFFFFFFFF
160
+ break;
161
+ }
162
+ value = (value << 8) + buffer[buffer._index + i];
163
+ }
164
+ if (tagObj.end !== -1) {
165
+ tagObj.end += value + size;
166
+ }
167
+ tagObj.size = value;
168
+
169
+ buffer._index += size;
170
+ this._total += tagSize + size;
171
+ this._state = STATE_CONTENT;
172
+
173
+ this._tag_stack.push(tagObj);
174
+
175
+ return true;
176
+ }
177
+
178
+ _transform(chunk, enc, cb) {
179
+ if (this._remainder) {
180
+ chunk = Buffer.concat([this._remainder, chunk]);
181
+ this._remainder = null;
182
+ }
183
+
184
+ chunk._index = 0;
185
+
186
+ while (chunk._index < chunk.length) {
187
+ if (this._state === STATE_TAG && !this.readTag(chunk)) {
188
+ break;
189
+ }
190
+ if (this._state === STATE_CONTENT && !this.readContent(chunk)) {
191
+ break;
192
+ }
193
+ }
194
+
195
+ if (chunk._index < chunk.length) {
196
+ this._remainder = chunk.subarray(chunk._index);
197
+ }
198
+
199
+ this.setTransformCB(cb);
200
+ }
201
+ }
202
+
203
+ module.exports = WebmOpusTransformer;
204
+
205
+ const schema = {
206
+ "ae": {
207
+ name: "TrackEntry",
208
+ type: "m",
209
+ },
210
+ "d7": {
211
+ name: "TrackNumber",
212
+ type: "u",
213
+ },
214
+ "86": {
215
+ name: "CodecID",
216
+ type: "s",
217
+ },
218
+ "83": {
219
+ name: "TrackType",
220
+ type: "u",
221
+ },
222
+ "1654ae6b": {
223
+ name: "Tracks",
224
+ type: "m",
225
+ },
226
+ "63a2": {
227
+ name: "CodecPrivate",
228
+ type: "b",
229
+ },
230
+ "a3": {
231
+ name: "SimpleBlock",
232
+ type: "b",
233
+ },
234
+ "1a45dfa3": {
235
+ name: "EBML",
236
+ type: "m",
237
+ },
238
+ "18538067": {
239
+ name: "Segment",
240
+ type: "m",
241
+ },
242
+ "114d9b74": {
243
+ name: "SeekHead",
244
+ type: "m",
245
+ },
246
+ "1549a966": {
247
+ name: "Info",
248
+ type: "m",
249
+ },
250
+ "e1": {
251
+ name: "Audio",
252
+ type: "m",
253
+ },
254
+ "1f43b675": {
255
+ name: "Cluster",
256
+ type: "m",
257
+ },
258
+ };
package/package.json CHANGED
@@ -1,6 +1,82 @@
1
- {
2
- "name": "@zygout/eris",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@zygout/eris",
3
+ "version": "0.19.0",
4
+ "description": "A Node.js Discord library, a maintained fork of Eris",
5
+ "main": "./index.js",
6
+ "exports": {
7
+ ".": [
8
+ {
9
+ "require": "./index.js",
10
+ "import": "./esm.mjs"
11
+ },
12
+ "./index.js"
13
+ ],
14
+ "./*": "./*.js",
15
+ "./esm": "./esm.mjs"
16
+ },
17
+ "typings": "./index.d.ts",
18
+ "engines": {
19
+ "node": ">=10.4.0"
20
+ },
21
+ "scripts": {
22
+ "format": "eslint --fix lib examples \"*.{js,mjs,ts}\"",
23
+ "lint": "eslint --max-warnings 0 lib examples \"*.{js,mjs,ts}\""
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/ZyGout/eris.git"
28
+ },
29
+ "keywords": [
30
+ "api",
31
+ "discord",
32
+ "discordapp",
33
+ "eris",
34
+ "wrapper"
35
+ ],
36
+ "author": "abalabahaha",
37
+ "contributors": [
38
+ "ZyGout"
39
+ ],
40
+ "license": "MIT",
41
+ "bugs": {
42
+ "url": "https://github.com/ZyGout/eris/issues"
43
+ },
44
+ "homepage": "https://github.com/ZyGout/eris#readme",
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "dependencies": {
49
+ "ws": "^8.2.3"
50
+ },
51
+ "devDependencies": {
52
+ "@eslint/js": "^9.9.1",
53
+ "@stylistic/eslint-plugin": "^2.6.4",
54
+ "@types/eslint__js": "^8.42.3",
55
+ "@types/node": "^16.11.7",
56
+ "@types/ws": "^8.2.0",
57
+ "eslint": "^9.9.1",
58
+ "eslint-plugin-jsdoc": "^50.2.2",
59
+ "eslint-plugin-sort-class-members": "^1.20.0",
60
+ "globals": "^15.9.0",
61
+ "typescript": "^5.5.3",
62
+ "typescript-eslint": "^8.2.0"
63
+ },
64
+ "optionalDependencies": {
65
+ "@snazzah/davey": "^0.2.0",
66
+ "@stablelib/xchacha20poly1305": "~1.0.1",
67
+ "opusscript": "^0.0.8"
68
+ },
69
+ "browser": {
70
+ "@discordjs/opus": false,
71
+ "@snazzah/davey": false,
72
+ "@stablelib/xchacha20poly1305": false,
73
+ "child_process": false,
74
+ "crypto": false,
75
+ "dgram": false,
76
+ "dns": false,
77
+ "fs": false,
78
+ "sodium-native": false,
79
+ "tls": false,
80
+ "ws": false
81
+ }
82
+ }