mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor(ThreadChannel): Remove MAX helper from threads (#7846)
This commit is contained in:
@@ -13,7 +13,6 @@ const Webhook = require('../structures/Webhook');
|
||||
const { ThreadChannelTypes } = require('../util/Constants');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const Util = require('../util/Util');
|
||||
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
|
||||
|
||||
let cacheWarningEmitted = false;
|
||||
|
||||
@@ -253,9 +252,6 @@ class GuildChannelManager extends CachedManager {
|
||||
}
|
||||
}
|
||||
|
||||
let defaultAutoArchiveDuration = data.defaultAutoArchiveDuration;
|
||||
if (defaultAutoArchiveDuration === 'MAX') defaultAutoArchiveDuration = resolveAutoArchiveMaxLimit(this.guild);
|
||||
|
||||
const newData = await this.client.rest.patch(Routes.channel(channel.id), {
|
||||
body: {
|
||||
name: (data.name ?? channel.name).trim(),
|
||||
@@ -269,7 +265,7 @@ class GuildChannelManager extends CachedManager {
|
||||
parent_id: parent,
|
||||
lock_permissions: data.lockPermissions,
|
||||
rate_limit_per_user: data.rateLimitPerUser,
|
||||
default_auto_archive_duration: defaultAutoArchiveDuration,
|
||||
default_auto_archive_duration: data.defaultAutoArchiveDuration,
|
||||
permission_overwrites,
|
||||
},
|
||||
reason,
|
||||
|
||||
@@ -6,7 +6,6 @@ const { ChannelType, Routes } = require('discord-api-types/v10');
|
||||
const CachedManager = require('./CachedManager');
|
||||
const { TypeError } = require('../errors');
|
||||
const ThreadChannel = require('../structures/ThreadChannel');
|
||||
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Manages API methods for {@link ThreadChannel} objects and stores their cache.
|
||||
@@ -122,8 +121,6 @@ class ThreadManager extends CachedManager {
|
||||
resolvedType = type ?? resolvedType;
|
||||
}
|
||||
|
||||
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.channel.guild);
|
||||
|
||||
const data = await this.client.rest.post(Routes.threads(this.channel.id, startMessageId), {
|
||||
body: {
|
||||
name,
|
||||
|
||||
@@ -797,9 +797,8 @@ class Message extends Base {
|
||||
* archived. This can be:
|
||||
* * `60` (1 hour)
|
||||
* * `1440` (1 day)
|
||||
* * `4320` (3 days) <warn>This is only available when the guild has the `THREE_DAY_THREAD_ARCHIVE` feature.</warn>
|
||||
* * `10080` (7 days) <warn>This is only available when the guild has the `SEVEN_DAY_THREAD_ARCHIVE` feature.</warn>
|
||||
* * `'MAX'` Based on the guild's features
|
||||
* * `4320` (3 days)
|
||||
* * `10080` (7 days)
|
||||
* @typedef {number|string} ThreadAutoArchiveDuration
|
||||
*/
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||
const { RangeError } = require('../errors');
|
||||
const MessageManager = require('../managers/MessageManager');
|
||||
const ThreadMemberManager = require('../managers/ThreadMemberManager');
|
||||
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Represents a thread channel on Discord.
|
||||
@@ -313,14 +312,11 @@ class ThreadChannel extends Channel {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async edit(data, reason) {
|
||||
let autoArchiveDuration = data.autoArchiveDuration;
|
||||
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.guild);
|
||||
|
||||
const newData = await this.client.rest.patch(Routes.channel(this.id), {
|
||||
body: {
|
||||
name: (data.name ?? this.name).trim(),
|
||||
archived: data.archived,
|
||||
auto_archive_duration: autoArchiveDuration,
|
||||
auto_archive_duration: data.autoArchiveDuration,
|
||||
rate_limit_per_user: data.rateLimitPerUser,
|
||||
locked: data.locked,
|
||||
invitable: this.type === ChannelType.GuildPrivateThread ? data.invitable : undefined,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
const { parse } = require('node:path');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const { ChannelType, RouteBases, Routes, GuildFeature } = require('discord-api-types/v10');
|
||||
const { ChannelType, RouteBases, Routes } = require('discord-api-types/v10');
|
||||
const { fetch } = require('undici');
|
||||
const Colors = require('./Colors');
|
||||
const { Error: DiscordError, RangeError, TypeError } = require('../errors');
|
||||
@@ -521,17 +521,6 @@ class Util extends null {
|
||||
static cleanCodeBlockContent(text) {
|
||||
return text.replaceAll('```', '`\u200b``');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(GuildFeature.SevenDayThreadArchive)) return 10080;
|
||||
if (features.includes(GuildFeature.ThreeDayThreadArchive)) return 4320;
|
||||
return 1440;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
|
||||
11
packages/discord.js/typings/index.d.ts
vendored
11
packages/discord.js/typings/index.d.ts
vendored
@@ -500,7 +500,7 @@ export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel) {
|
||||
public createInvite(options?: CreateInviteOptions): Promise<Invite>;
|
||||
public fetchInvites(cache?: boolean): Promise<Collection<string, Invite>>;
|
||||
public setDefaultAutoArchiveDuration(
|
||||
defaultAutoArchiveDuration: ThreadAutoArchiveDuration | 'MAX',
|
||||
defaultAutoArchiveDuration: ThreadAutoArchiveDuration,
|
||||
reason?: string,
|
||||
): Promise<this>;
|
||||
public setNSFW(nsfw?: boolean, reason?: string): Promise<this>;
|
||||
@@ -2453,7 +2453,7 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhook
|
||||
public fetchStarterMessage(options?: BaseFetchOptions): Promise<Message>;
|
||||
public setArchived(archived?: boolean, reason?: string): Promise<ThreadChannel>;
|
||||
public setAutoArchiveDuration(
|
||||
autoArchiveDuration: ThreadAutoArchiveDuration | 'MAX',
|
||||
autoArchiveDuration: ThreadAutoArchiveDuration,
|
||||
reason?: string,
|
||||
): Promise<ThreadChannel>;
|
||||
public setInvitable(invitable?: boolean, reason?: string): Promise<ThreadChannel>;
|
||||
@@ -2582,7 +2582,6 @@ export class Util extends null {
|
||||
route: string,
|
||||
reason?: string,
|
||||
): Promise<{ id: Snowflake; position: number }[]>;
|
||||
public static resolveAutoArchiveMaxLimit(guild: Guild): Exclude<ThreadAutoArchiveDuration, 60>;
|
||||
}
|
||||
|
||||
export class Components extends null {
|
||||
@@ -3749,7 +3748,7 @@ export interface ChannelData {
|
||||
rateLimitPerUser?: number;
|
||||
lockPermissions?: boolean;
|
||||
permissionOverwrites?: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
||||
defaultAutoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX';
|
||||
defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
|
||||
rtcRegion?: string | null;
|
||||
videoQualityMode?: VideoQualityMode | null;
|
||||
}
|
||||
@@ -5122,7 +5121,7 @@ export type StageInstanceResolvable = StageInstance | Snowflake;
|
||||
|
||||
export interface StartThreadOptions {
|
||||
name: string;
|
||||
autoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX';
|
||||
autoArchiveDuration?: ThreadAutoArchiveDuration;
|
||||
reason?: string;
|
||||
rateLimitPerUser?: number;
|
||||
}
|
||||
@@ -5230,7 +5229,7 @@ export interface ThreadCreateOptions<AllowedThreadType> extends StartThreadOptio
|
||||
export interface ThreadEditData {
|
||||
name?: string;
|
||||
archived?: boolean;
|
||||
autoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX';
|
||||
autoArchiveDuration?: ThreadAutoArchiveDuration;
|
||||
rateLimitPerUser?: number;
|
||||
locked?: boolean;
|
||||
invitable?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user