mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 01:40:08 +00:00
change filter logic
This commit is contained in:
61
src/cache.ts
61
src/cache.ts
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user