change filter logic

This commit is contained in:
ITOH
2021-07-08 19:54:55 +02:00
parent 5f66c7950d
commit ea0673c259
3 changed files with 44 additions and 29 deletions

View File

@@ -236,30 +236,43 @@ async function forEach(
}
}
// async function filter(
// table: "threads",
// callback: (value: DiscordenoThread, key: bigint) => boolean
// ): Promise<Collection<bigint, DiscordenoThread>>;
// async function filter(
// table: "guilds",
// callback: (value: DiscordenoGuild, key: bigint) => boolean
// ): Promise<Collection<bigint, DiscordenoGuild>>;
// async function filter(
// table: "unavailableGuilds",
// callback: (value: number, key: bigint) => boolean
// ): Promise<Collection<bigint, number>>;
// async function filter(
// table: "channels",
// callback: (value: DiscordenoChannel, key: bigint) => boolean
// ): Promise<Collection<bigint, DiscordenoChannel>>;
// async function filter(
// table: "messages",
// callback: (value: DiscordenoMessage, key: bigint) => boolean
// ): Promise<Collection<bigint, DiscordenoMessage>>;
// async function filter(
// table: "members",
// callback: (value: DiscordenoMember, key: bigint) => boolean
// ): Promise<Collection<bigint, DiscordenoMember>>;
// async function filter(table: TableName, callback: (value: any, key: bigint) => boolean) {
// return cache[table].filter(callback);
// }
async function filter(
table: "threads",
callback: (value: DiscordenoThread, key: bigint) => boolean
): Promise<Collection<bigint, DiscordenoThread>>;
async function filter(
table: "guilds",
callback: (value: DiscordenoGuild, key: bigint) => boolean
): Promise<Collection<bigint, DiscordenoGuild>>;
async function filter(
table: "unavailableGuilds",
callback: (value: number, key: bigint) => boolean
): Promise<Collection<bigint, number>>;
async function filter(
table: "channels",
callback: (value: DiscordenoChannel, key: bigint) => boolean
): Promise<Collection<bigint, DiscordenoChannel>>;
async function filter(
table: "messages",
callback: (value: DiscordenoMessage, key: bigint) => boolean
): Promise<Collection<bigint, DiscordenoMessage>>;
async function filter(
table: "members",
callback: (value: DiscordenoMember, key: bigint) => boolean
type: "GET_MEMBERS_IN_GUILD",
options: { guildId: bigint }
): Promise<Collection<bigint, DiscordenoMember>>;
async function filter(table: TableName, callback: (value: any, key: bigint) => boolean) {
return cache[table].filter(callback);
async function filter(
type: "GET_MEMBERS_IN_GUILD",
options?: Record<string, unknown>
): Promise<Collection<bigint, DiscordenoMember> | undefined> {
if (type === "GET_MEMBERS_IN_GUILD") {
return cache.members.filter((member) => member.guilds.has(options?.guildId as bigint));
}
}

View File

@@ -31,7 +31,7 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
return resolve(new Collection(members.map((m) => [m.id, m])));
}
return resolve(await cacheHandlers.filter("members", (m) => m.guilds.has(guildId)));
return resolve(await cacheHandlers.filter("GET_MEMBERS_IN_GUILD", { guildId }));
}
}
}

View File

@@ -1,6 +1,8 @@
import { cacheHandlers } from "../../cache.ts";
import { cache } from "../../cache.ts";
/** Gets an array of all the channels ids that are the children of this category. */
export async function categoryChildren(id: bigint) {
return await cacheHandlers.filter("channels", (channel) => channel.parentId === id);
/** Gets an array of all the channels ids that are the children of this category.
* ⚠️ This does not work for custom cache users!
*/
export function categoryChildren(parentChannelId: bigint) {
return cache.channels.filter((channel) => channel.parentId === parentChannelId);
}