@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,70 +1,70 @@
1
- "use strict";
2
-
3
- class MultipartData {
4
- constructor() {
5
- this.boundary = "----------------Eris";
6
- this.bufs = [];
7
- }
8
-
9
- attach(fieldName, data, filename) {
10
- if (data === undefined) {
11
- return;
12
- }
13
- let str = "\r\n--" + this.boundary + "\r\nContent-Disposition: form-data; name=\"" + fieldName + "\"";
14
- let contentType;
15
- if (filename) {
16
- str += "; filename=\"" + filename + "\"";
17
- const extension = filename.match(/\.(png|apng|gif|jpg|jpeg|webp|svg|json|csv)$/i);
18
- if (extension) {
19
- let ext = extension[1].toLowerCase();
20
- switch (ext) {
21
- case "png":
22
- case "apng":
23
- case "gif":
24
- case "jpg":
25
- case "jpeg":
26
- case "webp":
27
- case "svg": {
28
- if (ext === "svg") {
29
- ext = "svg+xml";
30
- }
31
- contentType = "image/";
32
- break;
33
- }
34
- case "json": {
35
- contentType = "application/";
36
- break;
37
- }
38
- case "csv": {
39
- contentType = "text/";
40
- break;
41
- }
42
- }
43
- contentType += ext;
44
- }
45
- }
46
-
47
- if (contentType) {
48
- str += `\r\nContent-Type: ${contentType}`;
49
- } else if (ArrayBuffer.isView(data)) {
50
- str += "\r\nContent-Type: application/octet-stream";
51
- if (!(data instanceof Uint8Array)) {
52
- data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
53
- }
54
- } else if (typeof data === "object") {
55
- str += "\r\nContent-Type: application/json";
56
- data = Buffer.from(JSON.stringify(data));
57
- } else {
58
- data = Buffer.from("" + data);
59
- }
60
- this.bufs.push(Buffer.from(str + "\r\n\r\n"));
61
- this.bufs.push(data);
62
- }
63
-
64
- finish() {
65
- this.bufs.push(Buffer.from("\r\n--" + this.boundary + "--"));
66
- return this.bufs;
67
- }
68
- }
69
-
70
- module.exports = MultipartData;
1
+ "use strict";
2
+
3
+ class MultipartData {
4
+ constructor() {
5
+ this.boundary = "----------------Eris";
6
+ this.bufs = [];
7
+ }
8
+
9
+ attach(fieldName, data, filename) {
10
+ if (data === undefined) {
11
+ return;
12
+ }
13
+ let str = "\r\n--" + this.boundary + "\r\nContent-Disposition: form-data; name=\"" + fieldName + "\"";
14
+ let contentType;
15
+ if (filename) {
16
+ str += "; filename=\"" + filename + "\"";
17
+ const extension = filename.match(/\.(png|apng|gif|jpg|jpeg|webp|svg|json|csv)$/i);
18
+ if (extension) {
19
+ let ext = extension[1].toLowerCase();
20
+ switch (ext) {
21
+ case "png":
22
+ case "apng":
23
+ case "gif":
24
+ case "jpg":
25
+ case "jpeg":
26
+ case "webp":
27
+ case "svg": {
28
+ if (ext === "svg") {
29
+ ext = "svg+xml";
30
+ }
31
+ contentType = "image/";
32
+ break;
33
+ }
34
+ case "json": {
35
+ contentType = "application/";
36
+ break;
37
+ }
38
+ case "csv": {
39
+ contentType = "text/";
40
+ break;
41
+ }
42
+ }
43
+ contentType += ext;
44
+ }
45
+ }
46
+
47
+ if (contentType) {
48
+ str += `\r\nContent-Type: ${contentType}`;
49
+ } else if (ArrayBuffer.isView(data)) {
50
+ str += "\r\nContent-Type: application/octet-stream";
51
+ if (!(data instanceof Uint8Array)) {
52
+ data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
53
+ }
54
+ } else if (typeof data === "object") {
55
+ str += "\r\nContent-Type: application/json";
56
+ data = Buffer.from(JSON.stringify(data));
57
+ } else {
58
+ data = Buffer.from("" + data);
59
+ }
60
+ this.bufs.push(Buffer.from(str + "\r\n\r\n"));
61
+ this.bufs.push(data);
62
+ }
63
+
64
+ finish() {
65
+ this.bufs.push(Buffer.from("\r\n--" + this.boundary + "--"));
66
+ return this.bufs;
67
+ }
68
+ }
69
+
70
+ module.exports = MultipartData;
package/lib/util/Opus.js CHANGED
@@ -1,33 +1,33 @@
1
- "use strict";
2
-
3
- let NativeOpus;
4
- let OpusScript;
5
-
6
- module.exports.createOpus = function createOpus(samplingRate, channels, bitrate) {
7
- if (!NativeOpus && !OpusScript) {
8
- try {
9
- NativeOpus = require("@discordjs/opus");
10
- } catch {
11
- try {
12
- OpusScript = require("opusscript");
13
- } catch {} // eslint-disable-line no-empty
14
- }
15
- }
16
-
17
- let opus;
18
- if (NativeOpus) {
19
- opus = new NativeOpus.OpusEncoder(samplingRate, channels);
20
- } else if (OpusScript) {
21
- opus = new OpusScript(samplingRate, channels, OpusScript.Application.AUDIO);
22
- } else {
23
- throw new Error("No opus encoder found, playing non-opus audio will not work.");
24
- }
25
-
26
- if (opus.setBitrate) {
27
- opus.setBitrate(bitrate);
28
- } else if (opus.encoderCTL) {
29
- opus.encoderCTL(4002, bitrate);
30
- }
31
-
32
- return opus;
33
- };
1
+ "use strict";
2
+
3
+ let NativeOpus;
4
+ let OpusScript;
5
+
6
+ module.exports.createOpus = function createOpus(samplingRate, channels, bitrate) {
7
+ if (!NativeOpus && !OpusScript) {
8
+ try {
9
+ NativeOpus = require("@discordjs/opus");
10
+ } catch {
11
+ try {
12
+ OpusScript = require("opusscript");
13
+ } catch {} // eslint-disable-line no-empty
14
+ }
15
+ }
16
+
17
+ let opus;
18
+ if (NativeOpus) {
19
+ opus = new NativeOpus.OpusEncoder(samplingRate, channels);
20
+ } else if (OpusScript) {
21
+ opus = new OpusScript(samplingRate, channels, OpusScript.Application.AUDIO);
22
+ } else {
23
+ throw new Error("No opus encoder found, playing non-opus audio will not work.");
24
+ }
25
+
26
+ if (opus.setBitrate) {
27
+ opus.setBitrate(bitrate);
28
+ } else if (opus.encoderCTL) {
29
+ opus.encoderCTL(4002, bitrate);
30
+ }
31
+
32
+ return opus;
33
+ };
@@ -1,83 +1,83 @@
1
- "use strict";
2
-
3
- const util = require("util");
4
- const Base = require("../structures/Base");
5
-
6
- /**
7
- * Ratelimit requests and release in sequence
8
- * TODO: add latencyref
9
- * @prop {Number} limit How many tokens the bucket can consume in the current interval
10
- * @prop {Boolean} processing Whether the queue is being processed
11
- * @prop {Number} remaining How many tokens the bucket has left in the current interval
12
- * @prop {Number} reset Timestamp of next reset
13
- */
14
- class SequentialBucket {
15
- /**
16
- * Construct a SequentialBucket
17
- * @arg {Number} limit The max number of tokens the bucket can consume per interval
18
- * @arg {Object} [latencyRef] An object
19
- * @arg {Number} latencyRef.latency Interval between consuming tokens
20
- */
21
- constructor(limit, latencyRef = { latency: 0 }) {
22
- this.limit = this.remaining = limit;
23
- this.reset = 0;
24
- this.processing = false;
25
- this.latencyRef = latencyRef;
26
- this._queue = [];
27
- }
28
-
29
- check(override) {
30
- if (this._queue.length === 0) {
31
- if (this.processing) {
32
- clearTimeout(this.processing);
33
- this.processing = false;
34
- }
35
- return;
36
- }
37
- if (this.processing && !override) {
38
- return;
39
- }
40
- const now = Date.now();
41
- const offset = this.latencyRef.latency;
42
- if (!this.reset || this.reset < now - offset) {
43
- this.reset = now - offset;
44
- this.remaining = this.limit;
45
- }
46
- this.last = now;
47
- if (this.remaining <= 0) {
48
- this.processing = setTimeout(() => {
49
- this.processing = false;
50
- this.check(true);
51
- }, Math.max(0, (this.reset || 0) - now + offset) + 1);
52
- return;
53
- }
54
- --this.remaining;
55
- this.processing = true;
56
- this._queue.shift()(() => {
57
- if (this._queue.length > 0) {
58
- this.check(true);
59
- } else {
60
- this.processing = false;
61
- }
62
- });
63
- }
64
-
65
- /**
66
- * Queue something in the SequentialBucket
67
- * @arg {Function} func A function to call when a token can be consumed. The function will be passed a callback argument, which must be called to allow the bucket to continue to work
68
- */
69
- queue(func, short) {
70
- if (short) {
71
- this._queue.unshift(func);
72
- } else {
73
- this._queue.push(func);
74
- }
75
- this.check();
76
- }
77
-
78
- [util.inspect.custom]() {
79
- return Base.prototype[util.inspect.custom].call(this);
80
- }
81
- }
82
-
83
- module.exports = SequentialBucket;
1
+ "use strict";
2
+
3
+ const util = require("util");
4
+ const Base = require("../structures/Base");
5
+
6
+ /**
7
+ * Ratelimit requests and release in sequence
8
+ * TODO: add latencyref
9
+ * @prop {Number} limit How many tokens the bucket can consume in the current interval
10
+ * @prop {Boolean} processing Whether the queue is being processed
11
+ * @prop {Number} remaining How many tokens the bucket has left in the current interval
12
+ * @prop {Number} reset Timestamp of next reset
13
+ */
14
+ class SequentialBucket {
15
+ /**
16
+ * Construct a SequentialBucket
17
+ * @arg {Number} limit The max number of tokens the bucket can consume per interval
18
+ * @arg {Object} [latencyRef] An object
19
+ * @arg {Number} latencyRef.latency Interval between consuming tokens
20
+ */
21
+ constructor(limit, latencyRef = { latency: 0 }) {
22
+ this.limit = this.remaining = limit;
23
+ this.reset = 0;
24
+ this.processing = false;
25
+ this.latencyRef = latencyRef;
26
+ this._queue = [];
27
+ }
28
+
29
+ check(override) {
30
+ if (this._queue.length === 0) {
31
+ if (this.processing) {
32
+ clearTimeout(this.processing);
33
+ this.processing = false;
34
+ }
35
+ return;
36
+ }
37
+ if (this.processing && !override) {
38
+ return;
39
+ }
40
+ const now = Date.now();
41
+ const offset = this.latencyRef.latency;
42
+ if (!this.reset || this.reset < now - offset) {
43
+ this.reset = now - offset;
44
+ this.remaining = this.limit;
45
+ }
46
+ this.last = now;
47
+ if (this.remaining <= 0) {
48
+ this.processing = setTimeout(() => {
49
+ this.processing = false;
50
+ this.check(true);
51
+ }, Math.max(0, (this.reset || 0) - now + offset) + 1);
52
+ return;
53
+ }
54
+ --this.remaining;
55
+ this.processing = true;
56
+ this._queue.shift()(() => {
57
+ if (this._queue.length > 0) {
58
+ this.check(true);
59
+ } else {
60
+ this.processing = false;
61
+ }
62
+ });
63
+ }
64
+
65
+ /**
66
+ * Queue something in the SequentialBucket
67
+ * @arg {Function} func A function to call when a token can be consumed. The function will be passed a callback argument, which must be called to allow the bucket to continue to work
68
+ */
69
+ queue(func, short) {
70
+ if (short) {
71
+ this._queue.unshift(func);
72
+ } else {
73
+ this._queue.push(func);
74
+ }
75
+ this.check();
76
+ }
77
+
78
+ [util.inspect.custom]() {
79
+ return Base.prototype[util.inspect.custom].call(this);
80
+ }
81
+ }
82
+
83
+ module.exports = SequentialBucket;
@@ -1,26 +1,26 @@
1
- const warningMessages = {
2
- CREATE_CHANNEL_OPTIONS: "Passing parentID or reason string arguments directly to createChannel() is deprecated. Use an options object instead.",
3
- CREATE_THREAD_WITHOUT_MESSAGE: "createThreadWithoutMessage() is deprecated. Use createThread() instead.",
4
- DEFAULT_PERMISSION: "Passing a defaultPermission for application commands is deprecated. Use defaultMemberPermissions instead.",
5
- DELETE_MESSAGE_DAYS: "Passing the deleteMessageDays parameter to banGuildMember is deprecated. Use an options object with deleteMessageSeconds instead.",
6
- DM_REACTION_REMOVE: "Passing a userID when using removeMessageReaction() in a DMChannel is deprecated. This behavior is no longer supported by Discord.",
7
- GET_CHANNEL_PINS: "getPins() returning an array of messages is deprecated and will be removed in future versions. Use an options object instead.",
8
- GET_INVITE_WITH_EXPIRATION: "Passing withExpiration to getInvite() is deprecated. This is because Discord now always sends an expiration date when fetching an invite.",
9
- GET_REACTION_BEFORE: "Passing the before parameter to getMessageReaction() is deprecated. Discord no longer supports this parameter.",
10
- GET_NITRO_STICKER_PACKS: "getNitroStickerPacks() is deprecated because standard sticker packs are no longer Nitro locked. Use getStickerPacks() instead.",
11
- MEMBER_PERMISSION: "Member#permission is deprecated. Use Member#permissions instead.",
12
- MESSAGE_REFERENCE: "Passing the content.messageReferenceID option to createMessage() is deprecated. Use the content.messageReference option instead.",
13
- REACTION_USER: "Passing a userID other than \"@me\" to addMessageReaction() is deprecated. Discord no longer supports this parameter.",
14
- PRIVATE_CHANNEL: "Using PrivateChannel is deprecated. Use DMChannel instead, and rename all relevant properties to dmChannel or otherwise where necessary.",
15
- };
16
- const unknownCodeMessage = "You have triggered a deprecated behavior whose warning was implemented improperly. Please report this issue.";
17
-
18
- const emittedCodes = [];
19
-
20
- module.exports = function emitDeprecation(code) {
21
- if (emittedCodes.includes(code)) {
22
- return;
23
- }
24
- emittedCodes.push(code);
25
- process.emitWarning(warningMessages[code] || unknownCodeMessage, "DeprecationWarning", `eris:${code}`);
26
- };
1
+ const warningMessages = {
2
+ CREATE_CHANNEL_OPTIONS: "Passing parentID or reason string arguments directly to createChannel() is deprecated. Use an options object instead.",
3
+ CREATE_THREAD_WITHOUT_MESSAGE: "createThreadWithoutMessage() is deprecated. Use createThread() instead.",
4
+ DEFAULT_PERMISSION: "Passing a defaultPermission for application commands is deprecated. Use defaultMemberPermissions instead.",
5
+ DELETE_MESSAGE_DAYS: "Passing the deleteMessageDays parameter to banGuildMember is deprecated. Use an options object with deleteMessageSeconds instead.",
6
+ DM_REACTION_REMOVE: "Passing a userID when using removeMessageReaction() in a DMChannel is deprecated. This behavior is no longer supported by Discord.",
7
+ GET_CHANNEL_PINS: "getPins() returning an array of messages is deprecated and will be removed in future versions. Use an options object instead.",
8
+ GET_INVITE_WITH_EXPIRATION: "Passing withExpiration to getInvite() is deprecated. This is because Discord now always sends an expiration date when fetching an invite.",
9
+ GET_REACTION_BEFORE: "Passing the before parameter to getMessageReaction() is deprecated. Discord no longer supports this parameter.",
10
+ GET_NITRO_STICKER_PACKS: "getNitroStickerPacks() is deprecated because standard sticker packs are no longer Nitro locked. Use getStickerPacks() instead.",
11
+ MEMBER_PERMISSION: "Member#permission is deprecated. Use Member#permissions instead.",
12
+ MESSAGE_REFERENCE: "Passing the content.messageReferenceID option to createMessage() is deprecated. Use the content.messageReference option instead.",
13
+ REACTION_USER: "Passing a userID other than \"@me\" to addMessageReaction() is deprecated. Discord no longer supports this parameter.",
14
+ PRIVATE_CHANNEL: "Using PrivateChannel is deprecated. Use DMChannel instead, and rename all relevant properties to dmChannel or otherwise where necessary.",
15
+ };
16
+ const unknownCodeMessage = "You have triggered a deprecated behavior whose warning was implemented improperly. Please report this issue.";
17
+
18
+ const emittedCodes = [];
19
+
20
+ module.exports = function emitDeprecation(code) {
21
+ if (emittedCodes.includes(code)) {
22
+ return;
23
+ }
24
+ emittedCodes.push(code);
25
+ process.emitWarning(warningMessages[code] || unknownCodeMessage, "DeprecationWarning", `eris:${code}`);
26
+ };