diff --git a/src/cache.ts b/src/cache.ts index 02f30ca09..76f351156 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -23,12 +23,19 @@ export const cache = { presences: new Collection(), fetchAllMembersProcessingRequests: new Collection< string, - (value: Collection | PromiseLike>) => void + ( + value: + | Collection + | PromiseLike>, + ) => void >(), executedSlashCommands: new Set(), get emojis() { return new Collection( - this.guilds.reduce((a, b) => [...a, ...b.emojis.map((e) => [e.id, e])], [] as any[]) + this.guilds.reduce( + (a, b) => [...a, ...b.emojis.map((e) => [e.id, e])], + [] as any[], + ), ); }, }; @@ -63,72 +70,142 @@ export let cacheHandlers = { filter, }; -export type TableName = "guilds" | "unavailableGuilds" | "channels" | "messages" | "members" | "presences"; +export type TableName = + | "guilds" + | "unavailableGuilds" + | "channels" + | "messages" + | "members" + | "presences"; -function set(table: "guilds", key: bigint, value: DiscordenoGuild): Promise>; -function set(table: "channels", key: bigint, value: DiscordenoChannel): Promise>; -function set(table: "messages", key: bigint, value: DiscordenoMessage): Promise>; -function set(table: "members", key: bigint, value: DiscordenoMember): Promise>; -function set(table: "presences", key: bigint, value: PresenceUpdate): Promise>; -function set(table: "unavailableGuilds", key: bigint, value: number): Promise>; +function set( + table: "guilds", + key: bigint, + value: DiscordenoGuild, +): Promise>; +function set( + table: "channels", + key: bigint, + value: DiscordenoChannel, +): Promise>; +function set( + table: "messages", + key: bigint, + value: DiscordenoMessage, +): Promise>; +function set( + table: "members", + key: bigint, + value: DiscordenoMember, +): Promise>; +function set( + table: "presences", + key: bigint, + value: PresenceUpdate, +): Promise>; +function set( + table: "unavailableGuilds", + key: bigint, + value: number, +): Promise>; async function set(table: TableName, key: bigint, value: any) { return cache[table].set(key, value); } -function get(table: "guilds", key: bigint): Promise; -function get(table: "channels", key: bigint): Promise; -function get(table: "messages", key: bigint): Promise; -function get(table: "members", key: bigint): Promise; -function get(table: "presences", key: bigint): Promise; -function get(table: "unavailableGuilds", key: bigint): Promise; +function get( + table: "guilds", + key: bigint, +): Promise; +function get( + table: "channels", + key: bigint, +): Promise; +function get( + table: "messages", + key: bigint, +): Promise; +function get( + table: "members", + key: bigint, +): Promise; +function get( + table: "presences", + key: bigint, +): Promise; +function get( + table: "unavailableGuilds", + key: bigint, +): Promise; async function get(table: TableName, key: bigint) { return cache[table].get(key); } function forEach( table: "guilds", - callback: (value: DiscordenoGuild, key: bigint, map: Map) => unknown + callback: ( + value: DiscordenoGuild, + key: bigint, + map: Map, + ) => unknown, ): void; function forEach( table: "unavailableGuilds", - callback: (value: number, key: bigint, map: Map) => unknown + callback: (value: number, key: bigint, map: Map) => unknown, ): void; function forEach( table: "channels", - callback: (value: DiscordenoChannel, key: bigint, map: Map) => unknown + callback: ( + value: DiscordenoChannel, + key: bigint, + map: Map, + ) => unknown, ): void; function forEach( table: "messages", - callback: (value: DiscordenoMessage, key: bigint, map: Map) => unknown + callback: ( + value: DiscordenoMessage, + key: bigint, + map: Map, + ) => unknown, ): void; function forEach( table: "members", - callback: (value: DiscordenoMember, key: bigint, map: Map) => unknown + callback: ( + value: DiscordenoMember, + key: bigint, + map: Map, + ) => unknown, ): void; -function forEach(table: TableName, callback: (value: any, key: bigint, map: Map) => unknown) { +function forEach( + table: TableName, + callback: (value: any, key: bigint, map: Map) => unknown, +) { return cache[table].forEach(callback); } function filter( table: "guilds", - callback: (value: DiscordenoGuild, key: bigint) => boolean + callback: (value: DiscordenoGuild, key: bigint) => boolean, ): Promise>; function filter( table: "unavailableGuilds", - callback: (value: number, key: bigint) => boolean + callback: (value: number, key: bigint) => boolean, ): Promise>; function filter( table: "channels", - callback: (value: DiscordenoChannel, key: bigint) => boolean + callback: (value: DiscordenoChannel, key: bigint) => boolean, ): Promise>; function filter( table: "messages", - callback: (value: DiscordenoMessage, key: bigint) => boolean + callback: (value: DiscordenoMessage, key: bigint) => boolean, ): Promise>; function filter( table: "members", - callback: (value: DiscordenoMember, key: bigint) => boolean + callback: (value: DiscordenoMember, key: bigint) => boolean, ): Promise>; -async function filter(table: TableName, callback: (value: any, key: bigint) => boolean) { +async function filter( + table: TableName, + callback: (value: any, key: bigint) => boolean, +) { return cache[table].filter(callback); }