@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,190 @@
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const Guild = require("./Guild");
5
+ const GuildChannel = require("./GuildChannel");
6
+ const Invite = require("./Invite");
7
+ const { AuditLogActions } = require("../Constants");
8
+
9
+ /**
10
+ * Represents a guild audit log entry describing a moderation action
11
+ * @prop {Number} actionType The action type of the entry. See Constants.AuditLogActions for more details
12
+ * @prop {Object?} after The properties of the targeted object after the action was taken
13
+ * For example, if a channel was renamed from #general to #potato, this would be `{name: "potato"}``
14
+ * @prop {String?} autoModerationRuleName The name of the automod rule that was triggered, action types 143-145 only
15
+ * @prop {Number?} autoModerationRuleTriggerType The trigger type of the automod rule that was triggered, action types 143-145 only
16
+ * @prop {Object?} before The properties of the targeted object before the action was taken
17
+ * For example, if a channel was renamed from #general to #potato, this would be `{name: "general"}``
18
+ * @prop {(CategoryChannel | TextChannel | VoiceChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel | StageChannel | Object)?} channel The channel targeted in the entry, action types 26 (MEMBER_MOVE), 72/74/75 (MESSAGE_DELETE/PIN/UNPIN) and 83/84/85 (STAGE_INSTANCE_CREATE/UPDATE/DELETE) only. If the channel is not cached, this will be an object with an `id` key. No other property is guaranteed.
19
+ * @prop {Number?} count The number of entities targeted
20
+ * For example, for action type 26 (MEMBER_MOVE), this is the number of members that were moved/disconnected from the voice channel
21
+ * @prop {Number?} deleteMemberDays The number of days of inactivity to prune for, action type 21 (MEMBER_PRUNE) only
22
+ * @prop {Guild | Object} guild The guild containing the entry. If the guild is not cached, this will be an object with an `id` key. No other property is guaranteed.
23
+ * @prop {String} id The ID of the entry
24
+ * @prop {(Member | Object)?} member The member described by the permission overwrite, action types 13-15 (CHANNEL\_OVERWRITE\_CREATE/UPDATE/DELETE) only. If the guild or member is not cached, this could be {id: String}
25
+ * @prop {Number?} membersRemoved The number of members pruned from the server, action type 21 (MEMBER_PRUNE) only
26
+ * @prop {(Message | Object)?} message The message that was (un)pinned, action types 74/75 (MESSAGE_PIN/UNPIN) only. If the channel or message is not cached, this will be an object with an `id` key. No other property is guaranteed.
27
+ * @prop {String?} reason The reason for the action
28
+ * @prop {(Role | Object)?} role The role described by the permission overwrite, action types 13-15 (CHANNEL\_OVERWRITE\_CREATE/UPDATE/DELETE) only. If the guild or role is not cached, this could be {id: String, name: String}
29
+ * @prop {String?} status The new voice channel status, action type 192 (VOICE\_CHANNEL\_STATUS\_UPDATE) only
30
+ * @prop {(CategoryChannel | Guild | Member | Invite | Role | Object | TextChannel | VoiceChannel | NewsChannel)?} target The object of the action target
31
+ * If the item or the item's guild (where relevant, not including invites) is not cached, this property will be null
32
+ * If the action targets a guild, this could be a Guild object
33
+ * If the action targets a guild channel, this could be a CategoryChannel, TextChannel, or VoiceChannel object
34
+ * If the action targets a member, this could be a Member object
35
+ * If the action targets a role, this could be a Role object
36
+ * If the action targets an invite, this is an Invite object
37
+ * If the action targets a webhook, this is null
38
+ * If the action targets a emoji, this could be an emoji object
39
+ * If the action targets a sticker, this could be a sticker object
40
+ * If the action targets a message, this is a User object
41
+ * @prop {String} targetID The ID of the action target
42
+ * @prop {User} user The user that performed the action. If the user is not cached, this will be an object with an `id` key. No other property is guaranteed.
43
+ */
44
+ class GuildAuditLogEntry extends Base {
45
+ constructor(data, client) {
46
+ super(data.id);
47
+ this._client = client;
48
+
49
+ this.actionType = data.action_type;
50
+ this.guild = client.guilds.get(data.guild_id) || { id: data.guild_id };
51
+ this.reason = data.reason || null;
52
+ this.user = client.users.get(data.user_id);
53
+ this.before = null;
54
+ this.after = null;
55
+ if (data.changes) {
56
+ this.before = {};
57
+ this.after = {};
58
+ data.changes.forEach((change) => {
59
+ if (change.old_value != undefined) {
60
+ this.before[change.key] = change.old_value;
61
+ }
62
+ if (change.new_value != undefined) {
63
+ this.after[change.key] = change.new_value;
64
+ }
65
+ });
66
+ }
67
+
68
+ if (data.target_id) {
69
+ this.targetID = data.target_id;
70
+ }
71
+ if (data.options) {
72
+ if (data.options.count) {
73
+ this.count = +data.options.count;
74
+ }
75
+ if (data.options.channel_id) {
76
+ this.channel = client.getChannel(data.options.channel_id) || { id: data.options.channel_id };
77
+ }
78
+ if (data.options.message_id) {
79
+ if (this.channel instanceof GuildChannel) {
80
+ this.message = this.channel.messages.get(data.options.message_id) || { id: data.options.message_id };
81
+ } else {
82
+ this.message = { id: data.options.message_id };
83
+ }
84
+ }
85
+ if (data.options.delete_member_days) {
86
+ this.deleteMemberDays = +data.options.delete_member_days;
87
+ this.membersRemoved = +data.options.members_removed;
88
+ }
89
+ if (data.options.type) {
90
+ if (data.options.type === "1") {
91
+ if (this.guild instanceof Guild) {
92
+ this.member = this.guild.members.get(data.options.id) || { id: data.options.id };
93
+ } else {
94
+ this.member = { id: data.options.id };
95
+ }
96
+ } else if (data.options.type === "0") {
97
+ if (this.guild instanceof Guild) {
98
+ this.role = this.guild.roles.get(data.options.id) || {
99
+ id: data.options.id,
100
+ name: data.options.role_name,
101
+ };
102
+ } else {
103
+ this.role = {
104
+ id: data.options.id,
105
+ name: data.options.role_name,
106
+ };
107
+ }
108
+ }
109
+ }
110
+ if (data.options.status) {
111
+ this.status = data.options.status;
112
+ }
113
+ if (data.options.auto_moderation_rule_name) {
114
+ this.autoModerationRuleName = data.options.auto_moderation_rule_name;
115
+ this.autoModerationRuleTriggerType = +data.options.auto_moderation_rule_trigger_type; // NOTE Discord casts this into a string
116
+ }
117
+ }
118
+ }
119
+
120
+ get target() { // pay more, get less
121
+ const guildAvailable = this.guild instanceof Guild;
122
+ if (this.actionType < 10) { // Guild
123
+ return this.guild;
124
+ } else if (this.actionType < 20 || this.actionType === 192 || this.actionType === 193) { // Channel
125
+ return this._client.getChannel(this.targetID) || null;
126
+ } else if (this.actionType < 30) { // Member
127
+ if (this.actionType === AuditLogActions.MEMBER_MOVE || this.actionType === AuditLogActions.MEMBER_DISCONNECT) { // MEMBER_MOVE / MEMBER_DISCONNECT
128
+ return null;
129
+ }
130
+ if (guildAvailable) {
131
+ return this.guild.members.get(this.targetID) || null;
132
+ } else {
133
+ return null;
134
+ }
135
+ } else if (this.actionType < 40) { // Role
136
+ if (guildAvailable) {
137
+ return this.guild.roles.get(this.targetID) || null;
138
+ } else {
139
+ return null;
140
+ }
141
+ } else if (this.actionType < 50) { // Invite
142
+ const changes = this.actionType === 42 ? this.before : this.after; // Apparently the meaning of life is a deleted invite
143
+ return new Invite({
144
+ code: changes.code,
145
+ channel: changes.channel,
146
+ guild: this.guild,
147
+ uses: changes.uses,
148
+ max_uses: changes.max_uses,
149
+ max_age: changes.max_age,
150
+ temporary: changes.temporary,
151
+ }, this._client);
152
+ } else if (this.actionType < 60) { // Webhook
153
+ return null; // Go get the webhook yourself
154
+ } else if (this.actionType < 70) { // Emoji
155
+ return this.guild && this.guild.emojis.find((emoji) => emoji.id === this.targetID);
156
+ } else if (this.actionType < 80) { // Message
157
+ return this._client.users.get(this.targetID);
158
+ } else if (this.actionType < 83) { // Integrations
159
+ return null;
160
+ } else if (this.actionType < 90) { // Stage Instances
161
+ return this.guild && this.guild.threads.get(this.targetID);
162
+ } else if (this.actionType < 100) { // Sticker
163
+ return this.guild && this.guild.stickers.find((sticker) => sticker.id === this.targetID);
164
+ } else {
165
+ throw new Error("Unrecognized action type: " + this.actionType);
166
+ }
167
+ }
168
+
169
+ toJSON(props = []) {
170
+ return super.toJSON([
171
+ "actionType",
172
+ "after",
173
+ "autoModerationRuleName",
174
+ "autoModerationRuleTriggerType",
175
+ "before",
176
+ "channel",
177
+ "count",
178
+ "deleteMemberDays",
179
+ "member",
180
+ "membersRemoved",
181
+ "reason",
182
+ "role",
183
+ "targetID",
184
+ "user",
185
+ ...props,
186
+ ]);
187
+ }
188
+ }
189
+
190
+ module.exports = GuildAuditLogEntry;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+
3
+ const Channel = require("./Channel");
4
+ const Permission = require("./Permission");
5
+ const { Permissions } = require("../Constants");
6
+
7
+ /**
8
+ * Represents a guild channel. You also probably want to look at CategoryChannel, ForumChannel, NewsChannel, StageChannel, TextChannel, ThreadChannel, and VoiceChannel. See Channel for more properties
9
+ * @extends Channel
10
+ * @prop {Number} flags The channel's flags (see constants). Currently only applies to thread/forum/media channels
11
+ * @prop {Guild} guild The guild that owns the channel
12
+ * @prop {String} name The name of the channel
13
+ * @prop {String?} parentID The ID of the category (or channel for threads) this channel belongs to
14
+ */
15
+ class GuildChannel extends Channel {
16
+ constructor(data, client) {
17
+ super(data, client);
18
+ this.guild = client.guilds.get(data.guild_id) || {
19
+ id: data.guild_id,
20
+ };
21
+
22
+ this.update(data);
23
+ }
24
+
25
+ update(data) {
26
+ if (data.type !== undefined) {
27
+ this.type = data.type;
28
+ }
29
+ if (data.name !== undefined) {
30
+ this.name = data.name;
31
+ }
32
+ if (data.parent_id !== undefined) {
33
+ this.parentID = data.parent_id;
34
+ }
35
+ if (data.flags !== undefined) {
36
+ this.flags = data.flags; // NOTE - Channel flags appear everywhere including in DMs?
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Delete the channel
42
+ * @arg {String} [reason] The reason to be displayed in audit logs
43
+ * @returns {Promise<CategoryChannel | ForumChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel | TextChannel | VoiceChannel>}
44
+ */
45
+ delete(reason) {
46
+ return this._client.deleteChannel.call(this._client, this.id, reason);
47
+ }
48
+
49
+ /**
50
+ * Edit the channel's properties
51
+ * @arg {Object} options The properties to edit
52
+ * @arg {Array<String>} [options.appliedTags] [Th] The tags applied to a forum/media thread
53
+ * @arg {Boolean} [options.archived] [Th] The archive status of the channel
54
+ * @arg {Number} [options.autoArchiveDuration] [Th] The duration in minutes to automatically archive the thread after recent activity, either 60, 1440, 4320 or 10080
55
+ * @arg {Array<Object>} [options.availableTags] [FM] An array of [tags](https://discord.dev/resources/channel#forum-tag-object) that can be applied. This will overwrite all existing tags unless edited by specifying the tag ID
56
+ * @arg {Number?} [options.bitrate] [VS] The bitrate of the channel
57
+ * @arg {Number?} [options.defaultAutoArchiveDuration] [TAFM] The default duration of newly created threads in minutes to automatically archive the thread after inactivity (60, 1440, 4320, 10080)
58
+ * @arg {Number} [options.defaultForumLayout] [F] The default post [layout type](https://discord.dev/resources/channel#channel-object-forum-layout-types)
59
+ * @arg {Object?} [options.defaultReactionEmoji] [FM] The [emoji](https://discord.dev/resources/channel#default-reaction-object) to show in the Add Reaction Button
60
+ * @arg {Number?} [options.defaultSortOrder] [FM] The default post sort type (0 for latest activity, 1 for creation date)
61
+ * @arg {Number} [options.defaultThreadRateLimitPerUser] [TFM] The default rate limit duration for newly created threads
62
+ * @arg {Number} [options.flags] [FM/Th] The channel's flag [bit set](https://discord.dev/resources/channel#channel-object-channel-flags)
63
+ * @arg {Boolean} [options.invitable] [Th] Whether non-moderators can add other non-moderators to the channel
64
+ * @arg {Boolean} [options.locked] [Th] The lock status of the channel
65
+ * @arg {String} [options.name] [All/Th] The name of the channel
66
+ * @arg {Boolean?} [options.nsfw] [TVASFM] The NSFW status of the channel
67
+ * @arg {String?} [options.parentID] [TVASFM] The ID of the parent channel category for this channel
68
+ * @arg {Array<Object>?} [options.permissionOverwrites] [All] An object containing [permission overwrite](https://discord.dev/resources/channel#overwrite-object) objects
69
+ * @arg {Number?} [options.position] [All] The sorting position of the channel
70
+ * @arg {Number?} [options.rateLimitPerUser] [TVSFM/Th] The time in seconds a user has to wait before sending another message (does not affect bots or users with manageMessages/manageChannel permissions)
71
+ * @arg {String?} [options.rtcRegion] [VS] The RTC region ID of the channel (automatic if `null`)
72
+ * @arg {String?} [options.topic] [TAFM] The topic of the channel
73
+ * @arg {Boolean} [options.type] [TA] The type of channel (only between types 0 and 5)
74
+ * @arg {Number?} [options.userLimit] [VS] The channel user limit
75
+ * @arg {Number?} [options.videoQualityMode] [VS] The camera video quality mode of the channel. `1` is auto, `2` is 720p
76
+ * @arg {String} [reason] The reason to be displayed in audit logs
77
+ * @returns {Promise<CategoryChannel | ForumChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel | TextChannel | VoiceChannel>}
78
+ */
79
+ edit(options, reason) {
80
+ return this._client.editChannel.call(this._client, this.id, options, reason);
81
+ }
82
+
83
+ /**
84
+ * Get the channel-specific permissions of a member
85
+ * @arg {String | Member | Object} memberID The ID of the member or a Member object
86
+ * @returns {Permission}
87
+ */
88
+ permissionsOf(memberID) {
89
+ const member = typeof memberID === "string" ? this.guild.members.get(memberID) : memberID;
90
+ let permission = this.guild.permissionsOf(member).allow;
91
+ if (permission & Permissions.administrator) {
92
+ return new Permission(Permissions.all);
93
+ }
94
+ const channel = this instanceof ThreadChannel ? this.guild.channels.get(this.parentID) : this;
95
+ let overwrite = channel && channel.permissionOverwrites.get(this.guild.id);
96
+ if (overwrite) {
97
+ permission = (permission & ~overwrite.deny) | overwrite.allow;
98
+ }
99
+ let deny = 0n;
100
+ let allow = 0n;
101
+ for (const roleID of member.roles) {
102
+ if ((overwrite = channel && channel.permissionOverwrites.get(roleID))) {
103
+ deny |= overwrite.deny;
104
+ allow |= overwrite.allow;
105
+ }
106
+ }
107
+ permission = (permission & ~deny) | allow;
108
+ overwrite = channel && channel.permissionOverwrites.get(member.id);
109
+ if (overwrite) {
110
+ permission = (permission & ~overwrite.deny) | overwrite.allow;
111
+ }
112
+ return new Permission(permission);
113
+ }
114
+
115
+ toJSON(props = []) {
116
+ return super.toJSON([
117
+ "flags",
118
+ "name",
119
+ "parentID",
120
+ "type",
121
+ ...props,
122
+ ]);
123
+ }
124
+ }
125
+
126
+ module.exports = GuildChannel;
127
+
128
+ const ThreadChannel = require("./ThreadChannel");
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+
5
+ /**
6
+ * Represents a guild integration
7
+ * @prop {Object} account Info on the integration account
8
+ * @prop {String} account.id The ID of the integration account
9
+ * @prop {String} account.name The name of the integration account
10
+ * @prop {Object?} application The bot/OAuth2 application for Discord integrations. See [the Discord docs](https://discord.com/developers/docs/resources/guild#integration-application-object)
11
+ * @prop {Number} createdAt Timestamp of the guild integration's creation
12
+ * @prop {Boolean} enabled Whether the integration is enabled or not
13
+ * @prop {Boolean?} enableEmoticons Whether integration emoticons are enabled or not
14
+ * @prop {Number?} expireBehavior behavior of expired subscriptions
15
+ * @prop {Number?} expireGracePeriod grace period for expired subscriptions
16
+ * @prop {String} id The ID of the integration
17
+ * @prop {String} name The name of the integration
18
+ * @prop {Boolean?} revoked Whether or not the application was revoked
19
+ * @prop {String?} roleID The ID of the role connected to the integration
20
+ * @prop {Number?} subscriberCount number of subscribers
21
+ * @prop {Number?} syncedAt Unix timestamp of last integration sync
22
+ * @prop {Boolean?} syncing Whether the integration is syncing or not
23
+ * @prop {String} type The type of the integration
24
+ * @prop {User?} user The user connected to the integration
25
+ */
26
+ class GuildIntegration extends Base {
27
+ constructor(data, guild) {
28
+ super(data.id);
29
+ this.guild = guild;
30
+ this.name = data.name;
31
+ this.type = data.type;
32
+ if (data.role_id !== undefined) {
33
+ this.roleID = data.role_id;
34
+ }
35
+ if (data.user) {
36
+ this.user = guild.shard.client.users.add(data.user, guild.shard.client);
37
+ }
38
+ this.account = data.account; // not worth making a class for
39
+ this.update(data);
40
+ }
41
+
42
+ update(data) {
43
+ this.enabled = data.enabled;
44
+ if (data.syncing !== undefined) {
45
+ this.syncing = data.syncing;
46
+ }
47
+ if (data.expire_behavior !== undefined) {
48
+ this.expireBehavior = data.expire_behavior;
49
+ }
50
+ if (data.expire_behavior !== undefined) {
51
+ this.expireGracePeriod = data.expire_grace_period;
52
+ }
53
+ if (data.enable_emoticons) {
54
+ this.enableEmoticons = data.enable_emoticons;
55
+ }
56
+ if (data.subscriber_count !== undefined) {
57
+ this.subscriberCount = data.subscriber_count;
58
+ }
59
+ if (data.synced_at !== undefined) {
60
+ this.syncedAt = data.synced_at;
61
+ }
62
+ if (data.revoked !== undefined) {
63
+ this.revoked = data.revoked;
64
+ }
65
+ if (data.application !== undefined) {
66
+ this.application = data.application;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Delete the guild integration
72
+ * @returns {Promise}
73
+ */
74
+ delete() {
75
+ return this.guild.shard.client.deleteGuildIntegration.call(this.guild.shard.client, this.guild.id, this.id);
76
+ }
77
+
78
+ toJSON(props = []) {
79
+ return super.toJSON([
80
+ "account",
81
+ "application",
82
+ "enabled",
83
+ "enableEmoticons",
84
+ "expireBehavior",
85
+ "expireGracePeriod",
86
+ "name",
87
+ "revoked",
88
+ "roleID",
89
+ "subscriberCount",
90
+ "syncedAt",
91
+ "syncing",
92
+ "type",
93
+ "user",
94
+ ...props,
95
+ ]);
96
+ }
97
+ }
98
+
99
+ module.exports = GuildIntegration;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const Endpoints = require("../rest/Endpoints.js");
5
+
6
+ /**
7
+ * Represents a GuildPreview structure
8
+ * @extends Base
9
+ * @prop {Number} approximateMemberCount The **approximate** number of members in the guild
10
+ * @prop {Number} approximatePresenceCount The **approximate** number of presences in the guild
11
+ * @prop {String?} description The description for the guild (VIP only)
12
+ * @prop {String?} discoverySplash The hash of the guild discovery splash image, or null if no splash
13
+ * @prop {String?} discoverySplashURL The URL of the guild's discovery splash image
14
+ * @prop {Array<Object>} emojis An array of guild emoji objects
15
+ * @prop {Array<String>} features An array of guild feature strings
16
+ * @prop {String?} icon The hash of the guild icon, or null if no icon
17
+ * @prop {String?} iconURL The URL of the guild's icon
18
+ * @prop {String} id The ID of the guild
19
+ * @prop {String} name The name of the guild
20
+ * @prop {String?} splash The hash of the guild splash image, or null if no splash (VIP only)
21
+ * @prop {String?} splashURL The URL of the guild's splash image
22
+ */
23
+ class GuildPreview extends Base {
24
+ constructor(data, client) {
25
+ super(data.id);
26
+ this._client = client;
27
+
28
+ this.name = data.name;
29
+ this.icon = data.icon;
30
+ this.description = data.description;
31
+ this.splash = data.splash;
32
+ this.discoverySplash = data.discovery_splash;
33
+ this.features = data.features;
34
+ this.approximateMemberCount = data.approximate_member_count;
35
+ this.approximatePresenceCount = data.approximate_presence_count;
36
+ this.emojis = data.emojis;
37
+ }
38
+
39
+ get iconURL() {
40
+ return this.icon ? this._client._formatImage(Endpoints.GUILD_ICON(this.id, this.icon)) : null;
41
+ }
42
+
43
+ get splashURL() {
44
+ return this.splash ? this._client._formatImage(Endpoints.GUILD_SPLASH(this.id, this.splash)) : null;
45
+ }
46
+
47
+ get discoverySplashURL() {
48
+ return this.discoverySplash ? this._client._formatImage(Endpoints.GUILD_DISCOVERY_SPLASH(this.id, this.discoverySplash)) : null;
49
+ }
50
+
51
+ /**
52
+ * Get the guild's splash with the given format and size
53
+ * @arg {String} [format] The filetype of the icon ("jpg", "jpeg", "png", "gif", or "webp")
54
+ * @arg {Number} [size] The size of the icon (any power of two between 16 and 4096)
55
+ * @returns {String?}
56
+ */
57
+ dynamicDiscoverySplashURL(format, size) {
58
+ return this.discoverySplash ? this._client._formatImage(Endpoints.GUILD_DISCOVERY_SPLASH(this.id, this.discoverySplash), format, size) : null;
59
+ }
60
+
61
+ /**
62
+ * Get the guild's icon with the given format and size
63
+ * @arg {String} [format] The filetype of the icon ("jpg", "jpeg", "png", "gif", or "webp")
64
+ * @arg {Number} [size] The size of the icon (any power of two between 16 and 4096)
65
+ * @returns {String?}
66
+ */
67
+ dynamicIconURL(format, size) {
68
+ return this.icon ? this._client._formatImage(Endpoints.GUILD_ICON(this.id, this.icon), format, size) : null;
69
+ }
70
+
71
+ /**
72
+ * Get the guild's splash with the given format and size
73
+ * @arg {String} [format] The filetype of the icon ("jpg", "jpeg", "png", "gif", or "webp")
74
+ * @arg {Number} [size] The size of the icon (any power of two between 16 and 4096)
75
+ * @returns {String?}
76
+ */
77
+ dynamicSplashURL(format, size) {
78
+ return this.splash ? this._client._formatImage(Endpoints.GUILD_SPLASH(this.id, this.splash), format, size) : null;
79
+ }
80
+
81
+ toJSON(props = []) {
82
+ return super.toJSON([
83
+ "approximateMemberCount",
84
+ "approximatePresenceCount",
85
+ "description",
86
+ "discoverySplash",
87
+ "emojis",
88
+ "features",
89
+ "icon",
90
+ "name",
91
+ "splash",
92
+ ...props,
93
+ ]);
94
+ }
95
+ }
96
+
97
+ module.exports = GuildPreview;