Skip to content

Commit

Permalink
fix: remove support for overriding caches that break functionality (#…
Browse files Browse the repository at this point in the history
…6282)

Co-authored-by: Noel <buechler.noel@outlook.com>
  • Loading branch information
ckohen and iCrawl committed Aug 4, 2021
1 parent 5be471b commit a6d4035
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/managers/ChannelManager.js
Expand Up @@ -4,13 +4,22 @@ 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}
*/
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',
);
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/managers/GuildChannelManager.js
Expand Up @@ -9,13 +9,22 @@ 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}
*/
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
Expand Down
9 changes: 9 additions & 0 deletions src/managers/GuildManager.js
Expand Up @@ -21,13 +21,22 @@ 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}
*/
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',
);
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/managers/PermissionOverwriteManager.js
Expand Up @@ -7,13 +7,22 @@ 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}
*/
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
Expand Down
9 changes: 9 additions & 0 deletions src/managers/RoleManager.js
Expand Up @@ -7,13 +7,22 @@ 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}
*/
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
Expand Down
2 changes: 2 additions & 0 deletions src/util/Options.js
Expand Up @@ -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.
* <warn>Overriding the cache used in `GuildManager`, `ChannelManager`, 'GuildChannelManager', `RoleManager`,
* and `PermissionOverwriteManager` is unsupported and **will** break functionality</warn>
* @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.
Expand Down
10 changes: 5 additions & 5 deletions typings/index.d.ts
Expand Up @@ -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];
Expand Down

0 comments on commit a6d4035

Please sign in to comment.