mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
perf: use logical assignments instead of if statements (#6693)
This commit is contained in:
@@ -93,9 +93,7 @@ class GuildBanManager extends CachedManager {
|
||||
if (!options) return this._fetchMany();
|
||||
const user = this.client.users.resolveId(options);
|
||||
if (user) return this._fetchSingle({ user, cache: true });
|
||||
if (options.user) {
|
||||
options.user = this.client.users.resolveId(options.user);
|
||||
}
|
||||
options.user &&= this.client.users.resolveId(options.user);
|
||||
if (!options.user) {
|
||||
if ('cache' in options) return this._fetchMany(options.cache);
|
||||
return Promise.reject(new Error('FETCH_BAN_RESOLVE_ID'));
|
||||
|
||||
@@ -133,10 +133,8 @@ class GuildChannelManager extends CachedManager {
|
||||
name,
|
||||
{ type, topic, nsfw, bitrate, userLimit, parent, permissionOverwrites, position, rateLimitPerUser, reason } = {},
|
||||
) {
|
||||
if (parent) parent = this.client.channels.resolveId(parent);
|
||||
if (permissionOverwrites) {
|
||||
permissionOverwrites = permissionOverwrites.map(o => PermissionOverwrites.resolve(o, this.guild));
|
||||
}
|
||||
parent &&= this.client.channels.resolveId(parent);
|
||||
permissionOverwrites &&= permissionOverwrites.map(o => PermissionOverwrites.resolve(o, this.guild));
|
||||
|
||||
const data = await this.client.api.guilds(this.guild.id).channels.post({
|
||||
data: {
|
||||
|
||||
@@ -188,8 +188,8 @@ class GuildManager extends CachedManager {
|
||||
explicitContentFilter = ExplicitContentFilterLevels[explicitContentFilter];
|
||||
}
|
||||
for (const channel of channels) {
|
||||
if (channel.type) channel.type = ChannelTypes[channel.type.toUpperCase()];
|
||||
if (channel.type) channel.type = typeof channel.type === 'number' ? channel.type : ChannelTypes[channel.type];
|
||||
channel.type &&= ChannelTypes[channel.type.toUpperCase()];
|
||||
channel.type &&= typeof channel.type === 'number' ? channel.type : ChannelTypes[channel.type];
|
||||
channel.parent_id = channel.parentId;
|
||||
delete channel.parentId;
|
||||
channel.user_limit = channel.userLimit;
|
||||
@@ -201,17 +201,17 @@ class GuildManager extends CachedManager {
|
||||
if (typeof overwrite.type === 'string') {
|
||||
overwrite.type = OverwriteTypes[overwrite.type];
|
||||
}
|
||||
if (overwrite.allow) overwrite.allow = Permissions.resolve(overwrite.allow).toString();
|
||||
if (overwrite.deny) overwrite.deny = Permissions.resolve(overwrite.deny).toString();
|
||||
overwrite.allow &&= Permissions.resolve(overwrite.allow).toString();
|
||||
overwrite.deny &&= Permissions.resolve(overwrite.deny).toString();
|
||||
}
|
||||
channel.permission_overwrites = channel.permissionOverwrites;
|
||||
delete channel.permissionOverwrites;
|
||||
}
|
||||
for (const role of roles) {
|
||||
if (role.color) role.color = resolveColor(role.color);
|
||||
if (role.permissions) role.permissions = Permissions.resolve(role.permissions).toString();
|
||||
role.color &&= resolveColor(role.color);
|
||||
role.permissions &&= Permissions.resolve(role.permissions).toString();
|
||||
}
|
||||
if (systemChannelFlags) systemChannelFlags = SystemChannelFlags.resolve(systemChannelFlags);
|
||||
systemChannelFlags &&= SystemChannelFlags.resolve(systemChannelFlags);
|
||||
|
||||
const data = await this.client.api.guilds.post({
|
||||
data: {
|
||||
|
||||
@@ -248,7 +248,7 @@ class GuildMemberManager extends CachedManager {
|
||||
_data.channel_id = null;
|
||||
_data.channel = undefined;
|
||||
}
|
||||
if (_data.roles) _data.roles = _data.roles.map(role => (role instanceof Role ? role.id : role));
|
||||
_data.roles &&= _data.roles.map(role => (role instanceof Role ? role.id : role));
|
||||
let endpoint = this.client.api.guilds(this.guild.id);
|
||||
if (id === this.client.user.id) {
|
||||
const keys = Object.keys(_data);
|
||||
|
||||
@@ -129,7 +129,7 @@ class RoleManager extends CachedManager {
|
||||
*/
|
||||
async create(options = {}) {
|
||||
let { name, color, hoist, permissions, position, mentionable, reason } = options;
|
||||
if (color) color = resolveColor(color);
|
||||
color &&= resolveColor(color);
|
||||
if (typeof permissions !== 'undefined') permissions = new Permissions(permissions);
|
||||
|
||||
const data = await this.client.api.guilds(this.guild.id).roles.post({
|
||||
|
||||
@@ -60,7 +60,7 @@ class StageInstanceManager extends CachedManager {
|
||||
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
|
||||
let { topic, privacyLevel } = options;
|
||||
|
||||
if (privacyLevel) privacyLevel = typeof privacyLevel === 'number' ? privacyLevel : PrivacyLevels[privacyLevel];
|
||||
privacyLevel &&= typeof privacyLevel === 'number' ? privacyLevel : PrivacyLevels[privacyLevel];
|
||||
|
||||
const data = await this.client.api['stage-instances'].post({
|
||||
data: {
|
||||
@@ -122,7 +122,7 @@ class StageInstanceManager extends CachedManager {
|
||||
|
||||
let { topic, privacyLevel } = options;
|
||||
|
||||
if (privacyLevel) privacyLevel = typeof privacyLevel === 'number' ? privacyLevel : PrivacyLevels[privacyLevel];
|
||||
privacyLevel &&= typeof privacyLevel === 'number' ? privacyLevel : PrivacyLevels[privacyLevel];
|
||||
|
||||
const data = await this.client.api('stage-instances', channelId).patch({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user