Downgrade to v13

[vi] cảm giác đau khổ
This commit is contained in:
March 7th
2022-03-24 17:55:32 +07:00
parent 9596b1a210
commit 7dfdef46a5
218 changed files with 8584 additions and 9108 deletions

View File

@@ -1,11 +1,11 @@
'use strict';
const { ChannelType, PermissionFlagsBits, Routes } = require('discord-api-types/v9');
const { Channel } = require('./Channel');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { RangeError } = require('../errors');
const MessageManager = require('../managers/MessageManager');
const ThreadMemberManager = require('../managers/ThreadMemberManager');
const Permissions = require('../util/Permissions');
/**
* Represents a thread channel on Discord.
@@ -79,7 +79,7 @@ class ThreadChannel extends Channel {
* <info>Always `null` in public threads</info>
* @type {?boolean}
*/
this.invitable = this.type === ChannelType.GuildPrivateThread ? data.thread_metadata.invitable ?? false : null;
this.invitable = this.type === 'GUILD_PRIVATE_THREAD' ? data.thread_metadata.invitable ?? false : null;
/**
* Whether the thread is archived
@@ -99,12 +99,7 @@ class ThreadChannel extends Channel {
* created</info>
* @type {?number}
*/
this.archiveTimestamp = Date.parse(data.thread_metadata.archive_timestamp);
if ('create_timestamp' in data.thread_metadata) {
// Note: this is needed because we can't assign directly to getters
this._createdTimestamp = Date.parse(data.thread_metadata.create_timestamp);
}
this.archiveTimestamp = new Date(data.thread_metadata.archive_timestamp).getTime();
} else {
this.locked ??= null;
this.archived ??= null;
@@ -113,8 +108,6 @@ class ThreadChannel extends Channel {
this.invitable ??= null;
}
this._createdTimestamp ??= this.type === ChannelType.GuildPrivateThread ? super.createdTimestamp : null;
if ('owner_id' in data) {
/**
* The id of the member who created this thread
@@ -140,7 +133,7 @@ class ThreadChannel extends Channel {
* The timestamp when the last pinned message was pinned, if there was one
* @type {?number}
*/
this.lastPinTimestamp = data.last_pin_timestamp ? Date.parse(data.last_pin_timestamp) : null;
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
} else {
this.lastPinTimestamp ??= null;
}
@@ -183,16 +176,6 @@ class ThreadChannel extends Channel {
if (data.messages) for (const message of data.messages) this.messages._add(message);
}
/**
* The timestamp when this thread was created. This isn't available for threads
* created before 2022-01-09
* @type {?number}
* @readonly
*/
get createdTimestamp() {
return this._createdTimestamp;
}
/**
* A collection of associated guild member objects of this thread's members
* @type {Collection<Snowflake, GuildMember>}
@@ -209,16 +192,8 @@ class ThreadChannel extends Channel {
* @readonly
*/
get archivedAt() {
return this.archiveTimestamp && new Date(this.archiveTimestamp);
}
/**
* The time the thread was created at
* @type {?Date}
* @readonly
*/
get createdAt() {
return this.createdTimestamp && new Date(this.createdTimestamp);
if (!this.archiveTimestamp) return null;
return new Date(this.archiveTimestamp);
}
/**
@@ -253,7 +228,7 @@ class ThreadChannel extends Channel {
* account.
* @param {GuildMemberResolvable|RoleResolvable} memberOrRole The member or role to obtain the overall permissions for
* @param {boolean} [checkAdmin=true] Whether having `ADMINISTRATOR` will return all permissions
* @returns {?Readonly<PermissionsBitField>}
* @returns {?Readonly<Permissions>}
*/
permissionsFor(memberOrRole, checkAdmin) {
return this.parent?.permissionsFor(memberOrRole, checkAdmin) ?? null;
@@ -297,7 +272,7 @@ class ThreadChannel extends Channel {
* @property {number} [rateLimitPerUser] The rate limit per user (slowmode) for the thread in seconds
* @property {boolean} [locked] Whether the thread is locked
* @property {boolean} [invitable] Whether non-moderators can add other non-moderators to a thread
* <info>Can only be edited on {@link ChannelType.GuildPrivateThread}</info>
* <info>Can only be edited on `GUILD_PRIVATE_THREAD`</info>
*/
/**
@@ -322,13 +297,13 @@ class ThreadChannel extends Channel {
}
}
const newData = await this.client.api.channels(this.id).patch({
body: {
data: {
name: (data.name ?? this.name).trim(),
archived: data.archived,
auto_archive_duration: autoArchiveDuration,
rate_limit_per_user: data.rateLimitPerUser,
locked: data.locked,
invitable: this.type === ChannelType.GuildPrivateThread ? data.invitable : undefined,
invitable: this.type === 'GUILD_PRIVATE_THREAD' ? data.invitable : undefined,
},
reason,
});
@@ -377,9 +352,7 @@ class ThreadChannel extends Channel {
* @returns {Promise<ThreadChannel>}
*/
setInvitable(invitable = true, reason) {
if (this.type !== ChannelType.GuildPrivateThread) {
return Promise.reject(new RangeError('THREAD_INVITABLE_TYPE', this.type));
}
if (this.type !== 'GUILD_PRIVATE_THREAD') return Promise.reject(new RangeError('THREAD_INVITABLE_TYPE', this.type));
return this.edit({ invitable }, reason);
}
@@ -440,8 +413,7 @@ class ThreadChannel extends Channel {
*/
get editable() {
return (
(this.ownerId === this.client.user.id && (this.type !== ChannelType.GuildPrivateThread || this.joined)) ||
this.manageable
(this.ownerId === this.client.user.id && (this.type !== 'GUILD_PRIVATE_THREAD' || this.joined)) || this.manageable
);
}
@@ -455,9 +427,7 @@ class ThreadChannel extends Channel {
!this.archived &&
!this.joined &&
this.permissionsFor(this.client.user)?.has(
this.type === ChannelType.GuildPrivateThread
? PermissionFlagsBits.ManageThreads
: PermissionFlagsBits.ViewChannel,
this.type === 'GUILD_PRIVATE_THREAD' ? Permissions.FLAGS.MANAGE_THREADS : Permissions.FLAGS.VIEW_CHANNEL,
false,
)
);
@@ -472,11 +442,11 @@ class ThreadChannel extends Channel {
const permissions = this.permissionsFor(this.client.user);
if (!permissions) return false;
// This flag allows managing even if timed out
if (permissions.has(PermissionFlagsBits.Administrator, false)) return true;
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
return (
this.guild.me.communicationDisabledUntilTimestamp < Date.now() &&
permissions.has(PermissionFlagsBits.ManageThreads, false)
permissions.has(Permissions.FLAGS.MANAGE_THREADS, false)
);
}
@@ -489,7 +459,7 @@ class ThreadChannel extends Channel {
if (this.client.user.id === this.guild.ownerId) return true;
const permissions = this.permissionsFor(this.client.user);
if (!permissions) return false;
return permissions.has(PermissionFlagsBits.ViewChannel, false);
return permissions.has(Permissions.FLAGS.VIEW_CHANNEL, false);
}
/**
@@ -501,12 +471,12 @@ class ThreadChannel extends Channel {
const permissions = this.permissionsFor(this.client.user);
if (!permissions) return false;
// This flag allows sending even if timed out
if (permissions.has(PermissionFlagsBits.Administrator, false)) return true;
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
return (
!(this.archived && this.locked && !this.manageable) &&
(this.type !== ChannelType.GuildPrivateThread || this.joined || this.manageable) &&
permissions.has(PermissionFlagsBits.SendMessagesInThreads, false) &&
(this.type !== 'GUILD_PRIVATE_THREAD' || this.joined || this.manageable) &&
permissions.has(Permissions.FLAGS.SEND_MESSAGES_IN_THREADS, false) &&
this.guild.me.communicationDisabledUntilTimestamp < Date.now()
);
}
@@ -517,15 +487,7 @@ class ThreadChannel extends Channel {
* @readonly
*/
get unarchivable() {
return this.archived && this.sendable && (!this.locked || this.manageable);
}
/**
* Whether this thread is a private thread
* @returns {boolean}
*/
isPrivate() {
return this.type === ChannelType.GuildPrivateThread;
return this.archived && (this.locked ? this.manageable : this.sendable);
}
/**
@@ -539,7 +501,7 @@ class ThreadChannel extends Channel {
* .catch(console.error);
*/
async delete(reason) {
await this.guild.channels.delete(this.id, reason);
await this.client.api.channels(this.id).delete({ reason });
return this;
}