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,10 +1,21 @@
'use strict';
const { DiscordSnowflake } = require('@sapphire/snowflake');
const { PermissionFlagsBits } = require('discord-api-types/v9');
const process = require('node:process');
const Base = require('./Base');
const { Error } = require('../errors');
const PermissionsBitField = require('../util/PermissionsBitField');
const Permissions = require('../util/Permissions');
const SnowflakeUtil = require('../util/SnowflakeUtil');
const Util = require('../util/Util');
let deprecationEmittedForComparePositions = false;
/**
* @type {WeakSet<Role>}
* @private
* @internal
*/
const deletedRoles = new WeakSet();
let deprecationEmittedForDeleted = false;
/**
* Represents a role on Discord.
@@ -76,9 +87,9 @@ class Role extends Base {
if ('permissions' in data) {
/**
* The permissions of the role
* @type {Readonly<PermissionsBitField>}
* @type {Readonly<Permissions>}
*/
this.permissions = new PermissionsBitField(BigInt(data.permissions)).freeze();
this.permissions = new Permissions(BigInt(data.permissions)).freeze();
}
if ('managed' in data) {
@@ -128,7 +139,7 @@ class Role extends Base {
* @readonly
*/
get createdTimestamp() {
return DiscordSnowflake.timestampFrom(this.id);
return SnowflakeUtil.timestampFrom(this.id);
}
/**
@@ -140,6 +151,36 @@ class Role extends Base {
return new Date(this.createdTimestamp);
}
/**
* Whether or not the role has been deleted
* @type {boolean}
* @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091
*/
get deleted() {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Role#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}
return deletedRoles.has(this);
}
set deleted(value) {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Role#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}
if (value) deletedRoles.add(this);
else deletedRoles.delete(this);
}
/**
* The hexadecimal version of the role color, with a leading hashtag
* @type {string}
@@ -166,7 +207,7 @@ class Role extends Base {
get editable() {
if (this.managed) return false;
const clientMember = this.guild.members.resolve(this.client.user);
if (!clientMember.permissions.has(PermissionFlagsBits.ManageRoles)) return false;
if (!clientMember.permissions.has(Permissions.FLAGS.MANAGE_ROLES)) return false;
return clientMember.roles.highest.comparePositionTo(this) > 0;
}
@@ -225,7 +266,7 @@ class Role extends Base {
* taking into account permission overwrites.
* @param {GuildChannel|Snowflake} channel The guild channel to use as context
* @param {boolean} [checkAdmin=true] Whether having `ADMINISTRATOR` will return all permissions
* @returns {Readonly<PermissionsBitField>}
* @returns {Readonly<Permissions>}
*/
permissionsIn(channel, checkAdmin = true) {
channel = this.guild.channels.resolve(channel);
@@ -285,7 +326,7 @@ class Role extends Base {
* @returns {Promise<Role>}
* @example
* // Set the permissions of the role
* role.setPermissions([PermissionFlagsBits.KickMembers, PermissionFlagsBits.BanMembers])
* role.setPermissions([Permissions.FLAGS.KICK_MEMBERS, Permissions.FLAGS.BAN_MEMBERS])
* .then(updated => console.log(`Updated permissions to ${updated.permissions.bitfield}`))
* .catch(console.error);
* @example
@@ -358,8 +399,20 @@ class Role extends Base {
* .then(updated => console.log(`Role position: ${updated.position}`))
* .catch(console.error);
*/
setPosition(position, options = {}) {
return this.guild.roles.setPosition(this, position, options);
async setPosition(position, { relative, reason } = {}) {
const updatedRoles = await Util.setPosition(
this,
position,
relative,
this.guild._sortedRoles(),
this.client.api.guilds(this.guild.id).roles,
reason,
);
this.client.actions.GuildRolesPositionUpdate.handle({
guild_id: this.guild.id,
roles: updatedRoles,
});
return this;
}
/**
@@ -379,11 +432,12 @@ class Role extends Base {
/**
* A link to the role's icon
* @param {ImageURLOptions} [options={}] Options for the image URL
* @param {StaticImageURLOptions} [options={}] Options for the image URL
* @returns {?string}
*/
iconURL(options = {}) {
return this.icon && this.client.rest.cdn.roleIcon(this.id, this.icon, options);
iconURL({ format, size } = {}) {
if (!this.icon) return null;
return this.client.rest.cdn.RoleIcon(this.id, this.icon, format, size);
}
/**
@@ -426,9 +480,31 @@ class Role extends Base {
permissions: this.permissions.toJSON(),
};
}
/**
* Compares the positions of two roles.
* @param {Role} role1 First role to compare
* @param {Role} role2 Second role to compare
* @returns {number} Negative number if the first role's position is lower (second role's is higher),
* positive number if the first's is higher (second's is lower), 0 if equal
* @deprecated Use {@link RoleManager#comparePositions} instead.
*/
static comparePositions(role1, role2) {
if (!deprecationEmittedForComparePositions) {
process.emitWarning(
'The Role.comparePositions method is deprecated. Use RoleManager#comparePositions instead.',
'DeprecationWarning',
);
deprecationEmittedForComparePositions = true;
}
return role1.guild.roles.comparePositions(role1, role2);
}
}
exports.Role = Role;
exports.deletedRoles = deletedRoles;
/**
* @external APIRole