Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Threads): max autoArchiveDuration option #6304

Merged
merged 7 commits into from Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/managers/ThreadManager.js
Expand Up @@ -66,7 +66,8 @@ class ThreadManager extends CachedManager {
* * `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>
* @typedef {number} ThreadAutoArchiveDuration
* * `'MAX'` Based on the guilds boost count
* @typedef {number|string} ThreadAutoArchiveDuration
*/

/**
Expand Down Expand Up @@ -119,6 +120,14 @@ 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;
}
}

const data = await path.threads.post({
data: {
Expand Down
11 changes: 10 additions & 1 deletion src/structures/ThreadChannel.js
Expand Up @@ -275,11 +275,20 @@ class ThreadChannel extends Channel {
* .catch(console.error);
*/
async edit(data, reason) {
let maxAutoArchiveDuration;
papsavas marked this conversation as resolved.
Show resolved Hide resolved
if (data.autoArchiveDuration === 'MAX') {
maxAutoArchiveDuration = 1440;
if (this.guild.features.includes('SEVEN_DAY_THREAD_ARCHIVE')) {
maxAutoArchiveDuration = 10080;
} else if (this.guild.features.includes('THREE_DAY_THREAD_ARCHIVE')) {
maxAutoArchiveDuration = 4320;
}
}
const newData = await this.client.api.channels(this.id).patch({
data: {
name: (data.name ?? this.name).trim(),
archived: data.archived,
auto_archive_duration: data.autoArchiveDuration,
auto_archive_duration: maxAutoArchiveDuration ?? data.autoArchiveDuration,
rate_limit_per_user: data.rateLimitPerUser,
locked: data.locked,
},
Expand Down
2 changes: 1 addition & 1 deletion typings/index.d.ts
Expand Up @@ -4419,7 +4419,7 @@ export type TextBasedChannelTypes = TextBasedChannels['type'];

export type TextChannelResolvable = Snowflake | TextChannel;

export type ThreadAutoArchiveDuration = 60 | 1440 | 4320 | 10080;
export type ThreadAutoArchiveDuration = 60 | 1440 | 4320 | 10080 | 'MAX';

export type ThreadChannelResolvable = ThreadChannel | Snowflake;

Expand Down