Skip to content

Commit 3eb45e3

Browse files
authoredApr 14, 2022
feat: backport (#7787)
1 parent ab324ea commit 3eb45e3

File tree

6 files changed

+28
-22
lines changed

6 files changed

+28
-22
lines changed
 

‎src/managers/GuildChannelManager.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const Webhook = require('../structures/Webhook');
1212
const { ThreadChannelTypes, ChannelTypes, VideoQualityModes } = require('../util/Constants');
1313
const DataResolver = require('../util/DataResolver');
1414
const Util = require('../util/Util');
15+
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
1516

1617
let cacheWarningEmitted = false;
1718
let storeChannelDeprecationEmitted = false;
@@ -262,6 +263,9 @@ class GuildChannelManager extends CachedManager {
262263
}
263264
}
264265

266+
let defaultAutoArchiveDuration = data.defaultAutoArchiveDuration;
267+
if (defaultAutoArchiveDuration === 'MAX') defaultAutoArchiveDuration = resolveAutoArchiveMaxLimit(this.guild);
268+
265269
const newData = await this.client.api.channels(channel.id).patch({
266270
data: {
267271
name: (data.name ?? channel.name).trim(),
@@ -276,7 +280,7 @@ class GuildChannelManager extends CachedManager {
276280
parent_id: parent,
277281
lock_permissions: data.lockPermissions,
278282
rate_limit_per_user: data.rateLimitPerUser,
279-
default_auto_archive_duration: data.defaultAutoArchiveDuration,
283+
default_auto_archive_duration: defaultAutoArchiveDuration,
280284
permission_overwrites,
281285
},
282286
reason,

‎src/managers/ThreadManager.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const CachedManager = require('./CachedManager');
55
const { TypeError } = require('../errors');
66
const ThreadChannel = require('../structures/ThreadChannel');
77
const { ChannelTypes } = require('../util/Constants');
8+
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
89

910
/**
1011
* Manages API methods for {@link ThreadChannel} objects and stores their cache.
@@ -120,14 +121,8 @@ class ThreadManager extends CachedManager {
120121
} else if (this.channel.type !== 'GUILD_NEWS') {
121122
resolvedType = typeof type === 'string' ? ChannelTypes[type] : type ?? resolvedType;
122123
}
123-
if (autoArchiveDuration === 'MAX') {
124-
autoArchiveDuration = 1440;
125-
if (this.channel.guild.features.includes('SEVEN_DAY_THREAD_ARCHIVE')) {
126-
autoArchiveDuration = 10080;
127-
} else if (this.channel.guild.features.includes('THREE_DAY_THREAD_ARCHIVE')) {
128-
autoArchiveDuration = 4320;
129-
}
130-
}
124+
125+
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.channel.guild);
131126

132127
const data = await path.threads.post({
133128
data: {

‎src/structures/BaseGuildTextChannel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class BaseGuildTextChannel extends GuildChannel {
6969
if ('default_auto_archive_duration' in data) {
7070
/**
7171
* The default auto archive duration for newly created threads in this channel
72-
* @type {?ThreadAutoArchiveDuration}
72+
* @type {?number}
7373
*/
7474
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
7575
}

‎src/structures/ThreadChannel.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { RangeError } = require('../errors');
66
const MessageManager = require('../managers/MessageManager');
77
const ThreadMemberManager = require('../managers/ThreadMemberManager');
88
const Permissions = require('../util/Permissions');
9+
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
910

1011
/**
1112
* Represents a thread channel on Discord.
@@ -314,14 +315,8 @@ class ThreadChannel extends Channel {
314315
*/
315316
async edit(data, reason) {
316317
let autoArchiveDuration = data.autoArchiveDuration;
317-
if (data.autoArchiveDuration === 'MAX') {
318-
autoArchiveDuration = 1440;
319-
if (this.guild.features.includes('SEVEN_DAY_THREAD_ARCHIVE')) {
320-
autoArchiveDuration = 10080;
321-
} else if (this.guild.features.includes('THREE_DAY_THREAD_ARCHIVE')) {
322-
autoArchiveDuration = 4320;
323-
}
324-
}
318+
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.guild);
319+
325320
const newData = await this.client.api.channels(this.id).patch({
326321
data: {
327322
name: (data.name ?? this.name).trim(),

‎src/util/Util.js

+11
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,17 @@ class Util extends null {
603603
filter.isDefault = true;
604604
return filter;
605605
}
606+
607+
/**
608+
* Resolves the maximum time a guild's thread channels should automatcally archive in case of no recent activity.
609+
* @param {Guild} guild The guild to resolve this limit from.
610+
* @returns {number}
611+
*/
612+
static resolveAutoArchiveMaxLimit({ features }) {
613+
if (features.includes('SEVEN_DAY_THREAD_ARCHIVE')) return 10080;
614+
if (features.includes('THREE_DAY_THREAD_ARCHIVE')) return 4320;
615+
return 1440;
616+
}
606617
}
607618

608619
module.exports = Util;

‎typings/index.d.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel) {
441441
public createWebhook(name: string, options?: ChannelWebhookCreateOptions): Promise<Webhook>;
442442
public fetchInvites(cache?: boolean): Promise<Collection<string, Invite>>;
443443
public setDefaultAutoArchiveDuration(
444-
defaultAutoArchiveDuration: ThreadAutoArchiveDuration,
444+
defaultAutoArchiveDuration: ThreadAutoArchiveDuration | 'MAX',
445445
reason?: string,
446446
): Promise<this>;
447447
public setNSFW(nsfw?: boolean, reason?: string): Promise<this>;
@@ -2502,7 +2502,7 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel) {
25022502
public fetchStarterMessage(options?: BaseFetchOptions): Promise<Message>;
25032503
public setArchived(archived?: boolean, reason?: string): Promise<ThreadChannel>;
25042504
public setAutoArchiveDuration(
2505-
autoArchiveDuration: ThreadAutoArchiveDuration,
2505+
autoArchiveDuration: ThreadAutoArchiveDuration | 'MAX',
25062506
reason?: string,
25072507
): Promise<ThreadChannel>;
25082508
public setInvitable(invitable?: boolean, reason?: string): Promise<ThreadChannel>;
@@ -2628,6 +2628,7 @@ export class Util extends null {
26282628
reason?: string,
26292629
): Promise<{ id: Snowflake; position: number }[]>;
26302630
public static splitMessage(text: string, options?: SplitOptions): string[];
2631+
public static resolveAutoArchiveMaxLimit(guild: Guild): number;
26312632
}
26322633

26332634
export class Formatters extends null {
@@ -4086,7 +4087,7 @@ export interface ChannelData {
40864087
rateLimitPerUser?: number;
40874088
lockPermissions?: boolean;
40884089
permissionOverwrites?: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
4089-
defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
4090+
defaultAutoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX';
40904091
rtcRegion?: string | null;
40914092
videoQualityMode?: VideoQualityMode | null;
40924093
}
@@ -5882,7 +5883,7 @@ export type TextChannelResolvable = Snowflake | TextChannel;
58825883

58835884
export type TextBasedChannelResolvable = Snowflake | TextBasedChannel;
58845885

5885-
export type ThreadAutoArchiveDuration = 60 | 1440 | 4320 | 10080 | 'MAX';
5886+
export type ThreadAutoArchiveDuration = 60 | 1440 | 4320 | 10080;
58865887

58875888
export type ThreadChannelResolvable = ThreadChannel | Snowflake;
58885889

0 commit comments

Comments
 (0)
Please sign in to comment.