@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,296 @@
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const Endpoints = require("../rest/Endpoints");
5
+
6
+ /**
7
+ * Represents a user
8
+ * @prop {Number?} accentColor The user's banner color, or null if no banner color (REST only)
9
+ * @prop {String?} animatedNameplateURL The URL of the user's nameplate asset (always a WEBM)
10
+ * @prop {String?} avatar The hash of the user's avatar, or null if no avatar
11
+ * @prop {Object?} avatarDecorationData The data of the user's avatar decoration, including the asset and sku ID, or null if no avatar decoration
12
+ * @prop {String?} avatarDecorationURL The URL of the user's avatar decoration
13
+ * @prop {String} avatarURL The URL of the user's avatar which can be either a JPG or GIF
14
+ * @prop {String?} banner The hash of the user's banner, or null if no banner (REST only)
15
+ * @prop {String?} bannerURL The URL of the user's banner
16
+ * @prop {Boolean} bot Whether the user is an OAuth bot or not
17
+ * @prop {Object?} collectibles The data for the user's collectibles, including their nameplate, or null if no collectibles. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/user#collectibles) for object structure
18
+ * @prop {Number} createdAt Timestamp of the user's creation
19
+ * @prop {String} defaultAvatar The hash for the default avatar of a user if there is no avatar set
20
+ * @prop {String} defaultAvatarURL The URL of the user's default avatar
21
+ * @prop {String} discriminator The discriminator of the user. If they've migrated to the new username system, this will be "0"
22
+ * @prop {String?} globalName The user's display name, if it is set. For bots, this is the application name
23
+ * @prop {String?} guildTagBadgeURL The URL of the badge of the user's primary guild tag
24
+ * @prop {String} id The ID of the user
25
+ * @prop {String} mention A string that mentions the user
26
+ * @prop {Object?} primaryGuild The user's primary guild (guild tag), or null if not set
27
+ * @prop {String?} primaryGuild.badge The hash of the guild tag badge
28
+ * @prop {Boolean?} primaryGuild.identityEnabled Whether the user is displaying the primary guild's tag. `null` if the identity was cleared by the system
29
+ * @prop {String?} primaryGuild.identityGuildID The ID of the user's primary guild
30
+ * @prop {String?} primaryGuild.tag The text of the guild tag (up to 4 characters)
31
+ * @prop {Number?} publicFlags Publicly visible flags for this user
32
+ * @prop {String} staticAvatarURL The URL of the user's avatar (always a JPG)
33
+ * @prop {String?} staticNameplateURL The static URL of the user's nameplate asset (always a PNG)
34
+ * @prop {Boolean} system Whether the user is an official Discord system user (e.g. urgent messages)
35
+ * @prop {String} username The username of the user
36
+ */
37
+ class User extends Base {
38
+ constructor(data, client) {
39
+ super(data.id);
40
+ if (!client) {
41
+ this._missingClientError = new Error("Missing client in constructor"); // Preserve constructor callstack
42
+ }
43
+ this._client = client;
44
+ this.bot = !!data.bot;
45
+ this.system = !!data.system;
46
+ this.update(data);
47
+ }
48
+
49
+ update(data) {
50
+ if (data.avatar !== undefined) {
51
+ this.avatar = data.avatar;
52
+ }
53
+ if (data.username !== undefined) {
54
+ this.username = data.username;
55
+ }
56
+ if (data.global_name !== undefined) {
57
+ this.globalName = data.global_name;
58
+ }
59
+ if (data.discriminator !== undefined) {
60
+ this.discriminator = data.discriminator;
61
+ }
62
+ if (data.public_flags !== undefined) {
63
+ this.publicFlags = data.public_flags;
64
+ }
65
+ if (data.banner !== undefined) {
66
+ this.banner = data.banner;
67
+ }
68
+ if (data.accent_color !== undefined) {
69
+ this.accentColor = data.accent_color;
70
+ }
71
+ if (data.avatar_decoration_data !== undefined) {
72
+ this.avatarDecorationData = data.avatar_decoration_data;
73
+ }
74
+ if (data.collectibles !== undefined) {
75
+ this.collectibles = data.collectibles;
76
+ }
77
+ if (data.primary_guild !== undefined) {
78
+ this.primaryGuild = data.primary_guild
79
+ ? {
80
+ badge: data.primary_guild.badge,
81
+ identityEnabled: data.primary_guild.identity_enabled,
82
+ identityGuildID: data.primary_guild.identity_guild_id,
83
+ tag: data.primary_guild.tag,
84
+ }
85
+ : null;
86
+ }
87
+ }
88
+
89
+ get animatedNameplateURL() {
90
+ if (!this.collectibles || !this.collectibles.nameplate) {
91
+ return null;
92
+ }
93
+ return Endpoints.CDN_URL + Endpoints.USER_NAMEPLATE(this.collectibles.nameplate.asset, "asset.webm");
94
+ }
95
+
96
+ get avatarDecorationURL() {
97
+ if (!this.avatarDecorationData) {
98
+ return null;
99
+ }
100
+ if (this._missingClientError) {
101
+ throw this._missingClientError;
102
+ }
103
+ return this._client._formatImage(Endpoints.USER_AVATAR_DECORATION(this.avatarDecorationData.asset), "png");
104
+ }
105
+
106
+ get avatarURL() {
107
+ if (this._missingClientError) {
108
+ throw this._missingClientError;
109
+ }
110
+ return this.avatar ? this._client._formatImage(Endpoints.USER_AVATAR(this.id, this.avatar)) : this.defaultAvatarURL;
111
+ }
112
+
113
+ get bannerURL() {
114
+ if (!this.banner) {
115
+ return null;
116
+ }
117
+ if (this._missingClientError) {
118
+ throw this._missingClientError;
119
+ }
120
+ return this._client._formatImage(Endpoints.BANNER(this.id, this.banner));
121
+ }
122
+
123
+ get defaultAvatar() {
124
+ return this.discriminator === "0" ? Base.getDiscordEpoch(this.id) % 6 : this.discriminator % 5;
125
+ }
126
+
127
+ get defaultAvatarURL() {
128
+ return `${Endpoints.CDN_URL}${Endpoints.DEFAULT_USER_AVATAR(this.defaultAvatar)}.png`;
129
+ }
130
+
131
+ get guildTagBadgeURL() {
132
+ if (!this.primaryGuild || !this.primaryGuild.badge || !this.primaryGuild.identityGuildID) {
133
+ return null;
134
+ }
135
+ if (this._missingClientError) {
136
+ throw this._missingClientError;
137
+ }
138
+ return this._client._formatImage(Endpoints.GUILD_TAG_BADGE(this.primaryGuild.identityGuildID, this.primaryGuild.badge), "png");
139
+ }
140
+
141
+ get mention() {
142
+ return `<@${this.id}>`;
143
+ }
144
+
145
+ get staticAvatarURL() {
146
+ if (this._missingClientError) {
147
+ throw this._missingClientError;
148
+ }
149
+ return this.avatar ? this._client._formatImage(Endpoints.USER_AVATAR(this.id, this.avatar), "jpg") : this.defaultAvatarURL;
150
+ }
151
+
152
+ get staticNameplateURL() {
153
+ if (!this.collectibles || !this.collectibles.nameplate) {
154
+ return null;
155
+ }
156
+ return Endpoints.CDN_URL + Endpoints.USER_NAMEPLATE(this.collectibles.nameplate.asset, "static.png");
157
+ }
158
+
159
+ /**
160
+ * Create a test entitlement for this user
161
+ * @arg {String} skuID The ID of the SKU to grant to the user
162
+ * @returns {Promise<Entitlement>}
163
+ */
164
+ createTestEntitlement(skuID) {
165
+ return this._client.createTestEntitlement.call(this._client, {
166
+ ownerID: this.id,
167
+ ownerType: 2,
168
+ skuID: skuID,
169
+ });
170
+ }
171
+
172
+ /**
173
+ * Delete an application identity of this user, along with its profile data
174
+ * @arg {String} providerType The type of the external account provider
175
+ * @arg {String} providerIssuedUserID The ID of the user in the external system
176
+ * @arg {String} [providerID] The ID used by the provider to tell identities with the same type and user ID apart
177
+ * @returns {Promise}
178
+ */
179
+ deleteApplicationIdentity(providerType, providerIssuedUserID, providerID) {
180
+ return this._client.deleteApplicationIdentity.call(this._client, this.id, providerType, providerIssuedUserID, providerID);
181
+ }
182
+
183
+ /**
184
+ * Get the user's avatar with the given format and size
185
+ * @arg {String} [format] The filetype of the avatar ("jpg", "jpeg", "png", "gif", or "webp")
186
+ * @arg {Number} [size] The size of the avatar (any power of two between 16 and 4096)
187
+ * @returns {String}
188
+ */
189
+ dynamicAvatarURL(format, size) {
190
+ if (!this.avatar) {
191
+ return this.defaultAvatarURL;
192
+ }
193
+ if (this._missingClientError) {
194
+ throw this._missingClientError;
195
+ }
196
+ return this._client._formatImage(Endpoints.USER_AVATAR(this.id, this.avatar), format, size);
197
+ }
198
+
199
+ /**
200
+ * Get the user's banner with the given format and size
201
+ * @arg {String} [format] The filetype of the banner ("jpg", "jpeg", "png", "gif", or "webp")
202
+ * @arg {Number} [size] The size of the banner (any power of two between 16 and 4096)
203
+ * @returns {String?}
204
+ */
205
+ dynamicBannerURL(format, size) {
206
+ if (!this.banner) {
207
+ return null;
208
+ }
209
+ if (this._missingClientError) {
210
+ throw this._missingClientError;
211
+ }
212
+ return this._client._formatImage(Endpoints.BANNER(this.id, this.banner), format, size);
213
+ }
214
+
215
+ /**
216
+ * Get the guild tag badge of the user with the given format and size
217
+ * @arg {String} [format] The filetype of the badge ("jpg", "jpeg", "png", or "webp")
218
+ * @arg {Number} [size] The size of the badge (any power of two between 16 and 4096)
219
+ * @returns {String?}
220
+ */
221
+ dynamicGuildTagBadgeURL(format, size) {
222
+ if (!this.primaryGuild || !this.primaryGuild.badge || !this.primaryGuild.identityGuildID) {
223
+ return null;
224
+ }
225
+ if (this._missingClientError) {
226
+ throw this._missingClientError;
227
+ }
228
+ return this._client._formatImage(Endpoints.GUILD_TAG_BADGE(this.primaryGuild.identityGuildID, this.primaryGuild.badge), format, size);
229
+ }
230
+
231
+ /**
232
+ * Edit the game profile of this user, shown in the game stats widgets of their Discord profile
233
+ * @arg {String} providerIssuedUserID The ID of the user in your system
234
+ * @arg {Object} options The properties to edit. See `Client#editApplicationIdentityProfile` for the full list of options
235
+ * @returns {Promise<Object?>}
236
+ */
237
+ editApplicationIdentityProfile(providerIssuedUserID, options) {
238
+ return this._client.editApplicationIdentityProfile.call(this._client, this.id, providerIssuedUserID, options);
239
+ }
240
+
241
+ /**
242
+ * Get the application identities of this user, without their profile data
243
+ * @returns {Promise<Array<Object>>}
244
+ */
245
+ getApplicationIdentities() {
246
+ return this._client.getUserApplicationIdentities.call(this._client, this.id);
247
+ }
248
+
249
+ /**
250
+ * Get the game profile of this user, shown in the game stats widgets of their Discord profile
251
+ * @arg {String} providerIssuedUserID The ID of the user in your system
252
+ * @returns {Promise<Object>}
253
+ */
254
+ getApplicationIdentityProfile(providerIssuedUserID) {
255
+ return this._client.getApplicationIdentityProfile.call(this._client, this.id, providerIssuedUserID);
256
+ }
257
+
258
+ /**
259
+ * Get a DM channel with the user, or create one if it does not exist
260
+ * @returns {Promise<DMChannel>}
261
+ */
262
+ getDMChannel() {
263
+ return this._client.getDMChannel.call(this._client, this.id);
264
+ }
265
+
266
+ /**
267
+ * Get the entitlements of this user
268
+ * @arg {Object} [options] Options for the request. See `Client#getEntitlements` for the full list of options (`userID` is ignored)
269
+ * @returns {Promise<Array<Entitlement>>}
270
+ */
271
+ getEntitlements(options = {}) {
272
+ return this._client.getEntitlements.call(this._client, Object.assign({}, options, {
273
+ userID: this.id,
274
+ }));
275
+ }
276
+
277
+ toJSON(props = []) {
278
+ return super.toJSON([
279
+ "accentColor",
280
+ "avatar",
281
+ "avatarDecorationData",
282
+ "banner",
283
+ "bot",
284
+ "collectibles",
285
+ "discriminator",
286
+ "globalName",
287
+ "primaryGuild",
288
+ "publicFlags",
289
+ "system",
290
+ "username",
291
+ ...props,
292
+ ]);
293
+ }
294
+ }
295
+
296
+ module.exports = User;
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+
3
+ const Collection = require("../util/Collection");
4
+ const GuildTextableChannel = require("./GuildTextableChannel");
5
+ const Member = require("./Member");
6
+ const PermissionOverwrite = require("./PermissionOverwrite");
7
+
8
+ /**
9
+ * Represents a guild voice channel. See GuildTextableChannel for more properties and methods
10
+ * @extends GuildTextableChannel
11
+ * @prop {Number?} bitrate The bitrate of the channel
12
+ * @prop {Boolean} nsfw Whether the channel is an NSFW channel or not
13
+ * @prop {Collection<PermissionOverwrite>} permissionOverwrites Collection of PermissionOverwrites in the channel
14
+ * @prop {Number} position The position of the channel
15
+ * @prop {String?} rtcRegion The RTC region ID of the channel (automatic when `null`)
16
+ * @prop {String?} status The voice channel status
17
+ * @prop {Number?} userLimit The max number of users that can join the channel
18
+ * @prop {Number?} videoQualityMode The camera video quality mode of the voice channel. `1` is auto, `2` is 720p
19
+ * @prop {Collection<Member>} voiceMembers Collection of Members in this channel
20
+ * @prop {Number?} voiceStartTime Timestamp of when the current voice session of the channel started. Only available after a `voiceChannelStartTimeUpdate` event or `Guild#fetchChannelInfo()`
21
+ */
22
+ class VoiceChannel extends GuildTextableChannel {
23
+ constructor(data, client) {
24
+ super(data, client);
25
+ this.voiceMembers = new Collection(Member);
26
+ this.update(data);
27
+ }
28
+
29
+ update(data) {
30
+ super.update(data);
31
+ if (data.position !== undefined) {
32
+ this.position = data.position;
33
+ }
34
+ if (data.permission_overwrites !== undefined) {
35
+ this.permissionOverwrites = new Collection(PermissionOverwrite);
36
+ data.permission_overwrites.forEach((overwrite) => {
37
+ this.permissionOverwrites.add(overwrite);
38
+ });
39
+ }
40
+ if (data.nsfw !== undefined) {
41
+ this.nsfw = data.nsfw;
42
+ }
43
+ if (data.bitrate !== undefined) {
44
+ this.bitrate = data.bitrate;
45
+ }
46
+ if (data.user_limit !== undefined) {
47
+ this.userLimit = data.user_limit;
48
+ }
49
+ if (data.rtc_region !== undefined) {
50
+ this.rtcRegion = data.rtc_region;
51
+ }
52
+ if (data.video_quality_mode !== undefined) {
53
+ this.videoQualityMode = data.video_quality_mode;
54
+ }
55
+ if (data.status !== undefined) {
56
+ this.status = data.status;
57
+ }
58
+ if (data.voice_start_time !== undefined) {
59
+ this.voiceStartTime = data.voice_start_time ? data.voice_start_time * 1000 : null;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Create an invite for the channel
65
+ * @arg {Object} [options] Invite generation options
66
+ * @arg {Number} [options.maxAge] How long the invite should last in seconds
67
+ * @arg {Number} [options.maxUses] How many uses the invite should last for
68
+ * @arg {Boolean} [options.temporary] Whether the invite grants temporary membership or not
69
+ * @arg {Boolean} [options.unique] Whether the invite is unique or not
70
+ * @arg {String} [reason] The reason to be displayed in audit logs
71
+ * @returns {Promise<Invite>}
72
+ */
73
+ createInvite(options, reason) {
74
+ return this._client.createChannelInvite.call(this._client, this.id, options, reason);
75
+ }
76
+
77
+ /**
78
+ * Delete a channel permission overwrite
79
+ * @arg {String} overwriteID The ID of the overwritten user or role
80
+ * @arg {String} [reason] The reason to be displayed in audit logs
81
+ * @returns {Promise}
82
+ */
83
+ deletePermission(overwriteID, reason) {
84
+ return this._client.deleteChannelPermission.call(this._client, this.id, overwriteID, reason);
85
+ }
86
+
87
+ /**
88
+ * Create a channel permission overwrite
89
+ * @arg {String} overwriteID The ID of the overwritten user or role
90
+ * @arg {BigInt | Number | String} allow The permissions number for allowed permissions
91
+ * @arg {BigInt | Number | String} deny The permissions number for denied permissions
92
+ * @arg {Number} type The object type of the overwrite, either 1 for "member" or 0 for "role"
93
+ * @arg {String} [reason] The reason to be displayed in audit logs
94
+ * @returns {Promise<PermissionOverwrite>}
95
+ */
96
+ editPermission(overwriteID, allow, deny, type, reason) {
97
+ return this._client.editChannelPermission.call(this._client, this.id, overwriteID, allow, deny, type, reason);
98
+ }
99
+
100
+ /**
101
+ * Get all invites in the channel
102
+ * @returns {Promise<Array<Invite>>}
103
+ */
104
+ getInvites() {
105
+ return this._client.getChannelInvites.call(this._client, this.id);
106
+ }
107
+
108
+ /**
109
+ * Joins the channel
110
+ * @arg {Object} [options] VoiceConnection constructor options
111
+ * @arg {Object} [options.opusOnly] Skip opus encoder initialization. You should not enable this unless you know what you are doing
112
+ * @arg {Boolean} [options.selfDeaf] Whether the bot joins the channel deafened or not
113
+ * @arg {Boolean} [options.selfMute] Whether the bot joins the channel muted or not
114
+ * @arg {Object} [options.shared] Whether the VoiceConnection will be part of a SharedStream or not
115
+ * @returns {Promise<VoiceConnection>} Resolves with a VoiceConnection
116
+ */
117
+ join(options) {
118
+ return this._client.joinVoiceChannel.call(this._client, this.id, options);
119
+ }
120
+
121
+ /**
122
+ * Leaves the channel
123
+ */
124
+ leave() {
125
+ return this._client.leaveVoiceChannel.call(this._client, this.id);
126
+ }
127
+
128
+ /**
129
+ * Send a soundboard sound to the voice channel
130
+ * @arg {Object} options The soundboard sound options
131
+ * @arg {String} options.soundID The ID of the soundboard sound
132
+ * @arg {String} [options.sourceGuildID] The ID of the guild where the soundboard sound was created, if not in the same guild
133
+ * @returns {Promise}
134
+ */
135
+ sendSoundboardSound(options) {
136
+ return this._client.sendSoundboardSound.call(this._client, this.id, options);
137
+ }
138
+
139
+ /**
140
+ * Set the status of the voice channel. Note: This will not work in stage channels
141
+ * @arg {String} status The new voice channel status
142
+ * @arg {String} [reason] The reason to be displayed in audit logs
143
+ * @returns {Promise}
144
+ */
145
+ setStatus(status, reason) {
146
+ return this._client.setVoiceChannelStatus.call(this._client, this.id, status, reason);
147
+ }
148
+
149
+ toJSON(props = []) {
150
+ return super.toJSON([
151
+ "bitrate",
152
+ "nsfw",
153
+ "permissionOverwrites",
154
+ "position",
155
+ "rtcRegion",
156
+ "status",
157
+ "userLimit",
158
+ "videoQualityMode",
159
+ "voiceMembers",
160
+ "voiceStartTime",
161
+ ...props,
162
+ ]);
163
+ }
164
+ }
165
+
166
+ module.exports = VoiceChannel;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+
5
+ /**
6
+ * Represents a member's voice state in a guild
7
+ * @prop {String?} channelID The ID of the member's current voice channel
8
+ * @prop {Boolean} deaf Whether the member is server deafened or not
9
+ * @prop {String} id The ID of the member
10
+ * @prop {Boolean} mute Whether the member is server muted or not
11
+ * @prop {Number?} requestToSpeakTimestamp Timestamp of the member's latest request to speak
12
+ * @prop {Boolean} selfDeaf Whether the member is self deafened or not
13
+ * @prop {Boolean} selfMute Whether the member is self muted or not
14
+ * @prop {Boolean} selfStream Whether the member is streaming using "Go Live"
15
+ * @prop {Boolean} selfVideo Whether the member's camera is enabled
16
+ * @prop {String?} sessionID The ID of the member's current voice session
17
+ * @prop {Boolean} suppress Whether the member is suppressed or not
18
+ */
19
+ class VoiceState extends Base {
20
+ constructor(data) {
21
+ data.id = data.user_id; // Thanks Discord
22
+ super(data.id);
23
+ this.mute = false;
24
+ this.deaf = false;
25
+ this.requestToSpeakTimestamp = null;
26
+ this.selfMute = false;
27
+ this.selfDeaf = false;
28
+ this.selfStream = false;
29
+ this.selfVideo = false;
30
+ this.suppress = false;
31
+ this.update(data);
32
+ }
33
+
34
+ update(data) {
35
+ if (data.channel_id !== undefined) {
36
+ this.channelID = data.channel_id;
37
+ this.sessionID = data.channel_id === null ? null : data.session_id;
38
+ } else if (this.channelID === undefined) {
39
+ this.channelID = this.sessionID = null;
40
+ }
41
+ if (data.mute !== undefined) {
42
+ this.mute = data.mute;
43
+ }
44
+ if (data.deaf !== undefined) {
45
+ this.deaf = data.deaf;
46
+ }
47
+ if (data.request_to_speak_timestamp !== undefined) {
48
+ this.requestToSpeakTimestamp = Date.parse(data.request_to_speak_timestamp);
49
+ }
50
+ if (data.self_mute !== undefined) {
51
+ this.selfMute = data.self_mute;
52
+ }
53
+ if (data.self_deaf !== undefined) {
54
+ this.selfDeaf = data.self_deaf;
55
+ }
56
+ if (data.self_video !== undefined) {
57
+ this.selfVideo = data.self_video;
58
+ }
59
+ if (data.self_stream !== undefined) {
60
+ this.selfStream = data.self_stream;
61
+ }
62
+ if (data.suppress !== undefined) { // Bots ignore this
63
+ this.suppress = data.suppress;
64
+ }
65
+ }
66
+
67
+ toJSON(props = []) {
68
+ return super.toJSON([
69
+ "channelID",
70
+ "deaf",
71
+ "mute",
72
+ "requestToSpeakTimestamp",
73
+ "selfDeaf",
74
+ "selfMute",
75
+ "selfStream",
76
+ "selfVideo",
77
+ "sessionID",
78
+ "suppress",
79
+ ...props,
80
+ ]);
81
+ }
82
+ }
83
+
84
+ module.exports = VoiceState;
@@ -0,0 +1,76 @@
1
+ const util = require("util");
2
+ const Base = require("../structures/Base");
3
+
4
+ let EventEmitter;
5
+ try {
6
+ EventEmitter = require("eventemitter3");
7
+ } catch {
8
+ EventEmitter = require("events").EventEmitter;
9
+ }
10
+
11
+ class BrowserWebSocketError extends Error {
12
+ constructor(message, event) {
13
+ super(message);
14
+ this.event = event;
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Represents a browser's websocket usable by Eris
20
+ * @extends EventEmitter
21
+ * @prop {String} url The URL to connect to
22
+ */
23
+ class BrowserWebSocket extends EventEmitter {
24
+ constructor(url) {
25
+ super();
26
+
27
+ if (typeof window === "undefined") {
28
+ throw new Error("BrowserWebSocket cannot be used outside of a browser environment");
29
+ }
30
+
31
+ this._ws = new window.WebSocket(url);
32
+ this._ws.onopen = () => this.emit("open");
33
+ this._ws.onmessage = this._onMessage.bind(this);
34
+ this._ws.onerror = (event) => this.emit("error", new BrowserWebSocketError("Unknown error", event));
35
+ this._ws.onclose = (event) => this.emit("close", event.code, event.reason);
36
+ }
37
+
38
+ get readyState() {
39
+ return this._ws.readyState;
40
+ }
41
+
42
+ close(code, reason) {
43
+ return this._ws.close(code, reason);
44
+ }
45
+
46
+ removeEventListener(type, listener) {
47
+ return this.removeListener(type, listener);
48
+ }
49
+
50
+ send(data) {
51
+ return this._ws.send(data);
52
+ }
53
+
54
+ terminate() {
55
+ return this._ws.close();
56
+ }
57
+
58
+ async _onMessage(event) {
59
+ if (event.data instanceof window.Blob) {
60
+ this.emit("message", await event.data.arrayBuffer());
61
+ } else {
62
+ this.emit("message", event.data);
63
+ }
64
+ }
65
+
66
+ [util.inspect.custom]() {
67
+ return Base.prototype[util.inspect.custom].call(this);
68
+ }
69
+ }
70
+
71
+ BrowserWebSocket.CONNECTING = 0;
72
+ BrowserWebSocket.OPEN = 1;
73
+ BrowserWebSocket.CLOSING = 2;
74
+ BrowserWebSocket.CLOSED = 3;
75
+
76
+ module.exports = BrowserWebSocket;