mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
feat: remove datastores and implement Managers (#3696)
* Initial commit: add 5 initial managers - Base manager - GuildChannelManager - MessageManager - PresenceManager - Reaction Manager - Added LimitedCollection * Add GuildEmojiManager, various fixes * Modify some managers and add guildmembermanager * Initial integration * Delete old stores * Integration part two, removed LRUCollection - Most of the integration has been finished - TODO typings - Removed LRUCollection, needless sweeping * Typings + stuff i somehow missed in ChannelManager * LimitedCollection typings/ final changes * Various jsdoc and syntactical fixes, Removed Util.mixin() * tslint fix * Grammatical and logical changes * Delete temporary file placed by mistake * Grammatical changes * Add missing type * Update jsdoc examples * fix: ChannelManager#remove should call cache#delete not cache#remove * fix recursive require * Fix missed cache in util * fix: more missed cache * Remove accidental _fetchMany change from #3645 * fix: use .cache.delete() over .remove() * fix: missing cache in ReactionCollector * fix: missed cache in client * fix: members is a collection not a manager Co-Authored-By: Sugden <28943913+NotSugden@users.noreply.github.com> * fix: various docs and cache fixes * fix: missed cache * fix: missing _roles * Final testing and debugging * LimitedCollection: return the Collection instead of undefined on .set * Add cache to BaseManager in typings * Commit fixes i forgot to stage yesterday * Update invite events * Account for new commit * fix: MessageReactionRemoveAll should call .cache.clear() * fix: add .cache at various places, correct return type * docs: remove mentions of 'store' * Add extra documented properties to typings Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
@@ -11,12 +11,12 @@ const Util = require('../util/Util');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
const SystemChannelFlags = require('../util/SystemChannelFlags');
|
||||
const GuildMemberStore = require('../stores/GuildMemberStore');
|
||||
const RoleStore = require('../stores/RoleStore');
|
||||
const GuildEmojiStore = require('../stores/GuildEmojiStore');
|
||||
const GuildChannelStore = require('../stores/GuildChannelStore');
|
||||
const PresenceStore = require('../stores/PresenceStore');
|
||||
const VoiceStateStore = require('../stores/VoiceStateStore');
|
||||
const GuildMemberManager = require('../managers/GuildMemberManager');
|
||||
const RoleManager = require('../managers/RoleManager');
|
||||
const GuildEmojiManager = require('../managers/GuildEmojiManager');
|
||||
const GuildChannelManager = require('../managers/GuildChannelManager');
|
||||
const PresenceManager = require('../managers/PresenceManager');
|
||||
const VoiceStateManager = require('../managers/VoiceStateManager');
|
||||
const Base = require('./Base');
|
||||
const { Error, TypeError } = require('../errors');
|
||||
|
||||
@@ -35,34 +35,34 @@ class Guild extends Base {
|
||||
super(client);
|
||||
|
||||
/**
|
||||
* A collection of members that are in this guild. The key is the member's ID, the value is the member
|
||||
* @type {GuildMemberStore<Snowflake, GuildMember>}
|
||||
* A manager of the members belonging to this guild
|
||||
* @type {GuildMemberManager}
|
||||
*/
|
||||
this.members = new GuildMemberStore(this);
|
||||
this.members = new GuildMemberManager(this);
|
||||
|
||||
/**
|
||||
* A collection of channels that are in this guild. The key is the channel's ID, the value is the channel
|
||||
* @type {GuildChannelStore<Snowflake, GuildChannel>}
|
||||
* A manager of the members belonging to this guild
|
||||
* @type {GuildChannelManager}
|
||||
*/
|
||||
this.channels = new GuildChannelStore(this);
|
||||
this.channels = new GuildChannelManager(this);
|
||||
|
||||
/**
|
||||
* A collection of roles that are in this guild. The key is the role's ID, the value is the role
|
||||
* @type {RoleStore<Snowflake, Role>}
|
||||
* A manager of the roles belonging to this guild
|
||||
* @type {RoleManager}
|
||||
*/
|
||||
this.roles = new RoleStore(this);
|
||||
this.roles = new RoleManager(this);
|
||||
|
||||
/**
|
||||
* A collection of presences in this guild
|
||||
* @type {PresenceStore<Snowflake, Presence>}
|
||||
* A manager of the presences belonging to this guild
|
||||
* @type {PresenceManager}
|
||||
*/
|
||||
this.presences = new PresenceStore(this.client);
|
||||
this.presences = new PresenceManager(this.client);
|
||||
|
||||
/**
|
||||
* A collection of voice states in this guild
|
||||
* @type {VoiceStateStore<Snowflake, VoiceState>}
|
||||
* A manager of the voice states of this guild
|
||||
* @type {VoiceStateManager}
|
||||
*/
|
||||
this.voiceStates = new VoiceStateStore(this);
|
||||
this.voiceStates = new VoiceStateManager(this);
|
||||
|
||||
/**
|
||||
* Whether the bot has been removed from the guild
|
||||
@@ -321,19 +321,19 @@ class Guild extends Base {
|
||||
this.features = data.features || this.features || [];
|
||||
|
||||
if (data.channels) {
|
||||
this.channels.clear();
|
||||
this.channels.cache.clear();
|
||||
for (const rawChannel of data.channels) {
|
||||
this.client.channels.add(rawChannel, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.roles) {
|
||||
this.roles.clear();
|
||||
this.roles.cache.clear();
|
||||
for (const role of data.roles) this.roles.add(role);
|
||||
}
|
||||
|
||||
if (data.members) {
|
||||
this.members.clear();
|
||||
this.members.cache.clear();
|
||||
for (const guildUser of data.members) this.members.add(guildUser);
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ class Guild extends Base {
|
||||
}
|
||||
|
||||
if (data.voice_states) {
|
||||
this.voiceStates.clear();
|
||||
this.voiceStates.cache.clear();
|
||||
for (const voiceState of data.voice_states) {
|
||||
this.voiceStates.add(voiceState);
|
||||
}
|
||||
@@ -360,10 +360,10 @@ class Guild extends Base {
|
||||
|
||||
if (!this.emojis) {
|
||||
/**
|
||||
* A collection of emojis that are in this guild. The key is the emoji's ID, the value is the emoji.
|
||||
* @type {GuildEmojiStore<Snowflake, GuildEmoji>}
|
||||
* A manager of the emojis belonging to this guild
|
||||
* @type {GuildEmojiManager}
|
||||
*/
|
||||
this.emojis = new GuildEmojiStore(this);
|
||||
this.emojis = new GuildEmojiManager(this);
|
||||
if (data.emojis) for (const emoji of data.emojis) this.emojis.add(emoji);
|
||||
} else if (data.emojis) {
|
||||
this.client.actions.GuildEmojisUpdate.handle({
|
||||
@@ -463,7 +463,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get owner() {
|
||||
return this.members.get(this.ownerID) || (this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) ?
|
||||
return this.members.cache.get(this.ownerID) || (this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) ?
|
||||
this.members.add({ user: { id: this.ownerID } }, true) :
|
||||
null);
|
||||
}
|
||||
@@ -474,7 +474,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get afkChannel() {
|
||||
return this.client.channels.get(this.afkChannelID) || null;
|
||||
return this.client.channels.cache.get(this.afkChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -483,7 +483,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get systemChannel() {
|
||||
return this.client.channels.get(this.systemChannelID) || null;
|
||||
return this.client.channels.cache.get(this.systemChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -492,7 +492,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get widgetChannel() {
|
||||
return this.client.channels.get(this.widgetChannelID) || null;
|
||||
return this.client.channels.cache.get(this.widgetChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -501,7 +501,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get embedChannel() {
|
||||
return this.client.channels.get(this.embedChannelID) || null;
|
||||
return this.client.channels.cache.get(this.embedChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -510,9 +510,10 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get me() {
|
||||
return this.members.get(this.client.user.id) || (this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) ?
|
||||
this.members.add({ user: { id: this.client.user.id } }, true) :
|
||||
null);
|
||||
return this.members.cache.get(this.client.user.id) ||
|
||||
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) ?
|
||||
this.members.add({ user: { id: this.client.user.id } }, true) :
|
||||
null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -521,7 +522,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get voice() {
|
||||
return this.voiceStates.get(this.client.user.id);
|
||||
return this.voiceStates.cache.get(this.client.user.id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -716,7 +717,7 @@ class Guild extends Base {
|
||||
fetchEmbed() {
|
||||
return this.client.api.guilds(this.id).embed.get().then(data => ({
|
||||
enabled: data.enabled,
|
||||
channel: data.channel_id ? this.channels.get(data.channel_id) : null,
|
||||
channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -763,7 +764,7 @@ class Guild extends Base {
|
||||
addMember(user, options) {
|
||||
user = this.client.users.resolveID(user);
|
||||
if (!user) return Promise.reject(new TypeError('INVALID_TYPE', 'user', 'UserResolvable'));
|
||||
if (this.members.has(user)) return Promise.resolve(this.members.get(user));
|
||||
if (this.members.cache.has(user)) return Promise.resolve(this.members.cache.get(user));
|
||||
options.access_token = options.accessToken;
|
||||
if (options.roles) {
|
||||
const roles = [];
|
||||
@@ -988,7 +989,7 @@ class Guild extends Base {
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild owner
|
||||
* guild.setOwner(guild.members.first())
|
||||
* guild.setOwner(guild.members.cache.first())
|
||||
* .then(updated => console.log(`Updated the guild owner to ${updated.owner.displayName}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
@@ -1203,7 +1204,7 @@ class Guild extends Base {
|
||||
* @private
|
||||
*/
|
||||
_sortedRoles() {
|
||||
return Util.discordSort(this.roles);
|
||||
return Util.discordSort(this.roles.cache);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1214,7 +1215,7 @@ class Guild extends Base {
|
||||
*/
|
||||
_sortedChannels(channel) {
|
||||
const category = channel.type === ChannelTypes.CATEGORY;
|
||||
return Util.discordSort(this.channels.filter(c =>
|
||||
return Util.discordSort(this.channels.cache.filter(c =>
|
||||
c.type === channel.type && (category || c.parent === channel.parent)
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user