@zygout/eris 0.19.0 → 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 -20
  2. package/README.md +109 -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,176 +1,176 @@
1
- "use strict";
2
-
3
- const Base = require("./Base");
4
- const Endpoints = require("../rest/Endpoints");
5
-
6
- /**
7
- * Represents a guild scheduled event
8
- * @prop {(VoiceChannel | StageChannel | Object)?} channel The channel where the event will be held. This will be null if the event is external (`entityType` is `3`). Can be partial with only `id` if the channel or guild is not cached
9
- * @prop {User?} creator The user that created the scheduled event. For events created before October 25 2021, this will be null. Please see the relevant Discord documentation for more details
10
- * @prop {String?} description The description of the event
11
- * @prop {String?} entityID The entity ID associated to the event
12
- * @prop {Object?} entityMetadata Metadata for the event. This will be null if the event is not external (`entityType` is not `3`)
13
- * @prop {String?} entityMetadata.location Location of the event
14
- * @prop {Number} entityType The [entity type](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types) of the scheduled event
15
- * @prop {Guild | Object} guild The guild which the event belongs to. Can be partial with only `id` if not cached
16
- * @prop {String} id The ID of the guild event
17
- * @prop {String?} image The hash of the event's image, or null if no image
18
- * @prop {String?} imageURL The URL of the event's image, or null if no image
19
- * @prop {String} name The name of the event
20
- * @prop {Number} privacyLevel Event privacy level
21
- * @prop {Object?} recurrenceRule The [definitions](https://discord.dev/resources/guild-scheduled-event#guild-scheduled-event-recurrence-rule-object) for how often this event should recur. Note: properties have been camelCased, and ISO8601 timestamps are represented by epoch number.
22
- * @prop {Number} scheduledStartTime The time the event will start
23
- * @prop {Number?} scheduledEndTime The time the event will end, or null if the event does not have a scheduled time to end
24
- * @prop {Number} status The [status](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status) of the scheduled event
25
- * @prop {Number?} userCount The number of users subscribed to the event
26
- */
27
- class GuildScheduledEvent extends Base {
28
- constructor(data, client) {
29
- super(data.id);
30
-
31
- this._client = client;
32
- if (data.creator !== undefined) {
33
- this.creator = client.users.update(data.creator, this.client);
34
- } else {
35
- this.creator = null;
36
- }
37
- this.guild = client.guilds.get(data.guild_id) || {
38
- id: data.guild_id,
39
- };
40
- this.scheduledEndTime = null;
41
- this.update(data);
42
- }
43
-
44
- update(data) {
45
- if (data.channel_id !== undefined) {
46
- if (data.channel_id !== null) {
47
- if (this._client.guilds.get(data.guild_id)) {
48
- this.channel = this._client.guilds.get(data.guild_id).channels.get(data.channel_id) || { id: data.channel_id };
49
- } else {
50
- this.channel = { id: data.channel_id };
51
- }
52
- } else {
53
- this.channel = null;
54
- }
55
- }
56
- if (data.name !== undefined) {
57
- this.name = data.name;
58
- }
59
- if (data.description !== undefined) {
60
- this.description = data.description;
61
- }
62
- if (data.scheduled_start_time !== undefined) {
63
- this.scheduledStartTime = Date.parse(data.scheduled_start_time);
64
- }
65
- if (data.scheduled_end_time !== undefined) {
66
- this.scheduledEndTime = Date.parse(data.scheduled_end_time);
67
- }
68
- if (data.privacy_level !== undefined) {
69
- this.privacyLevel = data.privacy_level;
70
- }
71
- if (data.status !== undefined) {
72
- this.status = data.status;
73
- }
74
- if (data.entity_type !== undefined) {
75
- this.entityType = data.entity_type;
76
- }
77
- if (data.entity_id !== undefined) {
78
- this.entityID = data.entity_id;
79
- }
80
- if (data.entity_metadata !== undefined) {
81
- this.entityMetadata = data.entity_metadata;
82
- }
83
- if (data.user_count !== undefined) {
84
- this.userCount = data.user_count;
85
- }
86
- if (data.image !== undefined) {
87
- this.image = data.image;
88
- }
89
- if (data.recurrence_rule !== undefined) {
90
- if (data.recurrence_rule === null) {
91
- this.recurrenceRule = null;
92
- } else {
93
- this.recurrenceRule = {
94
- byMonth: data.recurrence_rule.by_month,
95
- byMonthDay: data.recurrence_rule.by_month_day,
96
- byNWeekday: data.recurrence_rule.by_n_weekday,
97
- byWeekday: data.recurrence_rule.by_weekday,
98
- byYearDay: data.recurrence_rule.by_year_day,
99
- count: data.recurrence_rule.count,
100
- end: data.recurrence_rule.end && Date.parse(data.recurrence_rule.end),
101
- frequency: data.recurrence_rule.frequency,
102
- interval: data.recurrence_rule.interval,
103
- start: Date.parse(data.recurrence_rule.start),
104
- };
105
- }
106
- }
107
- }
108
-
109
- get imageURL() {
110
- return this.image ? this._client._formatImage(Endpoints.GUILD_SCHEDULED_EVENT_COVER(this.id, this.image)) : null;
111
- }
112
-
113
- /**
114
- * Delete this scheduled event
115
- * @returns {Promise}
116
- */
117
- delete() {
118
- return this._client.deleteGuildScheduledEvent.call(this._client, this.guildID, this.id);
119
- }
120
-
121
- /**
122
- * Edit this scheduled event
123
- * @arg {Object} event The new guild scheduled event object
124
- * @arg {String} [event.channelID] The channel ID of the event. If updating `entityType` to `3` (external), this **must** be set to `null`
125
- * @arg {String} [event.description] The description of the event
126
- * @arg {Object} [event.entityMetadata] The entity metadata for the scheduled event. This is required if updating `entityType` to `3` (external)
127
- * @arg {String} [event.entityMetadata.location] Location of the event. This is required if updating `entityType` to `3` (external)
128
- * @arg {Number} [event.entityType] The [entity type](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types) of the scheduled event
129
- * @arg {String} [event.image] Base 64 encoded image for the event
130
- * @arg {String} [event.name] The name of the event
131
- * @arg {String} [event.privacyLevel] The privacy level of the event
132
- * @arg {Object?} [event.recurrenceRule] The [definitions](https://discord.dev/resources/guild-scheduled-event#guild-scheduled-event-recurrence-rule-object) for how often this event should recur. Properties can be camelCase (preferred) or snake_case
133
- * @arg {Date} [event.scheduledEndTime] The time when the scheduled event is scheduled to end. This is required if updating `entityType` to `3` (external)
134
- * @arg {Date} [event.scheduledStartTime] The time the event will start
135
- * @arg {Number} [event.status] The [status](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status) of the scheduled event
136
- * @arg {String} [reason] The reason to be displayed in audit logs
137
- * @returns {Promise<GuildScheduledEvent>}
138
- */
139
- edit(event, reason) {
140
- return this._client.editGuildScheduledEvent.call(this._client, this.guildID, this.id, event, reason);
141
- }
142
-
143
- /**
144
- * Get a list of users subscribed to the guild scheduled event
145
- * @arg {Object} [options] Options for the request
146
- * @arg {String} [options.after] Get users after this user ID. If `options.before` is provided, this will be ignored. Fetching users in between `before` and `after` is not supported
147
- * @arg {String} [options.before] Get users before this user ID
148
- * @arg {Number} [options.limit=100] The number of users to get (max 100). Pagination will only work if one of `options.after` or `options.after` is also provided
149
- * @arg {Boolean} [options.withMember] Include guild member data
150
- * @returns {Promise<Array<{guildScheduledEventID: String, member?: Member, user: User}>>}
151
- */
152
- getUsers(options) {
153
- return this._client.getGuildScheduledEventUsers.call(this._client, this.guild.id, this.id, options);
154
- }
155
-
156
- toJSON(props = []) {
157
- return super.toJSON([
158
- "channel",
159
- "creator",
160
- "description",
161
- "entityID",
162
- "entityMetadata",
163
- "entityType",
164
- "guild",
165
- "name",
166
- "privacyLevel",
167
- "scheduledEndTime",
168
- "scheduledStartTime",
169
- "status",
170
- "userCount",
171
- ...props,
172
- ]);
173
- }
174
- }
175
-
176
- module.exports = GuildScheduledEvent;
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const Endpoints = require("../rest/Endpoints");
5
+
6
+ /**
7
+ * Represents a guild scheduled event
8
+ * @prop {(VoiceChannel | StageChannel | Object)?} channel The channel where the event will be held. This will be null if the event is external (`entityType` is `3`). Can be partial with only `id` if the channel or guild is not cached
9
+ * @prop {User?} creator The user that created the scheduled event. For events created before October 25 2021, this will be null. Please see the relevant Discord documentation for more details
10
+ * @prop {String?} description The description of the event
11
+ * @prop {String?} entityID The entity ID associated to the event
12
+ * @prop {Object?} entityMetadata Metadata for the event. This will be null if the event is not external (`entityType` is not `3`)
13
+ * @prop {String?} entityMetadata.location Location of the event
14
+ * @prop {Number} entityType The [entity type](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types) of the scheduled event
15
+ * @prop {Guild | Object} guild The guild which the event belongs to. Can be partial with only `id` if not cached
16
+ * @prop {String} id The ID of the guild event
17
+ * @prop {String?} image The hash of the event's image, or null if no image
18
+ * @prop {String?} imageURL The URL of the event's image, or null if no image
19
+ * @prop {String} name The name of the event
20
+ * @prop {Number} privacyLevel Event privacy level
21
+ * @prop {Object?} recurrenceRule The [definitions](https://discord.dev/resources/guild-scheduled-event#guild-scheduled-event-recurrence-rule-object) for how often this event should recur. Note: properties have been camelCased, and ISO8601 timestamps are represented by epoch number.
22
+ * @prop {Number} scheduledStartTime The time the event will start
23
+ * @prop {Number?} scheduledEndTime The time the event will end, or null if the event does not have a scheduled time to end
24
+ * @prop {Number} status The [status](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status) of the scheduled event
25
+ * @prop {Number?} userCount The number of users subscribed to the event
26
+ */
27
+ class GuildScheduledEvent extends Base {
28
+ constructor(data, client) {
29
+ super(data.id);
30
+
31
+ this._client = client;
32
+ if (data.creator !== undefined) {
33
+ this.creator = client.users.update(data.creator, this.client);
34
+ } else {
35
+ this.creator = null;
36
+ }
37
+ this.guild = client.guilds.get(data.guild_id) || {
38
+ id: data.guild_id,
39
+ };
40
+ this.scheduledEndTime = null;
41
+ this.update(data);
42
+ }
43
+
44
+ update(data) {
45
+ if (data.channel_id !== undefined) {
46
+ if (data.channel_id !== null) {
47
+ if (this._client.guilds.get(data.guild_id)) {
48
+ this.channel = this._client.guilds.get(data.guild_id).channels.get(data.channel_id) || { id: data.channel_id };
49
+ } else {
50
+ this.channel = { id: data.channel_id };
51
+ }
52
+ } else {
53
+ this.channel = null;
54
+ }
55
+ }
56
+ if (data.name !== undefined) {
57
+ this.name = data.name;
58
+ }
59
+ if (data.description !== undefined) {
60
+ this.description = data.description;
61
+ }
62
+ if (data.scheduled_start_time !== undefined) {
63
+ this.scheduledStartTime = Date.parse(data.scheduled_start_time);
64
+ }
65
+ if (data.scheduled_end_time !== undefined) {
66
+ this.scheduledEndTime = Date.parse(data.scheduled_end_time);
67
+ }
68
+ if (data.privacy_level !== undefined) {
69
+ this.privacyLevel = data.privacy_level;
70
+ }
71
+ if (data.status !== undefined) {
72
+ this.status = data.status;
73
+ }
74
+ if (data.entity_type !== undefined) {
75
+ this.entityType = data.entity_type;
76
+ }
77
+ if (data.entity_id !== undefined) {
78
+ this.entityID = data.entity_id;
79
+ }
80
+ if (data.entity_metadata !== undefined) {
81
+ this.entityMetadata = data.entity_metadata;
82
+ }
83
+ if (data.user_count !== undefined) {
84
+ this.userCount = data.user_count;
85
+ }
86
+ if (data.image !== undefined) {
87
+ this.image = data.image;
88
+ }
89
+ if (data.recurrence_rule !== undefined) {
90
+ if (data.recurrence_rule === null) {
91
+ this.recurrenceRule = null;
92
+ } else {
93
+ this.recurrenceRule = {
94
+ byMonth: data.recurrence_rule.by_month,
95
+ byMonthDay: data.recurrence_rule.by_month_day,
96
+ byNWeekday: data.recurrence_rule.by_n_weekday,
97
+ byWeekday: data.recurrence_rule.by_weekday,
98
+ byYearDay: data.recurrence_rule.by_year_day,
99
+ count: data.recurrence_rule.count,
100
+ end: data.recurrence_rule.end && Date.parse(data.recurrence_rule.end),
101
+ frequency: data.recurrence_rule.frequency,
102
+ interval: data.recurrence_rule.interval,
103
+ start: Date.parse(data.recurrence_rule.start),
104
+ };
105
+ }
106
+ }
107
+ }
108
+
109
+ get imageURL() {
110
+ return this.image ? this._client._formatImage(Endpoints.GUILD_SCHEDULED_EVENT_COVER(this.id, this.image)) : null;
111
+ }
112
+
113
+ /**
114
+ * Delete this scheduled event
115
+ * @returns {Promise}
116
+ */
117
+ delete() {
118
+ return this._client.deleteGuildScheduledEvent.call(this._client, this.guildID, this.id);
119
+ }
120
+
121
+ /**
122
+ * Edit this scheduled event
123
+ * @arg {Object} event The new guild scheduled event object
124
+ * @arg {String} [event.channelID] The channel ID of the event. If updating `entityType` to `3` (external), this **must** be set to `null`
125
+ * @arg {String} [event.description] The description of the event
126
+ * @arg {Object} [event.entityMetadata] The entity metadata for the scheduled event. This is required if updating `entityType` to `3` (external)
127
+ * @arg {String} [event.entityMetadata.location] Location of the event. This is required if updating `entityType` to `3` (external)
128
+ * @arg {Number} [event.entityType] The [entity type](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types) of the scheduled event
129
+ * @arg {String} [event.image] Base 64 encoded image for the event
130
+ * @arg {String} [event.name] The name of the event
131
+ * @arg {String} [event.privacyLevel] The privacy level of the event
132
+ * @arg {Object?} [event.recurrenceRule] The [definitions](https://discord.dev/resources/guild-scheduled-event#guild-scheduled-event-recurrence-rule-object) for how often this event should recur. Properties can be camelCase (preferred) or snake_case
133
+ * @arg {Date} [event.scheduledEndTime] The time when the scheduled event is scheduled to end. This is required if updating `entityType` to `3` (external)
134
+ * @arg {Date} [event.scheduledStartTime] The time the event will start
135
+ * @arg {Number} [event.status] The [status](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status) of the scheduled event
136
+ * @arg {String} [reason] The reason to be displayed in audit logs
137
+ * @returns {Promise<GuildScheduledEvent>}
138
+ */
139
+ edit(event, reason) {
140
+ return this._client.editGuildScheduledEvent.call(this._client, this.guildID, this.id, event, reason);
141
+ }
142
+
143
+ /**
144
+ * Get a list of users subscribed to the guild scheduled event
145
+ * @arg {Object} [options] Options for the request
146
+ * @arg {String} [options.after] Get users after this user ID. If `options.before` is provided, this will be ignored. Fetching users in between `before` and `after` is not supported
147
+ * @arg {String} [options.before] Get users before this user ID
148
+ * @arg {Number} [options.limit=100] The number of users to get (max 100). Pagination will only work if one of `options.after` or `options.after` is also provided
149
+ * @arg {Boolean} [options.withMember] Include guild member data
150
+ * @returns {Promise<Array<{guildScheduledEventID: String, member?: Member, user: User}>>}
151
+ */
152
+ getUsers(options) {
153
+ return this._client.getGuildScheduledEventUsers.call(this._client, this.guild.id, this.id, options);
154
+ }
155
+
156
+ toJSON(props = []) {
157
+ return super.toJSON([
158
+ "channel",
159
+ "creator",
160
+ "description",
161
+ "entityID",
162
+ "entityMetadata",
163
+ "entityType",
164
+ "guild",
165
+ "name",
166
+ "privacyLevel",
167
+ "scheduledEndTime",
168
+ "scheduledStartTime",
169
+ "status",
170
+ "userCount",
171
+ ...props,
172
+ ]);
173
+ }
174
+ }
175
+
176
+ module.exports = GuildScheduledEvent;
@@ -1,76 +1,76 @@
1
- const Base = require("./Base");
2
- const Guild = require("./Guild");
3
-
4
- /**
5
- * Represents a guild template
6
- * @prop {String} code The template code
7
- * @prop {Number} createdAt Timestamp of template creation
8
- * @prop {User} creator User that created the template
9
- * @prop {String?} description The template description
10
- * @prop {Boolean?} isDirty Whether the template has unsynced changes
11
- * @prop {String} name The template name
12
- * @prop {Guild} serializedSourceGuild The guild snapshot this template contains
13
- * @prop {Guild | Object} sourceGuild The guild this template is based on. If the guild is not cached, this will be an object with `id` key. No other property is guaranteed
14
- * @prop {Number} updatedAt Timestamp of template update
15
- * @prop {Number} usageCount Number of times this template has been used
16
- */
17
- class GuildTemplate {
18
- constructor(data, client) {
19
- this._client = client;
20
- this.code = data.code;
21
- this.createdAt = Date.parse(data.created_at);
22
- this.creator = client.users.update(data.creator, client);
23
- this.description = data.description;
24
- this.isDirty = data.is_dirty;
25
- this.name = data.name;
26
- this.serializedSourceGuild = new Guild(data.serialized_source_guild, client);
27
- this.sourceGuild = client.guilds.get(data.source_guild_id) || { id: data.source_guild_id };
28
- this.updatedAt = Date.parse(data.updated_at);
29
- this.usageCount = data.usage_count;
30
- }
31
-
32
- /**
33
- * Delete this template
34
- * @returns {Promise<GuildTemplate>}
35
- */
36
- delete() {
37
- return this._client.deleteGuildTemplate.call(this._client, this.sourceGuild.id, this.code);
38
- }
39
-
40
- /**
41
- * Edit this template
42
- * @arg {Object} options The properties to edit
43
- * @arg {String?} [options.description] The description for the template. Set to `null` to remove the description
44
- * @arg {String} [options.name] The name of the template
45
- * @returns {Promise<GuildTemplate>}
46
- */
47
- edit(options) {
48
- return this._client.editGuildTemplate.call(this._client, this.sourceGuild.id, this.code, options);
49
- }
50
-
51
- /**
52
- * Force this template to sync to the guild's current state
53
- * @returns {Promise<GuildTemplate>}
54
- */
55
- sync() {
56
- return this._client.syncGuildTemplate.call(this._client, this.sourceGuild.id, this.code);
57
- }
58
-
59
- toJSON(props = []) {
60
- return Base.prototype.toJSON.call(this, [
61
- "code",
62
- "createdAt",
63
- "creator",
64
- "description",
65
- "isDirty",
66
- "name",
67
- "serializedSourceGuild",
68
- "sourceGuild",
69
- "updatedAt",
70
- "usageCount",
71
- ...props,
72
- ]);
73
- }
74
- }
75
-
76
- module.exports = GuildTemplate;
1
+ const Base = require("./Base");
2
+ const Guild = require("./Guild");
3
+
4
+ /**
5
+ * Represents a guild template
6
+ * @prop {String} code The template code
7
+ * @prop {Number} createdAt Timestamp of template creation
8
+ * @prop {User} creator User that created the template
9
+ * @prop {String?} description The template description
10
+ * @prop {Boolean?} isDirty Whether the template has unsynced changes
11
+ * @prop {String} name The template name
12
+ * @prop {Guild} serializedSourceGuild The guild snapshot this template contains
13
+ * @prop {Guild | Object} sourceGuild The guild this template is based on. If the guild is not cached, this will be an object with `id` key. No other property is guaranteed
14
+ * @prop {Number} updatedAt Timestamp of template update
15
+ * @prop {Number} usageCount Number of times this template has been used
16
+ */
17
+ class GuildTemplate {
18
+ constructor(data, client) {
19
+ this._client = client;
20
+ this.code = data.code;
21
+ this.createdAt = Date.parse(data.created_at);
22
+ this.creator = client.users.update(data.creator, client);
23
+ this.description = data.description;
24
+ this.isDirty = data.is_dirty;
25
+ this.name = data.name;
26
+ this.serializedSourceGuild = new Guild(data.serialized_source_guild, client);
27
+ this.sourceGuild = client.guilds.get(data.source_guild_id) || { id: data.source_guild_id };
28
+ this.updatedAt = Date.parse(data.updated_at);
29
+ this.usageCount = data.usage_count;
30
+ }
31
+
32
+ /**
33
+ * Delete this template
34
+ * @returns {Promise<GuildTemplate>}
35
+ */
36
+ delete() {
37
+ return this._client.deleteGuildTemplate.call(this._client, this.sourceGuild.id, this.code);
38
+ }
39
+
40
+ /**
41
+ * Edit this template
42
+ * @arg {Object} options The properties to edit
43
+ * @arg {String?} [options.description] The description for the template. Set to `null` to remove the description
44
+ * @arg {String} [options.name] The name of the template
45
+ * @returns {Promise<GuildTemplate>}
46
+ */
47
+ edit(options) {
48
+ return this._client.editGuildTemplate.call(this._client, this.sourceGuild.id, this.code, options);
49
+ }
50
+
51
+ /**
52
+ * Force this template to sync to the guild's current state
53
+ * @returns {Promise<GuildTemplate>}
54
+ */
55
+ sync() {
56
+ return this._client.syncGuildTemplate.call(this._client, this.sourceGuild.id, this.code);
57
+ }
58
+
59
+ toJSON(props = []) {
60
+ return Base.prototype.toJSON.call(this, [
61
+ "code",
62
+ "createdAt",
63
+ "creator",
64
+ "description",
65
+ "isDirty",
66
+ "name",
67
+ "serializedSourceGuild",
68
+ "sourceGuild",
69
+ "updatedAt",
70
+ "usageCount",
71
+ ...props,
72
+ ]);
73
+ }
74
+ }
75
+
76
+ module.exports = GuildTemplate;