feat: backport (#7787)

This commit is contained in:
Jiralite
2022-04-14 11:48:31 +01:00
committed by GitHub
parent ab324ea6ae
commit 3eb45e30b3
6 changed files with 28 additions and 22 deletions

View File

@@ -12,6 +12,7 @@ const Webhook = require('../structures/Webhook');
const { ThreadChannelTypes, ChannelTypes, VideoQualityModes } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const Util = require('../util/Util');
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
let cacheWarningEmitted = false;
let storeChannelDeprecationEmitted = false;
@@ -262,6 +263,9 @@ class GuildChannelManager extends CachedManager {
}
}
let defaultAutoArchiveDuration = data.defaultAutoArchiveDuration;
if (defaultAutoArchiveDuration === 'MAX') defaultAutoArchiveDuration = resolveAutoArchiveMaxLimit(this.guild);
const newData = await this.client.api.channels(channel.id).patch({
data: {
name: (data.name ?? channel.name).trim(),
@@ -276,7 +280,7 @@ class GuildChannelManager extends CachedManager {
parent_id: parent,
lock_permissions: data.lockPermissions,
rate_limit_per_user: data.rateLimitPerUser,
default_auto_archive_duration: data.defaultAutoArchiveDuration,
default_auto_archive_duration: defaultAutoArchiveDuration,
permission_overwrites,
},
reason,

View File

@@ -5,6 +5,7 @@ const CachedManager = require('./CachedManager');
const { TypeError } = require('../errors');
const ThreadChannel = require('../structures/ThreadChannel');
const { ChannelTypes } = require('../util/Constants');
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
/**
* Manages API methods for {@link ThreadChannel} objects and stores their cache.
@@ -120,14 +121,8 @@ class ThreadManager extends CachedManager {
} else if (this.channel.type !== 'GUILD_NEWS') {
resolvedType = typeof type === 'string' ? ChannelTypes[type] : type ?? resolvedType;
}
if (autoArchiveDuration === 'MAX') {
autoArchiveDuration = 1440;
if (this.channel.guild.features.includes('SEVEN_DAY_THREAD_ARCHIVE')) {
autoArchiveDuration = 10080;
} else if (this.channel.guild.features.includes('THREE_DAY_THREAD_ARCHIVE')) {
autoArchiveDuration = 4320;
}
}
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.channel.guild);
const data = await path.threads.post({
data: {

View File

@@ -69,7 +69,7 @@ class BaseGuildTextChannel extends GuildChannel {
if ('default_auto_archive_duration' in data) {
/**
* The default auto archive duration for newly created threads in this channel
* @type {?ThreadAutoArchiveDuration}
* @type {?number}
*/
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
}

View File

@@ -6,6 +6,7 @@ const { RangeError } = require('../errors');
const MessageManager = require('../managers/MessageManager');
const ThreadMemberManager = require('../managers/ThreadMemberManager');
const Permissions = require('../util/Permissions');
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
/**
* Represents a thread channel on Discord.
@@ -314,14 +315,8 @@ class ThreadChannel extends Channel {
*/
async edit(data, reason) {
let autoArchiveDuration = data.autoArchiveDuration;
if (data.autoArchiveDuration === 'MAX') {
autoArchiveDuration = 1440;
if (this.guild.features.includes('SEVEN_DAY_THREAD_ARCHIVE')) {
autoArchiveDuration = 10080;
} else if (this.guild.features.includes('THREE_DAY_THREAD_ARCHIVE')) {
autoArchiveDuration = 4320;
}
}
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.guild);
const newData = await this.client.api.channels(this.id).patch({
data: {
name: (data.name ?? this.name).trim(),

View File

@@ -603,6 +603,17 @@ class Util extends null {
filter.isDefault = true;
return filter;
}
/**
* Resolves the maximum time a guild's thread channels should automatcally archive in case of no recent activity.
* @param {Guild} guild The guild to resolve this limit from.
* @returns {number}
*/
static resolveAutoArchiveMaxLimit({ features }) {
if (features.includes('SEVEN_DAY_THREAD_ARCHIVE')) return 10080;
if (features.includes('THREE_DAY_THREAD_ARCHIVE')) return 4320;
return 1440;
}
}
module.exports = Util;