diff --git a/src/client/base.ts b/src/client/base.ts index 0a75d76..a379b52 100644 --- a/src/client/base.ts +++ b/src/client/base.ts @@ -193,12 +193,41 @@ export class BaseClient { this.rest = rest; } if (cache) { + const caches: (keyof Cache['disabledCache'])[] = [ + 'bans', + 'channels', + 'emojis', + 'guilds', + 'members', + 'messages', + 'onPacket', + 'overwrites', + 'presences', + 'roles', + 'stageInstances', + 'stickers', + 'threads', + 'users', + 'voiceStates', + ]; + let disabledCache: Partial> = this.cache?.disabledCache ?? {}; + + if (typeof cache.disabledCache === 'boolean') { + for (const i of caches) { + disabledCache[i] = cache.disabledCache; + } + } else if (typeof cache.disabledCache === 'function') { + for (const i of caches) { + disabledCache[i] = cache.disabledCache(i); + } + } else if (typeof cache.disabledCache === 'object') { + disabledCache = cache.disabledCache; + } + this.cache = new Cache( this.cache?.intents ?? 0, cache?.adapter ?? this.cache?.adapter ?? new MemoryAdapter(), - (typeof cache.disabledCache === 'boolean' ? { onPacket: cache.disabledCache } : cache.disabledCache) ?? - this.cache?.disabledCache ?? - [], + disabledCache, this, ); } @@ -527,7 +556,10 @@ export type RuntimeConfig = OmitInsert< export interface ServicesOptions { rest?: ApiHandler; - cache?: { adapter?: Adapter; disabledCache?: true | Cache['disabledCache'] }; + cache?: { + adapter?: Adapter; + disabledCache?: boolean | Cache['disabledCache'] | ((cacheType: keyof Cache['disabledCache']) => boolean); + }; langs?: { default?: string; aliases?: Record; diff --git a/src/commands/applications/shared.ts b/src/commands/applications/shared.ts index c049db8..f8766bc 100644 --- a/src/commands/applications/shared.ts +++ b/src/commands/applications/shared.ts @@ -16,6 +16,9 @@ export interface ExtendContext {} export interface ExtraProps {} export interface UsingClient extends BaseClient {} export type ParseClient = T; +export type ParseGlobalMiddlewares> = { + [K in keyof T]: MetadataMiddleware; +}; export interface InternalOptions {} export interface CustomStructures {}