mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
feat: backport (#7787)
This commit is contained in:
@@ -12,6 +12,7 @@ const Webhook = require('../structures/Webhook');
|
|||||||
const { ThreadChannelTypes, ChannelTypes, VideoQualityModes } = require('../util/Constants');
|
const { ThreadChannelTypes, ChannelTypes, VideoQualityModes } = require('../util/Constants');
|
||||||
const DataResolver = require('../util/DataResolver');
|
const DataResolver = require('../util/DataResolver');
|
||||||
const Util = require('../util/Util');
|
const Util = require('../util/Util');
|
||||||
|
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
|
||||||
|
|
||||||
let cacheWarningEmitted = false;
|
let cacheWarningEmitted = false;
|
||||||
let storeChannelDeprecationEmitted = 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({
|
const newData = await this.client.api.channels(channel.id).patch({
|
||||||
data: {
|
data: {
|
||||||
name: (data.name ?? channel.name).trim(),
|
name: (data.name ?? channel.name).trim(),
|
||||||
@@ -276,7 +280,7 @@ class GuildChannelManager extends CachedManager {
|
|||||||
parent_id: parent,
|
parent_id: parent,
|
||||||
lock_permissions: data.lockPermissions,
|
lock_permissions: data.lockPermissions,
|
||||||
rate_limit_per_user: data.rateLimitPerUser,
|
rate_limit_per_user: data.rateLimitPerUser,
|
||||||
default_auto_archive_duration: data.defaultAutoArchiveDuration,
|
default_auto_archive_duration: defaultAutoArchiveDuration,
|
||||||
permission_overwrites,
|
permission_overwrites,
|
||||||
},
|
},
|
||||||
reason,
|
reason,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const CachedManager = require('./CachedManager');
|
|||||||
const { TypeError } = require('../errors');
|
const { TypeError } = require('../errors');
|
||||||
const ThreadChannel = require('../structures/ThreadChannel');
|
const ThreadChannel = require('../structures/ThreadChannel');
|
||||||
const { ChannelTypes } = require('../util/Constants');
|
const { ChannelTypes } = require('../util/Constants');
|
||||||
|
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages API methods for {@link ThreadChannel} objects and stores their cache.
|
* 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') {
|
} else if (this.channel.type !== 'GUILD_NEWS') {
|
||||||
resolvedType = typeof type === 'string' ? ChannelTypes[type] : type ?? resolvedType;
|
resolvedType = typeof type === 'string' ? ChannelTypes[type] : type ?? resolvedType;
|
||||||
}
|
}
|
||||||
if (autoArchiveDuration === 'MAX') {
|
|
||||||
autoArchiveDuration = 1440;
|
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.channel.guild);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await path.threads.post({
|
const data = await path.threads.post({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class BaseGuildTextChannel extends GuildChannel {
|
|||||||
if ('default_auto_archive_duration' in data) {
|
if ('default_auto_archive_duration' in data) {
|
||||||
/**
|
/**
|
||||||
* The default auto archive duration for newly created threads in this channel
|
* The default auto archive duration for newly created threads in this channel
|
||||||
* @type {?ThreadAutoArchiveDuration}
|
* @type {?number}
|
||||||
*/
|
*/
|
||||||
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
|
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const { RangeError } = require('../errors');
|
|||||||
const MessageManager = require('../managers/MessageManager');
|
const MessageManager = require('../managers/MessageManager');
|
||||||
const ThreadMemberManager = require('../managers/ThreadMemberManager');
|
const ThreadMemberManager = require('../managers/ThreadMemberManager');
|
||||||
const Permissions = require('../util/Permissions');
|
const Permissions = require('../util/Permissions');
|
||||||
|
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a thread channel on Discord.
|
* Represents a thread channel on Discord.
|
||||||
@@ -314,14 +315,8 @@ class ThreadChannel extends Channel {
|
|||||||
*/
|
*/
|
||||||
async edit(data, reason) {
|
async edit(data, reason) {
|
||||||
let autoArchiveDuration = data.autoArchiveDuration;
|
let autoArchiveDuration = data.autoArchiveDuration;
|
||||||
if (data.autoArchiveDuration === 'MAX') {
|
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.guild);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const newData = await this.client.api.channels(this.id).patch({
|
const newData = await this.client.api.channels(this.id).patch({
|
||||||
data: {
|
data: {
|
||||||
name: (data.name ?? this.name).trim(),
|
name: (data.name ?? this.name).trim(),
|
||||||
|
|||||||
@@ -603,6 +603,17 @@ class Util extends null {
|
|||||||
filter.isDefault = true;
|
filter.isDefault = true;
|
||||||
return filter;
|
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;
|
module.exports = Util;
|
||||||
|
|||||||
9
typings/index.d.ts
vendored
9
typings/index.d.ts
vendored
@@ -441,7 +441,7 @@ export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel) {
|
|||||||
public createWebhook(name: string, options?: ChannelWebhookCreateOptions): Promise<Webhook>;
|
public createWebhook(name: string, options?: ChannelWebhookCreateOptions): Promise<Webhook>;
|
||||||
public fetchInvites(cache?: boolean): Promise<Collection<string, Invite>>;
|
public fetchInvites(cache?: boolean): Promise<Collection<string, Invite>>;
|
||||||
public setDefaultAutoArchiveDuration(
|
public setDefaultAutoArchiveDuration(
|
||||||
defaultAutoArchiveDuration: ThreadAutoArchiveDuration,
|
defaultAutoArchiveDuration: ThreadAutoArchiveDuration | 'MAX',
|
||||||
reason?: string,
|
reason?: string,
|
||||||
): Promise<this>;
|
): Promise<this>;
|
||||||
public setNSFW(nsfw?: boolean, reason?: string): Promise<this>;
|
public setNSFW(nsfw?: boolean, reason?: string): Promise<this>;
|
||||||
@@ -2502,7 +2502,7 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel) {
|
|||||||
public fetchStarterMessage(options?: BaseFetchOptions): Promise<Message>;
|
public fetchStarterMessage(options?: BaseFetchOptions): Promise<Message>;
|
||||||
public setArchived(archived?: boolean, reason?: string): Promise<ThreadChannel>;
|
public setArchived(archived?: boolean, reason?: string): Promise<ThreadChannel>;
|
||||||
public setAutoArchiveDuration(
|
public setAutoArchiveDuration(
|
||||||
autoArchiveDuration: ThreadAutoArchiveDuration,
|
autoArchiveDuration: ThreadAutoArchiveDuration | 'MAX',
|
||||||
reason?: string,
|
reason?: string,
|
||||||
): Promise<ThreadChannel>;
|
): Promise<ThreadChannel>;
|
||||||
public setInvitable(invitable?: boolean, reason?: string): Promise<ThreadChannel>;
|
public setInvitable(invitable?: boolean, reason?: string): Promise<ThreadChannel>;
|
||||||
@@ -2628,6 +2628,7 @@ export class Util extends null {
|
|||||||
reason?: string,
|
reason?: string,
|
||||||
): Promise<{ id: Snowflake; position: number }[]>;
|
): Promise<{ id: Snowflake; position: number }[]>;
|
||||||
public static splitMessage(text: string, options?: SplitOptions): string[];
|
public static splitMessage(text: string, options?: SplitOptions): string[];
|
||||||
|
public static resolveAutoArchiveMaxLimit(guild: Guild): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Formatters extends null {
|
export class Formatters extends null {
|
||||||
@@ -4086,7 +4087,7 @@ export interface ChannelData {
|
|||||||
rateLimitPerUser?: number;
|
rateLimitPerUser?: number;
|
||||||
lockPermissions?: boolean;
|
lockPermissions?: boolean;
|
||||||
permissionOverwrites?: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
permissionOverwrites?: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
||||||
defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
|
defaultAutoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX';
|
||||||
rtcRegion?: string | null;
|
rtcRegion?: string | null;
|
||||||
videoQualityMode?: VideoQualityMode | null;
|
videoQualityMode?: VideoQualityMode | null;
|
||||||
}
|
}
|
||||||
@@ -5882,7 +5883,7 @@ export type TextChannelResolvable = Snowflake | TextChannel;
|
|||||||
|
|
||||||
export type TextBasedChannelResolvable = Snowflake | TextBasedChannel;
|
export type TextBasedChannelResolvable = Snowflake | TextBasedChannel;
|
||||||
|
|
||||||
export type ThreadAutoArchiveDuration = 60 | 1440 | 4320 | 10080 | 'MAX';
|
export type ThreadAutoArchiveDuration = 60 | 1440 | 4320 | 10080;
|
||||||
|
|
||||||
export type ThreadChannelResolvable = ThreadChannel | Snowflake;
|
export type ThreadChannelResolvable = ThreadChannel | Snowflake;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user