From a6d4035176ca784e75bd1cbdf30e039658c62fd4 Mon Sep 17 00:00:00 2001 From: ckohen Date: Wed, 4 Aug 2021 14:04:40 -0700 Subject: [PATCH] fix: remove support for overriding caches that break functionality (#6282) Co-authored-by: Noel --- src/managers/ChannelManager.js | 9 +++++++++ src/managers/GuildChannelManager.js | 9 +++++++++ src/managers/GuildManager.js | 9 +++++++++ src/managers/PermissionOverwriteManager.js | 9 +++++++++ src/managers/RoleManager.js | 9 +++++++++ src/util/Options.js | 2 ++ typings/index.d.ts | 10 +++++----- 7 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/managers/ChannelManager.js b/src/managers/ChannelManager.js index 357c5af22539..55ac5fff64ff 100644 --- a/src/managers/ChannelManager.js +++ b/src/managers/ChannelManager.js @@ -4,6 +4,8 @@ const CachedManager = require('./CachedManager'); const Channel = require('../structures/Channel'); const { Events, ThreadChannelTypes } = require('../util/Constants'); +let cacheWarningEmitted = false; + /** * A manager of channels belonging to a client * @extends {CachedManager} @@ -11,6 +13,13 @@ const { Events, ThreadChannelTypes } = require('../util/Constants'); class ChannelManager extends CachedManager { constructor(client, iterable) { super(client, Channel, iterable); + if (!cacheWarningEmitted && this._cache.constructor.name !== 'Collection') { + cacheWarningEmitted = true; + process.emitWarning( + `Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`, + 'UnuspportedCacheOverwriteWarning', + ); + } } /** diff --git a/src/managers/GuildChannelManager.js b/src/managers/GuildChannelManager.js index db02c77f74ab..36c190af0be1 100644 --- a/src/managers/GuildChannelManager.js +++ b/src/managers/GuildChannelManager.js @@ -9,6 +9,8 @@ const PermissionOverwrites = require('../structures/PermissionOverwrites'); const ThreadChannel = require('../structures/ThreadChannel'); const { ChannelTypes, ThreadChannelTypes } = require('../util/Constants'); +let cacheWarningEmitted = false; + /** * Manages API methods for GuildChannels and stores their cache. * @extends {CachedManager} @@ -16,6 +18,13 @@ const { ChannelTypes, ThreadChannelTypes } = require('../util/Constants'); class GuildChannelManager extends CachedManager { constructor(guild, iterable) { super(guild.client, GuildChannel, iterable); + if (!cacheWarningEmitted && this._cache.constructor.name !== 'Collection') { + cacheWarningEmitted = true; + process.emitWarning( + `Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`, + 'UnuspportedCacheOverwriteWarning', + ); + } /** * The guild this Manager belongs to diff --git a/src/managers/GuildManager.js b/src/managers/GuildManager.js index c4a7c9c3abf6..f8d79d65d6f7 100644 --- a/src/managers/GuildManager.js +++ b/src/managers/GuildManager.js @@ -21,6 +21,8 @@ const Permissions = require('../util/Permissions'); const SystemChannelFlags = require('../util/SystemChannelFlags'); const { resolveColor } = require('../util/Util'); +let cacheWarningEmitted = false; + /** * Manages API methods for Guilds and stores their cache. * @extends {CachedManager} @@ -28,6 +30,13 @@ const { resolveColor } = require('../util/Util'); class GuildManager extends CachedManager { constructor(client, iterable) { super(client, Guild, iterable); + if (!cacheWarningEmitted && this._cache.constructor.name !== 'Collection') { + cacheWarningEmitted = true; + process.emitWarning( + `Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`, + 'UnuspportedCacheOverwriteWarning', + ); + } } /** diff --git a/src/managers/PermissionOverwriteManager.js b/src/managers/PermissionOverwriteManager.js index cadb4890b21f..26b76ac12546 100644 --- a/src/managers/PermissionOverwriteManager.js +++ b/src/managers/PermissionOverwriteManager.js @@ -7,6 +7,8 @@ const PermissionOverwrites = require('../structures/PermissionOverwrites'); const Role = require('../structures/Role'); const { OverwriteTypes } = require('../util/Constants'); +let cacheWarningEmitted = false; + /** * Manages API methods for guild channel permission overwrites and stores their cache. * @extends {CachedManager} @@ -14,6 +16,13 @@ const { OverwriteTypes } = require('../util/Constants'); class PermissionOverwriteManager extends CachedManager { constructor(channel, iterable) { super(channel.client, PermissionOverwrites); + if (!cacheWarningEmitted && this._cache.constructor.name !== 'Collection') { + cacheWarningEmitted = true; + process.emitWarning( + `Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`, + 'UnuspportedCacheOverwriteWarning', + ); + } /** * The channel of the permission overwrite this manager belongs to diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 211f96f30c9d..8f595374c022 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -7,6 +7,8 @@ const Role = require('../structures/Role'); const Permissions = require('../util/Permissions'); const { resolveColor, setPosition } = require('../util/Util'); +let cacheWarningEmitted = false; + /** * Manages API methods for roles and stores their cache. * @extends {CachedManager} @@ -14,6 +16,13 @@ const { resolveColor, setPosition } = require('../util/Util'); class RoleManager extends CachedManager { constructor(guild, iterable) { super(guild.client, Role, iterable); + if (!cacheWarningEmitted && this._cache.constructor.name !== 'Collection') { + cacheWarningEmitted = true; + process.emitWarning( + `Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`, + 'UnuspportedCacheOverwriteWarning', + ); + } /** * The guild belonging to this manager diff --git a/src/util/Options.js b/src/util/Options.js index e0dd578f7185..6278721f3799 100644 --- a/src/util/Options.js +++ b/src/util/Options.js @@ -35,6 +35,8 @@ * (e.g. recommended shard count, shard count of the ShardingManager) * @property {CacheFactory} [makeCache] Function to create a cache. * You can use your own function, or the {@link Options} class to customize the Collection used for the cache. + * Overriding the cache used in `GuildManager`, `ChannelManager`, 'GuildChannelManager', `RoleManager`, + * and `PermissionOverwriteManager` is unsupported and **will** break functionality * @property {number} [messageCacheLifetime=0] DEPRECATED: Use `makeCache` with a `LimitedCollection` instead. * How long a message should stay in the cache until it is considered sweepable (in seconds, 0 for forever) * @property {number} [messageSweepInterval=0] DEPRECATED: Use `makeCache` with a `LimitedCollection` instead. diff --git a/typings/index.d.ts b/typings/index.d.ts index 67a9a35fb505..d8a301031763 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2945,19 +2945,19 @@ export type BufferResolvable = Buffer | string; export interface Caches { ApplicationCommandManager: [manager: typeof ApplicationCommandManager, holds: typeof ApplicationCommand]; BaseGuildEmojiManager: [manager: typeof BaseGuildEmojiManager, holds: typeof GuildEmoji]; - ChannelManager: [manager: typeof ChannelManager, holds: typeof Channel]; - GuildChannelManager: [manager: typeof GuildChannelManager, holds: typeof GuildChannel]; - GuildManager: [manager: typeof GuildManager, holds: typeof Guild]; + // TODO: ChannelManager: [manager: typeof ChannelManager, holds: typeof Channel]; + // TODO: GuildChannelManager: [manager: typeof GuildChannelManager, holds: typeof GuildChannel]; + // TODO: GuildManager: [manager: typeof GuildManager, holds: typeof Guild]; GuildMemberManager: [manager: typeof GuildMemberManager, holds: typeof GuildMember]; GuildBanManager: [manager: typeof GuildBanManager, holds: typeof GuildBan]; GuildInviteManager: [manager: typeof GuildInviteManager, holds: typeof Invite]; GuildStickerManager: [manager: typeof GuildStickerManager, holds: typeof Sticker]; MessageManager: [manager: typeof MessageManager, holds: typeof Message]; - PermissionOverwriteManager: [manager: typeof PermissionOverwriteManager, holds: typeof PermissionOverwrites]; + // TODO: PermissionOverwriteManager: [manager: typeof PermissionOverwriteManager, holds: typeof PermissionOverwrites]; PresenceManager: [manager: typeof PresenceManager, holds: typeof Presence]; ReactionManager: [manager: typeof ReactionManager, holds: typeof MessageReaction]; ReactionUserManager: [manager: typeof ReactionUserManager, holds: typeof User]; - RoleManager: [manager: typeof RoleManager, holds: typeof Role]; + // TODO: RoleManager: [manager: typeof RoleManager, holds: typeof Role]; StageInstanceManager: [manager: typeof StageInstanceManager, holds: typeof StageInstance]; ThreadManager: [manager: typeof ThreadManager, holds: typeof ThreadChannel]; ThreadMemberManager: [manager: typeof ThreadMemberManager, holds: typeof ThreadMember];