@zygout/eris 0.0.0-stage → 0.19.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.
Files changed (88) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +108 -2
  3. package/esm.mjs +72 -0
  4. package/index.d.ts +4407 -0
  5. package/index.js +75 -0
  6. package/lib/Client.js +4708 -0
  7. package/lib/Constants.d.ts +990 -0
  8. package/lib/Constants.js +1163 -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 +81 -4
@@ -0,0 +1,371 @@
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const emitDeprecation = require("../util/emitDeprecation");
5
+ const Endpoints = require("../rest/Endpoints");
6
+ const User = require("./User");
7
+ const VoiceState = require("./VoiceState");
8
+
9
+ /**
10
+ * Represents a server member
11
+ * @prop {Number?} accentColor The user's banner color, or null if no banner color (REST only)
12
+ * @prop {Array<Object>?} activities The member's current activities
13
+ * @prop {String?} animatedNameplateURL The URL of the user's nameplate asset (always a WEBM)
14
+ * @prop {String?} avatar The hash of the member's guild avatar, or null if no guild avatar
15
+ * @prop {Object?} avatarDecorationData The data of the member's avatar decoration (guild-specific if set, otherwise the user's), including the asset and sku ID, or null if no avatar decoration
16
+ * @prop {String?} avatarDecorationURL The URL of the member's avatar decoration
17
+ * @prop {String} avatarURL The URL of the user's avatar which can be either a JPG or GIF
18
+ * @prop {String?} banner The hash of the member's guild banner, or the hash of the user's banner (REST only) if the member has no guild banner
19
+ * @prop {String?} bannerURL The URL of the member's guild banner if they have one, otherwise the URL of the user's banner
20
+ * @prop {Boolean} bot Whether the user is an OAuth bot or not
21
+ * @prop {Object?} clientStatus The member's per-client status
22
+ * @prop {String} clientStatus.desktop The member's status on desktop. Either "online", "idle", "dnd", or "offline". Will be "offline" for bots
23
+ * @prop {String} clientStatus.mobile The member's status on mobile. Either "online", "idle", "dnd", or "offline". Will be "offline" for bots
24
+ * @prop {String} clientStatus.web The member's status on web. Either "online", "idle", "dnd", or "offline". Will be "online" for bots
25
+ * @prop {Object?} collectibles The data for the member's collectibles (guild-specific if set, otherwise the user's), 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
26
+ * @prop {Number?} communicationDisabledUntil Timestamp of timeout expiry. If `null`, the member is not timed out
27
+ * @prop {Number} createdAt Timestamp of user creation
28
+ * @prop {String} defaultAvatar The hash for the default avatar of a user if there is no avatar set
29
+ * @prop {String} defaultAvatarURL The URL of the user's default avatar
30
+ * @prop {String} discriminator The discriminator of the user. If they've migrated to the new username system, this will be "0"
31
+ * @prop {Number} flags The member's flags (see Constants)
32
+ * @prop {Object?} game The active game the member is playing
33
+ * @prop {String} game.name The name of the active game
34
+ * @prop {Number} game.type The type of the active game (0 is default, 1 is Twitch, 2 is YouTube)
35
+ * @prop {String?} game.url The url of the active game
36
+ * @prop {String?} globalName The user's display name, if it is set. For bots, this is the application name
37
+ * @prop {Guild} guild The guild the member is in
38
+ * @prop {String} id The ID of the member
39
+ * @prop {Number?} joinedAt Timestamp of when the member joined the guild (Note: Member objects retrieved from `Client#voiceStateUpdate` events will have `joinedAt` set as `null` if the member was invited as a guest)
40
+ * @prop {String} mention A string that mentions the member
41
+ * @prop {String?} nick The server nickname of the member
42
+ * @prop {Boolean?} pending Whether the member has passed the guild's Membership Screening requirements
43
+ * @prop {Permission} permission [DEPRECATED] The guild-wide permissions of the member. Use Member#permissions instead
44
+ * @prop {Permission} permissions The guild-wide permissions of the member
45
+ * @prop {Number?} premiumSince Timestamp of when the member boosted the guild
46
+ * @prop {Array<String>} roles An array of role IDs this member is a part of
47
+ * @prop {String} staticAvatarURL The URL of the user's avatar (always a JPG)
48
+ * @prop {String?} staticNameplateURL The static URL of the user's nameplate asset (always a PNG)
49
+ * @prop {String} status The member's status. Either "online", "idle", "dnd", or "offline"
50
+ * @prop {User} user The user object of the member
51
+ * @prop {String} username The username of the user
52
+ * @prop {VoiceState} voiceState The voice state of the member
53
+ */
54
+ class Member extends Base {
55
+ constructor(data, guild, client) {
56
+ super(data.id || data.user.id);
57
+ if (!data.id && data.user) {
58
+ data.id = data.user.id;
59
+ }
60
+ if ((this.guild = guild)) {
61
+ this.user = guild._client.users.get(data.id);
62
+ if (!this.user && data.user) {
63
+ this.user = guild._client.users.add(data.user, guild._client);
64
+ }
65
+ if (!this.user) {
66
+ throw new Error("User associated with Member not found: " + data.id);
67
+ }
68
+ } else if (data.user) {
69
+ if (!client) {
70
+ this.user = new User(data.user);
71
+ } else {
72
+ this.user = client.users.update(data.user, client);
73
+ }
74
+ } else {
75
+ this.user = null;
76
+ }
77
+
78
+ this.nick = null;
79
+ this.roles = [];
80
+ this.update(data);
81
+ }
82
+
83
+ update(data) {
84
+ // Handle updates from voice states
85
+ if (data.hasOwnProperty("channel_id") && this.guild) {
86
+ const state = this.guild.voiceStates.get(this.id);
87
+ if (data.channel_id === null && !data.mute && !data.deaf) {
88
+ this.guild.voiceStates.delete(this.id);
89
+ } else if (state) {
90
+ state.update(data);
91
+ } else if (data.channel_id || data.mute || data.deaf || data.suppress) {
92
+ this.guild.voiceStates.update(data);
93
+ }
94
+ if (data.hasOwnProperty("member")) {
95
+ data = data.member;
96
+ }
97
+ }
98
+ if (data.status !== undefined) {
99
+ this.status = data.status;
100
+ }
101
+ if (data.joined_at !== undefined) {
102
+ this.joinedAt = data.joined_at ? Date.parse(data.joined_at) : null;
103
+ }
104
+ if (data.client_status !== undefined) {
105
+ this.clientStatus = Object.assign({ web: "offline", desktop: "offline", mobile: "offline" }, data.client_status);
106
+ }
107
+ if (data.activities !== undefined) {
108
+ this.activities = data.activities;
109
+ }
110
+ if (data.premium_since !== undefined) {
111
+ this.premiumSince = data.premium_since === null ? null : Date.parse(data.premium_since);
112
+ }
113
+ if (data.nick !== undefined) {
114
+ this.nick = data.nick;
115
+ }
116
+ if (data.roles !== undefined) {
117
+ this.roles = data.roles;
118
+ }
119
+ if (data.pending !== undefined) {
120
+ this.pending = data.pending;
121
+ }
122
+ if (data.avatar !== undefined) {
123
+ this.avatar = data.avatar;
124
+ }
125
+ if (data.avatar_decoration_data !== undefined) {
126
+ this._avatarDecorationData = data.avatar_decoration_data;
127
+ }
128
+ if (data.banner !== undefined) {
129
+ this._banner = data.banner;
130
+ }
131
+ if (data.collectibles !== undefined) {
132
+ this._collectibles = data.collectibles;
133
+ }
134
+ if (data.communication_disabled_until !== undefined) {
135
+ if (data.communication_disabled_until !== null) {
136
+ this.communicationDisabledUntil = Date.parse(data.communication_disabled_until);
137
+ } else {
138
+ this.communicationDisabledUntil = data.communication_disabled_until;
139
+ }
140
+ }
141
+ if (data.flags !== undefined) {
142
+ this.flags = data.flags;
143
+ }
144
+ if (data.user !== undefined) {
145
+ this.user.update(data.user);
146
+ }
147
+ }
148
+
149
+ get accentColor() {
150
+ return this.user.accentColor;
151
+ }
152
+
153
+ get animatedNameplateURL() {
154
+ const collectibles = this.collectibles;
155
+ if (!collectibles || !collectibles.nameplate) {
156
+ return null;
157
+ }
158
+ return Endpoints.CDN_URL + Endpoints.USER_NAMEPLATE(collectibles.nameplate.asset, "asset.webm");
159
+ }
160
+
161
+ get avatarDecorationData() {
162
+ return this._avatarDecorationData || this.user.avatarDecorationData;
163
+ }
164
+
165
+ get avatarDecorationURL() {
166
+ if (!this._avatarDecorationData) {
167
+ return this.user.avatarDecorationURL;
168
+ }
169
+ return this.guild._client._formatImage(Endpoints.USER_AVATAR_DECORATION(this._avatarDecorationData.asset), "png");
170
+ }
171
+
172
+ get avatarURL() {
173
+ return this.avatar ? this.guild._client._formatImage(Endpoints.GUILD_AVATAR(this.guild.id, this.id, this.avatar)) : this.user.avatarURL;
174
+ }
175
+
176
+ get banner() {
177
+ return this._banner || this.user.banner;
178
+ }
179
+
180
+ get bannerURL() {
181
+ return this._banner ? this.guild._client._formatImage(Endpoints.GUILD_MEMBER_BANNER(this.guild.id, this.id, this._banner)) : this.user.bannerURL;
182
+ }
183
+
184
+ get bot() {
185
+ return this.user.bot;
186
+ }
187
+
188
+ get collectibles() {
189
+ return this._collectibles || this.user.collectibles;
190
+ }
191
+
192
+ get createdAt() {
193
+ return this.user.createdAt;
194
+ }
195
+
196
+ get defaultAvatar() {
197
+ return this.user.defaultAvatar;
198
+ }
199
+
200
+ get defaultAvatarURL() {
201
+ return this.user.defaultAvatarURL;
202
+ }
203
+
204
+ get discriminator() {
205
+ return this.user.discriminator;
206
+ }
207
+
208
+ get globalName() {
209
+ return this.user.globalName;
210
+ }
211
+
212
+ get mention() {
213
+ return `<@!${this.id}>`;
214
+ }
215
+
216
+ get permission() {
217
+ emitDeprecation("MEMBER_PERMISSION");
218
+ this.guild._client.emit("warn", "[DEPRECATED] Member#permission is deprecated. Use Member#permissions instead");
219
+ return this.permissions;
220
+ }
221
+
222
+ get permissions() {
223
+ return this.guild.permissionsOf(this);
224
+ }
225
+
226
+ get staticAvatarURL() {
227
+ return this.user.staticAvatarURL;
228
+ }
229
+
230
+ get staticNameplateURL() {
231
+ const collectibles = this.collectibles;
232
+ if (!collectibles || !collectibles.nameplate) {
233
+ return null;
234
+ }
235
+ return Endpoints.CDN_URL + Endpoints.USER_NAMEPLATE(collectibles.nameplate.asset, "static.png");
236
+ }
237
+
238
+ get username() {
239
+ return this.user.username;
240
+ }
241
+
242
+ get voiceState() {
243
+ if (this.guild && this.guild.voiceStates.has(this.id)) {
244
+ return this.guild.voiceStates.get(this.id);
245
+ } else {
246
+ return new VoiceState({
247
+ id: this.id,
248
+ });
249
+ }
250
+ }
251
+
252
+ get game() {
253
+ return this.activities && this.activities.length > 0 ? this.activities[0] : null;
254
+ }
255
+
256
+ /**
257
+ * Add a role to the guild member
258
+ * @arg {String} roleID The ID of the role
259
+ * @arg {String} [reason] The reason to be displayed in audit logs
260
+ * @returns {Promise}
261
+ */
262
+ addRole(roleID, reason) {
263
+ return this.guild._client.addGuildMemberRole.call(this.guild._client, this.guild.id, this.id, roleID, reason);
264
+ }
265
+
266
+ /**
267
+ * Ban the user from the guild
268
+ * @arg {Number} [options.deleteMessageDays=0] [DEPRECATED] Number of days to delete messages for, between 0-7 inclusive
269
+ * @arg {Number} [options.deleteMessageSeconds=0] Number of seconds to delete messages for, between 0 and 604,800 inclusive
270
+ * @arg {String} [options.reason] The reason to be displayed in audit logs
271
+ * @arg {String} [reason] [DEPRECATED] The reason to be displayed in audit logs
272
+ * @returns {Promise}
273
+ */
274
+ ban(options, reason) {
275
+ return this.guild._client.banGuildMember.call(this.guild._client, this.guild.id, this.id, options, reason);
276
+ }
277
+
278
+ /**
279
+ * Get the member's avatar with the given format and size
280
+ * @arg {String} [format] The filetype of the avatar ("jpg", "jpeg", "png", "gif", or "webp")
281
+ * @arg {Number} [size] The size of the avatar (any power of two between 16 and 4096)
282
+ * @returns {String}
283
+ */
284
+ dynamicAvatarURL(format, size) {
285
+ if (!this.avatar) {
286
+ return this.user.dynamicAvatarURL(format, size);
287
+ }
288
+ return this.guild._client._formatImage(Endpoints.GUILD_AVATAR(this.guild.id, this.id, this.avatar), format, size);
289
+ }
290
+
291
+ /**
292
+ * Get the member's banner with the given format and size. Falls back to the user's banner if the member has no guild banner
293
+ * @arg {String} [format] The filetype of the banner ("jpg", "jpeg", "png", "gif", or "webp")
294
+ * @arg {Number} [size] The size of the banner (any power of two between 16 and 4096)
295
+ * @returns {String?}
296
+ */
297
+ dynamicBannerURL(format, size) {
298
+ if (!this._banner) {
299
+ return this.user.dynamicBannerURL(format, size);
300
+ }
301
+ return this.guild._client._formatImage(Endpoints.GUILD_MEMBER_BANNER(this.guild.id, this.id, this._banner), format, size);
302
+ }
303
+
304
+ /**
305
+ * Edit the guild member
306
+ * @arg {Object} options The properties to edit
307
+ * @arg {String?} [options.avatar] The new avatar for the bot user for this guild, as a base64 data URI. Only available when editing the current bot user. Note: base64 strings alone are not base64 data URI strings
308
+ * @arg {String?} [options.banner] The new banner for the bot user for this guild, as a base64 data URI. Only available when editing the current bot user. Note: base64 strings alone are not base64 data URI strings
309
+ * @arg {String?} [options.bio] The new bio for the bot user for this guild. Only available when editing the current bot user
310
+ * @arg {String?} [options.channelID] The ID of the voice channel to move the member to (must be in voice). Set to `null` to disconnect the member
311
+ * @arg {Date?} [options.communicationDisabledUntil] When the user's timeout should expire. Set to `null` to instantly remove timeout
312
+ * @arg {Boolean} [options.deaf] Server deafen the user
313
+ * @arg {Number} [options.flags] The user's flags - `OR` the `BYPASSES_VERIFICATION` flag (4) to make the member exempt from verification requirements, `NAND` the flag to make the member not exempt
314
+ * @arg {Boolean} [options.mute] Server mute the user
315
+ * @arg {String} [options.nick] Set the user's server nickname, "" to remove
316
+ * @arg {Array<String>} [options.roles] The array of role IDs the user should have
317
+ * @arg {String} [reason] The reason to be displayed in audit logs
318
+ * @returns {Promise}
319
+ */
320
+ edit(options, reason) {
321
+ return this.guild._client.editGuildMember.call(this.guild._client, this.guild.id, this.id, options, reason);
322
+ }
323
+
324
+ /**
325
+ * Kick the member from the guild
326
+ * @arg {String} [reason] The reason to be displayed in audit logs
327
+ * @returns {Promise}
328
+ */
329
+ kick(reason) {
330
+ return this.guild._client.kickGuildMember.call(this.guild._client, this.guild.id, this.id, reason);
331
+ }
332
+
333
+ /**
334
+ * Remove a role from the guild member
335
+ * @arg {String} roleID The ID of the role
336
+ * @arg {String} [reason] The reason to be displayed in audit logs
337
+ * @returns {Promise}
338
+ */
339
+ removeRole(roleID, reason) {
340
+ return this.guild._client.removeGuildMemberRole.call(this.guild._client, this.guild.id, this.id, roleID, reason);
341
+ }
342
+
343
+ /**
344
+ * Unban the user from the guild
345
+ * @arg {String} [reason] The reason to be displayed in audit logs
346
+ * @returns {Promise}
347
+ */
348
+ unban(reason) {
349
+ return this.guild._client.unbanGuildMember.call(this.guild._client, this.guild.id, this.id, reason);
350
+ }
351
+
352
+ toJSON(props = []) {
353
+ return super.toJSON([
354
+ "activities",
355
+ "avatar",
356
+ "banner",
357
+ "communicationDisabledUntil",
358
+ "joinedAt",
359
+ "nick",
360
+ "pending",
361
+ "premiumSince",
362
+ "roles",
363
+ "status",
364
+ "user",
365
+ "voiceState",
366
+ ...props,
367
+ ]);
368
+ }
369
+ }
370
+
371
+ module.exports = Member;