refactor: make Structure#deleted a getter to a WeakSet (#7074)

This commit is contained in:
Antonio Román
2021-12-08 10:47:54 +01:00
committed by GitHub
parent f410536c51
commit b0937502d3
51 changed files with 297 additions and 120 deletions

View File

@@ -37,6 +37,13 @@ const Util = require('../util/Util');
let deprecationEmittedForSetChannelPositions = false;
let deprecationEmittedForSetRolePositions = false;
/**
* @type {WeakSet<Guild>}
* @private
* @internal
*/
const deletedGuilds = new WeakSet();
/**
* Represents a guild (or a server) on Discord.
* <info>It's recommended to see if a guild is available before performing operations or reading data from it. You can
@@ -101,12 +108,6 @@ class Guild extends AnonymousGuild {
*/
this.invites = new GuildInviteManager(this);
/**
* Whether the bot has been removed from the guild
* @type {boolean}
*/
this.deleted = false;
if (!data) return;
if (data.unavailable) {
/**
@@ -126,6 +127,19 @@ class Guild extends AnonymousGuild {
this.shardId = data.shardId;
}
/**
* Whether or not the structure has been deleted
* @type {boolean}
*/
get deleted() {
return deletedGuilds.has(this);
}
set deleted(value) {
if (value) deletedGuilds.add(this);
else deletedGuilds.delete(this);
}
/**
* The Shard this Guild belongs to.
* @type {WebSocketShard}
@@ -1399,7 +1413,8 @@ class Guild extends AnonymousGuild {
}
}
module.exports = Guild;
exports.Guild = Guild;
exports.deletedGuilds = deletedGuilds;
/**
* @external APIGuild