@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,133 +1,133 @@
1
- "use strict";
2
-
3
- const Base = require("./Base");
4
- const Entitlement = require("./Entitlement");
5
- const Permission = require("./Permission");
6
- const { ApplicationIntegrationTypes, InteractionTypes } = require("../Constants");
7
-
8
- /**
9
- * Represents an interaction. You also probably want to look at PingInteraction, CommandInteraction, ComponentInteraction, AutocompleteInteraction, ModalSubmitInteraction, and UnknownInteraction.
10
- * @prop {Boolean} acknowledged Whether or not the interaction has been acknowledged
11
- * @prop {Permission?} appPermissions The permissions the app has within the channel the interaction was sent from
12
- * @prop {String} applicationID The ID of the interaction's application
13
- * @prop {Number?} attachmentSizeLimit The maximum size of attachments (in bytes) the app can send in response to the interaction
14
- * @prop {Object} authorizingIntegrationOwners The IDs of the installation contexts that authorized the app for this interaction
15
- * @prop {String?} authorizingIntegrationOwners.guildInstall The ID of the guild the app is installed in (`"0"` if the interaction was triggered from the app's bot DM), if the app is installed in a guild
16
- * @prop {String?} authorizingIntegrationOwners.userInstall The ID of the user who installed the app, if the app is installed by a user
17
- * @prop {Number?} context The context the interaction was triggered from. `0` is a guild, `1` is the app's bot DM, `2` is a group DM or a DM other than the app's bot DM. See `Constants.InteractionContextTypes`
18
- * @prop {Number} createdAt Timestamp of the interaction's creation
19
- * @prop {Array<Entitlement>} entitlements The entitlements of the user and/or guild that triggered the interaction, for monetized apps
20
- * @prop {String?} guildLocale The guild's preferred locale, if the interaction was triggered from a guild
21
- * @prop {String} id The ID of the interaction
22
- * @prop {String?} locale The selected language of the user who triggered the interaction (not available on ping interactions)
23
- * @prop {String} token The interaction token (Interaction tokens are valid for 15 minutes after initial response and can be used to send followup messages but you must send an initial response within 3 seconds of receiving the event. If the 3 second deadline is exceeded, the token will be invalidated.)
24
- * @prop {Number} type 1 is a Ping, 2 is an Application Command, 3 is a Message Component, 4 is an Application Command Autocomplete, 5 is a Modal Submit
25
- * @prop {Number} version The interaction version
26
- */
27
- class Interaction extends Base {
28
- constructor(data, client) {
29
- super(data.id);
30
- this._client = client;
31
-
32
- this.applicationID = data.application_id;
33
- this.token = data.token;
34
- this.type = data.type;
35
- this.version = data.version;
36
- this.acknowledged = false;
37
-
38
- if (data.app_permissions !== undefined) {
39
- this.appPermissions = new Permission(data.app_permissions);
40
- }
41
- if (data.attachment_size_limit !== undefined) {
42
- this.attachmentSizeLimit = data.attachment_size_limit;
43
- }
44
- const owners = data.authorizing_integration_owners || {};
45
- this.authorizingIntegrationOwners = {
46
- guildInstall: owners[ApplicationIntegrationTypes.GUILD_INSTALL],
47
- userInstall: owners[ApplicationIntegrationTypes.USER_INSTALL],
48
- };
49
- this.context = data.context !== undefined ? data.context : null;
50
- this.entitlements = data.entitlements ? data.entitlements.map((entitlement) => new Entitlement(entitlement, client)) : [];
51
- if (data.guild_locale !== undefined) {
52
- this.guildLocale = data.guild_locale;
53
- }
54
- if (data.locale !== undefined) {
55
- this.locale = data.locale;
56
- }
57
- }
58
-
59
- update() {
60
- this.acknowledged = true;
61
- }
62
-
63
- /**
64
- * Get the guild the interaction was triggered from. If the guild is not cached (e.g. user-installed apps), a partial guild is created from the interaction data
65
- * @arg {Object} data The raw interaction data
66
- * @returns {Guild}
67
- * @private
68
- */
69
- _resolveGuild(data) {
70
- if (this.channel && this.channel.guild instanceof Guild) {
71
- return this.channel.guild;
72
- }
73
- const guild = this._client.guilds.get(data.guild_id);
74
- if (guild) {
75
- return guild;
76
- }
77
- if (!this._partialGuild) {
78
- this._partialGuild = new Guild(Object.assign({}, data.guild, {
79
- id: data.guild_id,
80
- }), this._client);
81
- }
82
- return this._partialGuild;
83
- }
84
-
85
- /**
86
- * Create or update a member from raw interaction member data
87
- * @arg {Object} member The raw member data
88
- * @arg {Object} data The raw interaction data
89
- * @returns {Member}
90
- * @private
91
- */
92
- _resolveMember(member, data) {
93
- if (member.user) {
94
- member.id = member.user.id;
95
- }
96
- const guild = this._resolveGuild(data);
97
- return guild.members.update(member, guild);
98
- }
99
-
100
- static from(data, client) {
101
- switch (data.type) {
102
- case InteractionTypes.PING: {
103
- return new PingInteraction(data, client);
104
- }
105
- case InteractionTypes.APPLICATION_COMMAND: {
106
- return new CommandInteraction(data, client);
107
- }
108
- case InteractionTypes.MESSAGE_COMPONENT: {
109
- return new ComponentInteraction(data, client);
110
- }
111
- case InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE: {
112
- return new AutocompleteInteraction(data, client);
113
- }
114
- case InteractionTypes.MODAL_SUBMIT: {
115
- return new ModalSubmitInteraction(data, client);
116
- }
117
- }
118
-
119
- client.emit("warn", new Error(`Unknown interaction type: ${data.type}\n${JSON.stringify(data)}`));
120
- return new UnknownInteraction(data, client);
121
- }
122
- }
123
-
124
- module.exports = Interaction;
125
-
126
- // Circular import
127
- const Guild = require("./Guild");
128
- const PingInteraction = require("./PingInteraction");
129
- const CommandInteraction = require("./CommandInteraction");
130
- const ComponentInteraction = require("./ComponentInteraction");
131
- const AutocompleteInteraction = require("./AutocompleteInteraction");
132
- const ModalSubmitInteraction = require("./ModalSubmitInteraction.js");
133
- const UnknownInteraction = require("./UnknownInteraction");
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const Entitlement = require("./Entitlement");
5
+ const Permission = require("./Permission");
6
+ const { ApplicationIntegrationTypes, InteractionTypes } = require("../Constants");
7
+
8
+ /**
9
+ * Represents an interaction. You also probably want to look at PingInteraction, CommandInteraction, ComponentInteraction, AutocompleteInteraction, ModalSubmitInteraction, and UnknownInteraction.
10
+ * @prop {Boolean} acknowledged Whether or not the interaction has been acknowledged
11
+ * @prop {Permission?} appPermissions The permissions the app has within the channel the interaction was sent from
12
+ * @prop {String} applicationID The ID of the interaction's application
13
+ * @prop {Number?} attachmentSizeLimit The maximum size of attachments (in bytes) the app can send in response to the interaction
14
+ * @prop {Object} authorizingIntegrationOwners The IDs of the installation contexts that authorized the app for this interaction
15
+ * @prop {String?} authorizingIntegrationOwners.guildInstall The ID of the guild the app is installed in (`"0"` if the interaction was triggered from the app's bot DM), if the app is installed in a guild
16
+ * @prop {String?} authorizingIntegrationOwners.userInstall The ID of the user who installed the app, if the app is installed by a user
17
+ * @prop {Number?} context The context the interaction was triggered from. `0` is a guild, `1` is the app's bot DM, `2` is a group DM or a DM other than the app's bot DM. See `Constants.InteractionContextTypes`
18
+ * @prop {Number} createdAt Timestamp of the interaction's creation
19
+ * @prop {Array<Entitlement>} entitlements The entitlements of the user and/or guild that triggered the interaction, for monetized apps
20
+ * @prop {String?} guildLocale The guild's preferred locale, if the interaction was triggered from a guild
21
+ * @prop {String} id The ID of the interaction
22
+ * @prop {String?} locale The selected language of the user who triggered the interaction (not available on ping interactions)
23
+ * @prop {String} token The interaction token (Interaction tokens are valid for 15 minutes after initial response and can be used to send followup messages but you must send an initial response within 3 seconds of receiving the event. If the 3 second deadline is exceeded, the token will be invalidated.)
24
+ * @prop {Number} type 1 is a Ping, 2 is an Application Command, 3 is a Message Component, 4 is an Application Command Autocomplete, 5 is a Modal Submit
25
+ * @prop {Number} version The interaction version
26
+ */
27
+ class Interaction extends Base {
28
+ constructor(data, client) {
29
+ super(data.id);
30
+ this._client = client;
31
+
32
+ this.applicationID = data.application_id;
33
+ this.token = data.token;
34
+ this.type = data.type;
35
+ this.version = data.version;
36
+ this.acknowledged = false;
37
+
38
+ if (data.app_permissions !== undefined) {
39
+ this.appPermissions = new Permission(data.app_permissions);
40
+ }
41
+ if (data.attachment_size_limit !== undefined) {
42
+ this.attachmentSizeLimit = data.attachment_size_limit;
43
+ }
44
+ const owners = data.authorizing_integration_owners || {};
45
+ this.authorizingIntegrationOwners = {
46
+ guildInstall: owners[ApplicationIntegrationTypes.GUILD_INSTALL],
47
+ userInstall: owners[ApplicationIntegrationTypes.USER_INSTALL],
48
+ };
49
+ this.context = data.context !== undefined ? data.context : null;
50
+ this.entitlements = data.entitlements ? data.entitlements.map((entitlement) => new Entitlement(entitlement, client)) : [];
51
+ if (data.guild_locale !== undefined) {
52
+ this.guildLocale = data.guild_locale;
53
+ }
54
+ if (data.locale !== undefined) {
55
+ this.locale = data.locale;
56
+ }
57
+ }
58
+
59
+ update() {
60
+ this.acknowledged = true;
61
+ }
62
+
63
+ /**
64
+ * Get the guild the interaction was triggered from. If the guild is not cached (e.g. user-installed apps), a partial guild is created from the interaction data
65
+ * @arg {Object} data The raw interaction data
66
+ * @returns {Guild}
67
+ * @private
68
+ */
69
+ _resolveGuild(data) {
70
+ if (this.channel && this.channel.guild instanceof Guild) {
71
+ return this.channel.guild;
72
+ }
73
+ const guild = this._client.guilds.get(data.guild_id);
74
+ if (guild) {
75
+ return guild;
76
+ }
77
+ if (!this._partialGuild) {
78
+ this._partialGuild = new Guild(Object.assign({}, data.guild, {
79
+ id: data.guild_id,
80
+ }), this._client);
81
+ }
82
+ return this._partialGuild;
83
+ }
84
+
85
+ /**
86
+ * Create or update a member from raw interaction member data
87
+ * @arg {Object} member The raw member data
88
+ * @arg {Object} data The raw interaction data
89
+ * @returns {Member}
90
+ * @private
91
+ */
92
+ _resolveMember(member, data) {
93
+ if (member.user) {
94
+ member.id = member.user.id;
95
+ }
96
+ const guild = this._resolveGuild(data);
97
+ return guild.members.update(member, guild);
98
+ }
99
+
100
+ static from(data, client) {
101
+ switch (data.type) {
102
+ case InteractionTypes.PING: {
103
+ return new PingInteraction(data, client);
104
+ }
105
+ case InteractionTypes.APPLICATION_COMMAND: {
106
+ return new CommandInteraction(data, client);
107
+ }
108
+ case InteractionTypes.MESSAGE_COMPONENT: {
109
+ return new ComponentInteraction(data, client);
110
+ }
111
+ case InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE: {
112
+ return new AutocompleteInteraction(data, client);
113
+ }
114
+ case InteractionTypes.MODAL_SUBMIT: {
115
+ return new ModalSubmitInteraction(data, client);
116
+ }
117
+ }
118
+
119
+ client.emit("warn", new Error(`Unknown interaction type: ${data.type}\n${JSON.stringify(data)}`));
120
+ return new UnknownInteraction(data, client);
121
+ }
122
+ }
123
+
124
+ module.exports = Interaction;
125
+
126
+ // Circular import
127
+ const Guild = require("./Guild");
128
+ const PingInteraction = require("./PingInteraction");
129
+ const CommandInteraction = require("./CommandInteraction");
130
+ const ComponentInteraction = require("./ComponentInteraction");
131
+ const AutocompleteInteraction = require("./AutocompleteInteraction");
132
+ const ModalSubmitInteraction = require("./ModalSubmitInteraction.js");
133
+ const UnknownInteraction = require("./UnknownInteraction");
@@ -1,143 +1,143 @@
1
- "use strict";
2
-
3
- const Base = require("./Base");
4
- const Guild = require("./Guild");
5
- const GuildScheduledEvent = require("./GuildScheduledEvent");
6
- const Member = require("./Member");
7
- const Role = require("./Role");
8
-
9
- /**
10
- * Represents an invite. Some properties are only available when fetching invites from channels, which requires the Manage Channel permission.
11
- * @prop {(TextChannel | NewsChannel | VoiceChannel | GroupChannel | StageChannel | Object)?} channel Info on the invite channel
12
- * @prop {String?} channel.icon The icon of a channel (group dm)
13
- * @prop {String} channel.id The ID of the invite's channel
14
- * @prop {String?} channel.name The name of the invite's channel
15
- * @prop {Number} channel.type The type of the invite's channel
16
- * @prop {String} code The invite code
17
- * @prop {Number?} createdAt Timestamp of invite creation
18
- * @prop {Number?} expiresAt Timestamp of invite expiration
19
- * @prop {Number?} flags The invite flags. For now, if there are any invite flags, they will only be `1` (meaning this invite is a guest invite for a voice channel)
20
- * @prop {(Guild | Object)?} guild Info on the invite guild. If the guild is not cached, this will be an object with an `id` key. No other property is guaranteed.
21
- * @prop {GuildScheduledEvent?} guildScheduledEvent The guild scheduled event the invite points to, if the invite was fetched with a `guildScheduledEventID`
22
- * @prop {User?} inviter The invite creator
23
- * @prop {Number?} maxAge How long the invite lasts in seconds
24
- * @prop {Number?} maxUses The max number of invite uses
25
- * @prop {Number?} memberCount The **approximate** member count for the guild
26
- * @prop {Number?} presenceCount The **approximate** presence count for the guild
27
- * @prop {Array<Role>?} roles The roles assigned to the user upon accepting the invite. Roles of uncached guilds are partial (`id`, `name`, `position`, `color`, `colors`, `icon` and `unicodeEmoji` only)
28
- * @prop {Object?} stageInstance [DEPRECATED] The active public stage instance data for the stage channel this invite is for
29
- * @prop {String?} targetApplicationID The target application id
30
- * @prop {Number?} targetType The type of the target application
31
- * @prop {User?} targetUser The user whose stream is displayed for the invite (voice channel only)
32
- * @prop {Boolean?} temporary Whether the invite grants temporary membership or not
33
- * @prop {Number} type The type of invite. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/invite#invite-object-invite-types) for valid types
34
- * @prop {Number?} uses The number of invite uses
35
- */
36
- class Invite extends Base {
37
- constructor(data, client) {
38
- super();
39
- this._client = client;
40
- this.code = data.code;
41
- if (data.guild && client.guilds.has(data.guild.id)) {
42
- this.channel = client.guilds.get(data.guild.id).channels.update(data.channel, client);
43
- } else {
44
- this.channel = data.channel;
45
- }
46
- if (data.guild) {
47
- if (client.guilds.has(data.guild.id)) {
48
- this.guild = client.guilds.update(data.guild, client);
49
- } else if (Object.keys(data.guild).length !== 1) {
50
- this.guild = new Guild(data.guild, client);
51
- } else {
52
- this.guild = { id: data.guild.id };
53
- }
54
- }
55
- if (data.inviter) {
56
- this.inviter = client.users.add(data.inviter, client);
57
- }
58
- this.uses = data.uses !== undefined ? data.uses : null;
59
- this.maxUses = data.max_uses !== undefined ? data.max_uses : null;
60
- this.maxAge = data.max_age !== undefined ? data.max_age : null;
61
- this.temporary = data.temporary !== undefined ? data.temporary : null;
62
- this._createdAt = data.created_at !== undefined ? data.created_at : null;
63
- this._expiresAt = data.expires_at !== undefined ? data.expires_at : null;
64
- this.presenceCount = data.approximate_presence_count !== undefined ? data.approximate_presence_count : null;
65
- this.memberCount = data.approximate_member_count !== undefined ? data.approximate_member_count : null;
66
- if (data.stage_instance !== undefined) {
67
- data.stage_instance.members = data.stage_instance.members.map((m) => {
68
- m.id = m.user.id;
69
- return m;
70
- });
71
- this.stageInstance = {
72
- members: data.stage_instance.members.map((m) => this.guild instanceof Guild ? this.guild.members.update(m, this.guild) : new Member(m, undefined, this._client)),
73
- participantCount: data.stage_instance.participant_count,
74
- speakerCount: data.stage_instance.speaker_count,
75
- topic: data.stage_instance.topic,
76
- };
77
- } else {
78
- this.stageInstance = null;
79
- }
80
- if (data.flags !== undefined) {
81
- this.flags = data.flags;
82
- }
83
- if (data.guild_scheduled_event !== undefined) {
84
- this.guildScheduledEvent = new GuildScheduledEvent(data.guild_scheduled_event, client);
85
- }
86
- if (data.roles !== undefined) {
87
- this.roles = data.roles.map((role) => (this.guild instanceof Guild && this.guild.roles.get(role.id)) || new Role(role, this.guild));
88
- }
89
- if (data.type !== undefined) {
90
- this.type = data.type;
91
- }
92
- this.targetApplicationID = data.target_application !== undefined ? data.target_application.id : null;
93
- this.targetType = data.target_type !== undefined ? data.target_type : null;
94
- this.targetUser = data.target_user !== undefined ? this._client.users.update(data.target_user, this._client) : null;
95
- }
96
-
97
- get createdAt() {
98
- return Date.parse(this._createdAt) || null;
99
- }
100
-
101
- get expiresAt() {
102
- return Date.parse(this._expiresAt) || null;
103
- }
104
-
105
- /**
106
- * Delete the invite
107
- * @arg {String} [reason] The reason to be displayed in audit logs
108
- * @returns {Promise}
109
- */
110
- delete(reason) {
111
- return this._client.deleteInvite.call(this._client, this.code, reason);
112
- }
113
-
114
- toString() {
115
- return `[Invite ${this.code}]`;
116
- }
117
-
118
- toJSON(props = []) {
119
- return super.toJSON([
120
- "channel",
121
- "code",
122
- "createdAt",
123
- "flags",
124
- "guild",
125
- "guildScheduledEvent",
126
- "maxAge",
127
- "maxUses",
128
- "memberCount",
129
- "presenceCount",
130
- "revoked",
131
- "roles",
132
- "targetApplicationID",
133
- "targetType",
134
- "targetUser",
135
- "temporary",
136
- "type",
137
- "uses",
138
- ...props,
139
- ]);
140
- }
141
- }
142
-
143
- module.exports = Invite;
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const Guild = require("./Guild");
5
+ const GuildScheduledEvent = require("./GuildScheduledEvent");
6
+ const Member = require("./Member");
7
+ const Role = require("./Role");
8
+
9
+ /**
10
+ * Represents an invite. Some properties are only available when fetching invites from channels, which requires the Manage Channel permission.
11
+ * @prop {(TextChannel | NewsChannel | VoiceChannel | GroupChannel | StageChannel | Object)?} channel Info on the invite channel
12
+ * @prop {String?} channel.icon The icon of a channel (group dm)
13
+ * @prop {String} channel.id The ID of the invite's channel
14
+ * @prop {String?} channel.name The name of the invite's channel
15
+ * @prop {Number} channel.type The type of the invite's channel
16
+ * @prop {String} code The invite code
17
+ * @prop {Number?} createdAt Timestamp of invite creation
18
+ * @prop {Number?} expiresAt Timestamp of invite expiration
19
+ * @prop {Number?} flags The invite flags. For now, if there are any invite flags, they will only be `1` (meaning this invite is a guest invite for a voice channel)
20
+ * @prop {(Guild | Object)?} guild Info on the invite guild. If the guild is not cached, this will be an object with an `id` key. No other property is guaranteed.
21
+ * @prop {GuildScheduledEvent?} guildScheduledEvent The guild scheduled event the invite points to, if the invite was fetched with a `guildScheduledEventID`
22
+ * @prop {User?} inviter The invite creator
23
+ * @prop {Number?} maxAge How long the invite lasts in seconds
24
+ * @prop {Number?} maxUses The max number of invite uses
25
+ * @prop {Number?} memberCount The **approximate** member count for the guild
26
+ * @prop {Number?} presenceCount The **approximate** presence count for the guild
27
+ * @prop {Array<Role>?} roles The roles assigned to the user upon accepting the invite. Roles of uncached guilds are partial (`id`, `name`, `position`, `color`, `colors`, `icon` and `unicodeEmoji` only)
28
+ * @prop {Object?} stageInstance [DEPRECATED] The active public stage instance data for the stage channel this invite is for
29
+ * @prop {String?} targetApplicationID The target application id
30
+ * @prop {Number?} targetType The type of the target application
31
+ * @prop {User?} targetUser The user whose stream is displayed for the invite (voice channel only)
32
+ * @prop {Boolean?} temporary Whether the invite grants temporary membership or not
33
+ * @prop {Number} type The type of invite. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/invite#invite-object-invite-types) for valid types
34
+ * @prop {Number?} uses The number of invite uses
35
+ */
36
+ class Invite extends Base {
37
+ constructor(data, client) {
38
+ super();
39
+ this._client = client;
40
+ this.code = data.code;
41
+ if (data.guild && client.guilds.has(data.guild.id)) {
42
+ this.channel = client.guilds.get(data.guild.id).channels.update(data.channel, client);
43
+ } else {
44
+ this.channel = data.channel;
45
+ }
46
+ if (data.guild) {
47
+ if (client.guilds.has(data.guild.id)) {
48
+ this.guild = client.guilds.update(data.guild, client);
49
+ } else if (Object.keys(data.guild).length !== 1) {
50
+ this.guild = new Guild(data.guild, client);
51
+ } else {
52
+ this.guild = { id: data.guild.id };
53
+ }
54
+ }
55
+ if (data.inviter) {
56
+ this.inviter = client.users.add(data.inviter, client);
57
+ }
58
+ this.uses = data.uses !== undefined ? data.uses : null;
59
+ this.maxUses = data.max_uses !== undefined ? data.max_uses : null;
60
+ this.maxAge = data.max_age !== undefined ? data.max_age : null;
61
+ this.temporary = data.temporary !== undefined ? data.temporary : null;
62
+ this._createdAt = data.created_at !== undefined ? data.created_at : null;
63
+ this._expiresAt = data.expires_at !== undefined ? data.expires_at : null;
64
+ this.presenceCount = data.approximate_presence_count !== undefined ? data.approximate_presence_count : null;
65
+ this.memberCount = data.approximate_member_count !== undefined ? data.approximate_member_count : null;
66
+ if (data.stage_instance !== undefined) {
67
+ data.stage_instance.members = data.stage_instance.members.map((m) => {
68
+ m.id = m.user.id;
69
+ return m;
70
+ });
71
+ this.stageInstance = {
72
+ members: data.stage_instance.members.map((m) => this.guild instanceof Guild ? this.guild.members.update(m, this.guild) : new Member(m, undefined, this._client)),
73
+ participantCount: data.stage_instance.participant_count,
74
+ speakerCount: data.stage_instance.speaker_count,
75
+ topic: data.stage_instance.topic,
76
+ };
77
+ } else {
78
+ this.stageInstance = null;
79
+ }
80
+ if (data.flags !== undefined) {
81
+ this.flags = data.flags;
82
+ }
83
+ if (data.guild_scheduled_event !== undefined) {
84
+ this.guildScheduledEvent = new GuildScheduledEvent(data.guild_scheduled_event, client);
85
+ }
86
+ if (data.roles !== undefined) {
87
+ this.roles = data.roles.map((role) => (this.guild instanceof Guild && this.guild.roles.get(role.id)) || new Role(role, this.guild));
88
+ }
89
+ if (data.type !== undefined) {
90
+ this.type = data.type;
91
+ }
92
+ this.targetApplicationID = data.target_application !== undefined ? data.target_application.id : null;
93
+ this.targetType = data.target_type !== undefined ? data.target_type : null;
94
+ this.targetUser = data.target_user !== undefined ? this._client.users.update(data.target_user, this._client) : null;
95
+ }
96
+
97
+ get createdAt() {
98
+ return Date.parse(this._createdAt) || null;
99
+ }
100
+
101
+ get expiresAt() {
102
+ return Date.parse(this._expiresAt) || null;
103
+ }
104
+
105
+ /**
106
+ * Delete the invite
107
+ * @arg {String} [reason] The reason to be displayed in audit logs
108
+ * @returns {Promise}
109
+ */
110
+ delete(reason) {
111
+ return this._client.deleteInvite.call(this._client, this.code, reason);
112
+ }
113
+
114
+ toString() {
115
+ return `[Invite ${this.code}]`;
116
+ }
117
+
118
+ toJSON(props = []) {
119
+ return super.toJSON([
120
+ "channel",
121
+ "code",
122
+ "createdAt",
123
+ "flags",
124
+ "guild",
125
+ "guildScheduledEvent",
126
+ "maxAge",
127
+ "maxUses",
128
+ "memberCount",
129
+ "presenceCount",
130
+ "revoked",
131
+ "roles",
132
+ "targetApplicationID",
133
+ "targetType",
134
+ "targetUser",
135
+ "temporary",
136
+ "type",
137
+ "uses",
138
+ ...props,
139
+ ]);
140
+ }
141
+ }
142
+
143
+ module.exports = Invite;