mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +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 { ThreadChannelTypes } = 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;
|
||||||
|
|
||||||
@@ -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), {
|
const newData = await this.client.rest.patch(Routes.channel(channel.id), {
|
||||||
body: {
|
body: {
|
||||||
name: (data.name ?? channel.name).trim(),
|
name: (data.name ?? channel.name).trim(),
|
||||||
@@ -269,7 +265,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: defaultAutoArchiveDuration,
|
default_auto_archive_duration: data.defaultAutoArchiveDuration,
|
||||||
permission_overwrites,
|
permission_overwrites,
|
||||||
},
|
},
|
||||||
reason,
|
reason,
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const { ChannelType, Routes } = require('discord-api-types/v10');
|
|||||||
const CachedManager = require('./CachedManager');
|
const CachedManager = require('./CachedManager');
|
||||||
const { TypeError } = require('../errors');
|
const { TypeError } = require('../errors');
|
||||||
const ThreadChannel = require('../structures/ThreadChannel');
|
const ThreadChannel = require('../structures/ThreadChannel');
|
||||||
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.
|
||||||
@@ -122,8 +121,6 @@ class ThreadManager extends CachedManager {
|
|||||||
resolvedType = type ?? resolvedType;
|
resolvedType = type ?? resolvedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.channel.guild);
|
|
||||||
|
|
||||||
const data = await this.client.rest.post(Routes.threads(this.channel.id, startMessageId), {
|
const data = await this.client.rest.post(Routes.threads(this.channel.id, startMessageId), {
|
||||||
body: {
|
body: {
|
||||||
name,
|
name,
|
||||||
|
|||||||
@@ -797,9 +797,8 @@ class Message extends Base {
|
|||||||
* archived. This can be:
|
* archived. This can be:
|
||||||
* * `60` (1 hour)
|
* * `60` (1 hour)
|
||||||
* * `1440` (1 day)
|
* * `1440` (1 day)
|
||||||
* * `4320` (3 days) <warn>This is only available when the guild has the `THREE_DAY_THREAD_ARCHIVE` feature.</warn>
|
* * `4320` (3 days)
|
||||||
* * `10080` (7 days) <warn>This is only available when the guild has the `SEVEN_DAY_THREAD_ARCHIVE` feature.</warn>
|
* * `10080` (7 days)
|
||||||
* * `'MAX'` Based on the guild's features
|
|
||||||
* @typedef {number|string} ThreadAutoArchiveDuration
|
* @typedef {number|string} ThreadAutoArchiveDuration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
|||||||
const { RangeError } = require('../errors');
|
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 { resolveAutoArchiveMaxLimit } = require('../util/Util');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a thread channel on Discord.
|
* Represents a thread channel on Discord.
|
||||||
@@ -313,14 +312,11 @@ class ThreadChannel extends Channel {
|
|||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
async edit(data, reason) {
|
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), {
|
const newData = await this.client.rest.patch(Routes.channel(this.id), {
|
||||||
body: {
|
body: {
|
||||||
name: (data.name ?? this.name).trim(),
|
name: (data.name ?? this.name).trim(),
|
||||||
archived: data.archived,
|
archived: data.archived,
|
||||||
auto_archive_duration: autoArchiveDuration,
|
auto_archive_duration: data.autoArchiveDuration,
|
||||||
rate_limit_per_user: data.rateLimitPerUser,
|
rate_limit_per_user: data.rateLimitPerUser,
|
||||||
locked: data.locked,
|
locked: data.locked,
|
||||||
invitable: this.type === ChannelType.GuildPrivateThread ? data.invitable : undefined,
|
invitable: this.type === ChannelType.GuildPrivateThread ? data.invitable : undefined,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const { parse } = require('node:path');
|
const { parse } = require('node:path');
|
||||||
const { Collection } = require('@discordjs/collection');
|
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 { fetch } = require('undici');
|
||||||
const Colors = require('./Colors');
|
const Colors = require('./Colors');
|
||||||
const { Error: DiscordError, RangeError, TypeError } = require('../errors');
|
const { Error: DiscordError, RangeError, TypeError } = require('../errors');
|
||||||
@@ -521,17 +521,6 @@ class Util extends null {
|
|||||||
static cleanCodeBlockContent(text) {
|
static cleanCodeBlockContent(text) {
|
||||||
return text.replaceAll('```', '`\u200b``');
|
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;
|
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 createInvite(options?: CreateInviteOptions): Promise<Invite>;
|
||||||
public fetchInvites(cache?: boolean): Promise<Collection<string, Invite>>;
|
public fetchInvites(cache?: boolean): Promise<Collection<string, Invite>>;
|
||||||
public setDefaultAutoArchiveDuration(
|
public setDefaultAutoArchiveDuration(
|
||||||
defaultAutoArchiveDuration: ThreadAutoArchiveDuration | 'MAX',
|
defaultAutoArchiveDuration: ThreadAutoArchiveDuration,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
): Promise<this>;
|
): Promise<this>;
|
||||||
public setNSFW(nsfw?: boolean, 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 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 | 'MAX',
|
autoArchiveDuration: ThreadAutoArchiveDuration,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
): Promise<ThreadChannel>;
|
): Promise<ThreadChannel>;
|
||||||
public setInvitable(invitable?: boolean, reason?: string): Promise<ThreadChannel>;
|
public setInvitable(invitable?: boolean, reason?: string): Promise<ThreadChannel>;
|
||||||
@@ -2582,7 +2582,6 @@ export class Util extends null {
|
|||||||
route: string,
|
route: string,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
): Promise<{ id: Snowflake; position: number }[]>;
|
): Promise<{ id: Snowflake; position: number }[]>;
|
||||||
public static resolveAutoArchiveMaxLimit(guild: Guild): Exclude<ThreadAutoArchiveDuration, 60>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Components extends null {
|
export class Components extends null {
|
||||||
@@ -3749,7 +3748,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 | 'MAX';
|
defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
|
||||||
rtcRegion?: string | null;
|
rtcRegion?: string | null;
|
||||||
videoQualityMode?: VideoQualityMode | null;
|
videoQualityMode?: VideoQualityMode | null;
|
||||||
}
|
}
|
||||||
@@ -5122,7 +5121,7 @@ export type StageInstanceResolvable = StageInstance | Snowflake;
|
|||||||
|
|
||||||
export interface StartThreadOptions {
|
export interface StartThreadOptions {
|
||||||
name: string;
|
name: string;
|
||||||
autoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX';
|
autoArchiveDuration?: ThreadAutoArchiveDuration;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
rateLimitPerUser?: number;
|
rateLimitPerUser?: number;
|
||||||
}
|
}
|
||||||
@@ -5230,7 +5229,7 @@ export interface ThreadCreateOptions<AllowedThreadType> extends StartThreadOptio
|
|||||||
export interface ThreadEditData {
|
export interface ThreadEditData {
|
||||||
name?: string;
|
name?: string;
|
||||||
archived?: boolean;
|
archived?: boolean;
|
||||||
autoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX';
|
autoArchiveDuration?: ThreadAutoArchiveDuration;
|
||||||
rateLimitPerUser?: number;
|
rateLimitPerUser?: number;
|
||||||
locked?: boolean;
|
locked?: boolean;
|
||||||
invitable?: boolean;
|
invitable?: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user