mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
types: Fix auto archive duration type (#7688)
* types: fix auto archive shenanigans * refactor: deduplicate into utility * types: allow `MAX` for text channels * docs(Util): english * fix(ThreadManager): assign on `MAX`
This commit is contained in:
@@ -13,6 +13,7 @@ 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;
|
||||||
let storeChannelDeprecationEmitted = false;
|
let storeChannelDeprecationEmitted = false;
|
||||||
@@ -261,6 +262,9 @@ 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(),
|
||||||
@@ -273,7 +277,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 { 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.
|
||||||
@@ -119,14 +120,8 @@ class ThreadManager extends CachedManager {
|
|||||||
} else if (this.channel.type !== ChannelType.GuildNews) {
|
} else if (this.channel.type !== ChannelType.GuildNews) {
|
||||||
resolvedType = type ?? resolvedType;
|
resolvedType = 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 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: {
|
||||||
|
|||||||
@@ -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 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 +314,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.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(),
|
||||||
|
|||||||
@@ -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 } = require('discord-api-types/v10');
|
const { ChannelType, RouteBases, Routes, GuildFeature } = 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');
|
||||||
@@ -561,6 +561,17 @@ 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;
|
||||||
|
|||||||
8
packages/discord.js/typings/index.d.ts
vendored
8
packages/discord.js/typings/index.d.ts
vendored
@@ -464,7 +464,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>;
|
||||||
@@ -2402,7 +2402,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>;
|
||||||
@@ -3681,7 +3681,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5148,7 +5148,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