From 76ce68ecf206ae5bbfbc7e599899ba9421e1763c Mon Sep 17 00:00:00 2001 From: ITOH Date: Thu, 28 Oct 2021 22:54:38 +0200 Subject: [PATCH] twilight > * --- src/bot.ts | 1 + src/cache.ts | 52 ++++++++++++++++++++++------ src/handlers/misc/PRESENCE_UPDATE.ts | 4 +-- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 37d5a7abe..8c809628b 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -106,6 +106,7 @@ import { transformAttachment } from "./transformers/attachment.ts"; import { transformEmbed } from "./transformers/embed.ts"; import { transformComponent } from "./transformers/component.ts"; import { AsyncCache, AsyncCacheHandler, Cache, CacheHandler, createCache, TableNames } from "./cache.ts"; +import { transformThread } from "./transformers/thread.ts"; type CacheOptions = | { diff --git a/src/cache.ts b/src/cache.ts index 897a04897..c4ca32f51 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -3,9 +3,12 @@ import type { DiscordenoChannel } from "./transformers/channel.ts"; import type { DiscordenoGuild } from "./transformers/guild.ts"; import type { DiscordenoMember, DiscordenoUser } from "./transformers/member.ts"; import type { DiscordenoMessage } from "./transformers/message.ts"; +import { DiscordenoPresence } from "./transformers/presence.ts"; import { PresenceUpdate } from "./types/activity/presence_update.ts"; import { Channel } from "./types/channels/channel.ts"; +import { GuildMember } from "./types/members/guild_member.ts"; import { Message } from "./types/messages/message.ts"; +import { SnakeCasedPropertiesDeep } from "./types/util.ts"; import { Collection } from "./util/collection.ts"; export function createCache( @@ -55,15 +58,21 @@ export function createCache( } as Cache; } +export type CachedDiscordenoUser = DiscordenoUser & { guilds: Map }; + export interface Cache { guilds: CacheHandler; users: CacheHandler; - channels: CacheHandler; - messages: CacheHandler; - presences: CacheHandler; + members: CacheHandler; + channels: CacheHandler; + messages: CacheHandler; + presences: CacheHandler; // threads: CacheHandler; unavailableGuilds: CacheHandler; - executedSlashCommands: Set; + dispatchedGuildIds: CacheHandler; + dispatchedChannelIds: CacheHandler; + executedSlashCommands: Set; + fetchAllMembersProcessingRequests: Map; execute: CacheExecutor; } @@ -76,12 +85,16 @@ export interface CachedUnavailableGuild { export interface AsyncCache { guilds: AsyncCacheHandler; users: AsyncCacheHandler; - channels: AsyncCacheHandler; - messages: AsyncCacheHandler; - presences: AsyncCacheHandler; + members: CacheHandler; + channels: AsyncCacheHandler; + messages: AsyncCacheHandler; + presences: AsyncCacheHandler; // threads: AsyncCacheHandler; unavailableGuilds: AsyncCacheHandler; - executedSlashCommands: Set; + dispatchedGuildIds: AsyncCacheHandler; + dispatchedChannelIds: AsyncCacheHandler; + executedSlashCommands: Set; + fetchAllMembersProcessingRequests: Map; execute: CacheExecutor; } @@ -130,14 +143,27 @@ export type AsyncCacheHandler = { [K in keyof CacheHandler]: (...args: Parameters[K]>) => Promise[K]>>; }; -export interface CacheExecutor { - (type: "DELETE_MESSAGES_FROM_CHANNEL", options: { channelId: bigint }): Promise; -} +export type CacheExecutor = ( + type: + | "FILTER_CATEGORY_CHILDREN_CHANNELS" + | "DELETE_MESSAGES_FROM_CHANNEL" + | "DELETE_ROLE_FROM_MEMBER" + | "BULK_DELETE_MESSAGES" + | "GUILD_MEMBER_CHUNK" + | "GUILD_MEMBER_COUNT_DECREMENT" + | "GUILD_MEMBER_COUNT_INCREMENT" + | "DELETE_MESSAGES_FROM_GUILD" + | "DELETE_CHANNELS_FROM_GUILD" + | "DELETE_GUILD_FROM_MEMBER", + options: Record +) => Promise; export function createExecute(cache: Cache | AsyncCache): CacheExecutor { + // @ts-ignore no time to look into these errors now return async (type, options) => { if (type === "DELETE_MESSAGES_FROM_CHANNEL") { await cache.messages.forEach(async (message) => { + // @ts-ignore me smarter than u if (BigInt(message.channelId) === options.channelId) { await cache.messages.delete(BigInt(message.id)); } @@ -145,6 +171,10 @@ export function createExecute(cache: Cache | AsyncCache): CacheExecutor { return undefined; } + + // switch type { + // case "" + // } }; } diff --git a/src/handlers/misc/PRESENCE_UPDATE.ts b/src/handlers/misc/PRESENCE_UPDATE.ts index ff7b8e1e8..e9b725ba5 100644 --- a/src/handlers/misc/PRESENCE_UPDATE.ts +++ b/src/handlers/misc/PRESENCE_UPDATE.ts @@ -8,9 +8,9 @@ export async function handlePresenceUpdate(bot: Bot, data: DiscordGatewayPayload const id = bot.transformers.snowflake(payload.user.id); - const oldPresence = await bot.cache.presence.get(id); + const oldPresence = await bot.cache.presences.get(id); const presence = bot.transformers.presence(bot, payload); - await bot.cache.presence.set(id, presence); + await bot.cache.presences.set(id, presence); bot.events.presenceUpdate(bot, presence, oldPresence); }