11'use strict' ;
22
3- const GuildChannel = require ( './GuildChannel' ) ;
4- const TextBasedChannel = require ( './interfaces/TextBasedChannel' ) ;
5- const GuildForumThreadManager = require ( '../managers/GuildForumThreadManager' ) ;
6- const { transformAPIGuildForumTag, transformAPIGuildDefaultReaction } = require ( '../util/Channels' ) ;
3+ const ThreadOnlyChannel = require ( './ThreadOnlyChannel' ) ;
74
85/**
9- * @typedef {Object } GuildForumTagEmoji
10- * @property {?Snowflake } id The id of a guild's custom emoji
11- * @property {?string } name The unicode character of the emoji
6+ * Represents a forum channel.
7+ * @extends {ThreadOnlyChannel }
128 */
13-
14- /**
15- * @typedef {Object } GuildForumTag
16- * @property {Snowflake } id The id of the tag
17- * @property {string } name The name of the tag
18- * @property {boolean } moderated Whether this tag can only be added to or removed from threads
19- * by a member with the `ManageThreads` permission
20- * @property {?GuildForumTagEmoji } emoji The emoji of this tag
21- */
22-
23- /**
24- * @typedef {Object } GuildForumTagData
25- * @property {Snowflake } [id] The id of the tag
26- * @property {string } name The name of the tag
27- * @property {boolean } [moderated] Whether this tag can only be added to or removed from threads
28- * by a member with the `ManageThreads` permission
29- * @property {?GuildForumTagEmoji } [emoji] The emoji of this tag
30- */
31-
32- /**
33- * @typedef {Object } DefaultReactionEmoji
34- * @property {?Snowflake } id The id of a guild's custom emoji
35- * @property {?string } name The unicode character of the emoji
36- */
37-
38- /**
39- * Represents a channel that only contains threads
40- * @extends {GuildChannel }
41- * @implements {TextBasedChannel}
42- */
43- class ForumChannel extends GuildChannel {
44- constructor ( guild , data , client ) {
45- super ( guild , data , client , false ) ;
46-
47- /**
48- * A manager of the threads belonging to this channel
49- * @type {GuildForumThreadManager }
50- */
51- this . threads = new GuildForumThreadManager ( this ) ;
52-
53- this . _patch ( data ) ;
54- }
55-
9+ class ForumChannel extends ThreadOnlyChannel {
5610 _patch ( data ) {
5711 super . _patch ( data ) ;
58- if ( 'available_tags' in data ) {
59- /**
60- * The set of tags that can be used in this channel.
61- * @type {GuildForumTag[] }
62- */
63- this . availableTags = data . available_tags . map ( tag => transformAPIGuildForumTag ( tag ) ) ;
64- } else {
65- this . availableTags ??= [ ] ;
66- }
67-
68- if ( 'default_reaction_emoji' in data ) {
69- /**
70- * The emoji to show in the add reaction button on a thread in a guild forum channel
71- * @type {?DefaultReactionEmoji }
72- */
73- this . defaultReactionEmoji = data . default_reaction_emoji
74- ? transformAPIGuildDefaultReaction ( data . default_reaction_emoji )
75- : null ;
76- } else {
77- this . defaultReactionEmoji ??= null ;
78- }
79-
80- if ( 'default_thread_rate_limit_per_user' in data ) {
81- /**
82- * The initial rate limit per user (slowmode) to set on newly created threads in a channel.
83- * @type {?number }
84- */
85- this . defaultThreadRateLimitPerUser = data . default_thread_rate_limit_per_user ;
86- } else {
87- this . defaultThreadRateLimitPerUser ??= null ;
88- }
89-
90- if ( 'rate_limit_per_user' in data ) {
91- /**
92- * The rate limit per user (slowmode) for this channel.
93- * @type {?number }
94- */
95- this . rateLimitPerUser = data . rate_limit_per_user ;
96- } else {
97- this . rateLimitPerUser ??= null ;
98- }
99-
100- if ( 'default_auto_archive_duration' in data ) {
101- /**
102- * The default auto archive duration for newly created threads in this channel.
103- * @type {?ThreadAutoArchiveDuration }
104- */
105- this . defaultAutoArchiveDuration = data . default_auto_archive_duration ;
106- } else {
107- this . defaultAutoArchiveDuration ??= null ;
108- }
109-
110- if ( 'nsfw' in data ) {
111- /**
112- * If this channel is considered NSFW.
113- * @type {boolean }
114- */
115- this . nsfw = data . nsfw ;
116- } else {
117- this . nsfw ??= false ;
118- }
119-
120- if ( 'topic' in data ) {
121- /**
122- * The topic of this channel.
123- * @type {?string }
124- */
125- this . topic = data . topic ;
126- }
127-
128- if ( 'default_sort_order' in data ) {
129- /**
130- * The default sort order mode used to order posts
131- * @type {?SortOrderType }
132- */
133- this . defaultSortOrder = data . default_sort_order ;
134- } else {
135- this . defaultSortOrder ??= null ;
136- }
13712
13813 /**
13914 * The default layout type used to display posts
@@ -142,95 +17,6 @@ class ForumChannel extends GuildChannel {
14217 this . defaultForumLayout = data . default_forum_layout ;
14318 }
14419
145- /**
146- * Sets the available tags for this forum channel
147- * @param {GuildForumTagData[] } availableTags The tags to set as available in this channel
148- * @param {string } [reason] Reason for changing the available tags
149- * @returns {Promise<ForumChannel> }
150- */
151- setAvailableTags ( availableTags , reason ) {
152- return this . edit ( { availableTags, reason } ) ;
153- }
154-
155- /**
156- * Sets the default reaction emoji for this channel
157- * @param {?DefaultReactionEmoji } defaultReactionEmoji The emoji to set as the default reaction emoji
158- * @param {string } [reason] Reason for changing the default reaction emoji
159- * @returns {Promise<ForumChannel> }
160- */
161- setDefaultReactionEmoji ( defaultReactionEmoji , reason ) {
162- return this . edit ( { defaultReactionEmoji, reason } ) ;
163- }
164-
165- /**
166- * Sets the default rate limit per user (slowmode) for new threads in this channel
167- * @param {number } defaultThreadRateLimitPerUser The rate limit to set on newly created threads in this channel
168- * @param {string } [reason] Reason for changing the default rate limit
169- * @returns {Promise<ForumChannel> }
170- */
171- setDefaultThreadRateLimitPerUser ( defaultThreadRateLimitPerUser , reason ) {
172- return this . edit ( { defaultThreadRateLimitPerUser, reason } ) ;
173- }
174-
175- /**
176- * Creates an invite to this guild channel.
177- * @param {InviteCreateOptions } [options={}] The options for creating the invite
178- * @returns {Promise<Invite> }
179- * @example
180- * // Create an invite to a channel
181- * channel.createInvite()
182- * .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
183- * .catch(console.error);
184- */
185- createInvite ( options ) {
186- return this . guild . invites . create ( this . id , options ) ;
187- }
188-
189- /**
190- * Fetches a collection of invites to this guild channel.
191- * Resolves with a collection mapping invites by their codes.
192- * @param {boolean } [cache=true] Whether to cache the fetched invites
193- * @returns {Promise<Collection<string, Invite>> }
194- */
195- fetchInvites ( cache ) {
196- return this . guild . invites . fetch ( { channelId : this . id , cache } ) ;
197- }
198-
199- /**
200- * Sets the default auto archive duration for all newly created threads in this channel.
201- * @param {ThreadAutoArchiveDuration } defaultAutoArchiveDuration The new default auto archive duration
202- * @param {string } [reason] Reason for changing the channel's default auto archive duration
203- * @returns {Promise<ForumChannel> }
204- */
205- setDefaultAutoArchiveDuration ( defaultAutoArchiveDuration , reason ) {
206- return this . edit ( { defaultAutoArchiveDuration, reason } ) ;
207- }
208-
209- /**
210- * Sets a new topic for the guild channel.
211- * @param {?string } topic The new topic for the guild channel
212- * @param {string } [reason] Reason for changing the guild channel's topic
213- * @returns {Promise<ForumChannel> }
214- * @example
215- * // Set a new channel topic
216- * channel.setTopic('needs more rate limiting')
217- * .then(newChannel => console.log(`Channel's new topic is ${newChannel.topic}`))
218- * .catch(console.error);
219- */
220- setTopic ( topic , reason ) {
221- return this . edit ( { topic, reason } ) ;
222- }
223-
224- /**
225- * Sets the default sort order mode used to order posts
226- * @param {?SortOrderType } defaultSortOrder The default sort order mode to set on this channel
227- * @param {string } [reason] Reason for changing the default sort order
228- * @returns {Promise<ForumChannel> }
229- */
230- setDefaultSortOrder ( defaultSortOrder , reason ) {
231- return this . edit ( { defaultSortOrder, reason } ) ;
232- }
233-
23420 /**
23521 * Sets the default forum layout type used to display posts
23622 * @param {ForumLayoutType } defaultForumLayout The default forum layout type to set on this channel
@@ -240,25 +26,6 @@ class ForumChannel extends GuildChannel {
24026 setDefaultForumLayout ( defaultForumLayout , reason ) {
24127 return this . edit ( { defaultForumLayout, reason } ) ;
24228 }
243-
244- // These are here only for documentation purposes - they are implemented by TextBasedChannel
245- /* eslint-disable no-empty-function */
246- createWebhook ( ) { }
247- fetchWebhooks ( ) { }
248- setNSFW ( ) { }
249- setRateLimitPerUser ( ) { }
25029}
25130
252- TextBasedChannel . applyToClass ( ForumChannel , true , [
253- 'send' ,
254- 'lastMessage' ,
255- 'lastPinAt' ,
256- 'bulkDelete' ,
257- 'sendTyping' ,
258- 'createMessageCollector' ,
259- 'awaitMessages' ,
260- 'createMessageComponentCollector' ,
261- 'awaitMessageComponent' ,
262- ] ) ;
263-
26431module . exports = ForumChannel ;
0 commit comments