From 8ddd16c61e2aa7d776b1e65d16f87f399b6c2e0e Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 9 Oct 2021 17:07:55 +0000 Subject: [PATCH] channel create handler --- src/bot.ts | 18 ++++++++++++++++++ src/handlers/channels/CHANNEL_CREATE.ts | 14 ++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index b1826a9e6..e7e481bef 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -15,6 +15,8 @@ import { processQueue } from "./rest/process_queue.ts"; import { snowflakeToBigint } from "./util/bigint.ts"; import { Collection } from "./util/collection.ts"; import { DiscordenoUser, transformMember, transformUser } from "./transformers/member.ts"; +import { SnakeCasedPropertiesDeep } from "./types/util.ts"; +import { Channel } from "./types/channels/channel.ts"; export async function createBot(options: CreateBotOptions) { return { @@ -91,6 +93,8 @@ export function createRestManager(options: CreateRestManagerOptions) { } export async function startBot(bot: Bot) { + const transformers = createTransformers(bot.transformers); + // SETUP CACHE bot.users = new Collection(); @@ -99,6 +103,16 @@ export async function startBot(bot: Bot) { // START WS bot.gateway = createGatewayManager(); + + +} + +export interface CreateGatewayManagerOptions { + transformers: Partial; +} + +export function createGatewayManager(options: CreateGatewayManagerOptions) { + } export function stopBot(bot: Bot) { @@ -124,13 +138,16 @@ export type Bot = CreatedBot & { rest: RestManager; gateway: GatewayManager; transformers: Transformers; + // TODO: Support async cache users: Collection; + channels: Collection>; }; export interface Transformers { snowflake: typeof snowflakeToBigint; user: typeof transformUser; member: typeof transformMember; + channel: typeof transformChannel; } export function createTransformers(options: Partial) { @@ -145,4 +162,5 @@ export interface GatewayManager {} export interface EventHandlers { debug: (text: string) => unknown; + channelCreate: (bot: Bot, channel: DiscordenoChannel); } diff --git a/src/handlers/channels/CHANNEL_CREATE.ts b/src/handlers/channels/CHANNEL_CREATE.ts index 679241f19..23934e1fb 100644 --- a/src/handlers/channels/CHANNEL_CREATE.ts +++ b/src/handlers/channels/CHANNEL_CREATE.ts @@ -1,14 +1,12 @@ -import { eventHandlers } from "../../bot.ts"; -import { cacheHandlers } from "../../cache.ts"; -import { structures } from "../../structures/mod.ts"; import type { Channel } from "../../types/channels/channel.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export async function handleChannelCreate(data: DiscordGatewayPayload) { - const payload = data.d as Channel; +import { Bot } from "../../bot.ts"; - const discordenoChannel = await structures.createDiscordenoChannel(payload); - await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel); +export async function handleChannelCreate(bot: Bot, payload: SnakeCasedPropertiesDeep) { + const channel = bot.transformers.channel(bot, payload.d as SnakeCasedPropertiesDeep); + await bot.channels.set(channel.id, channel); - eventHandlers.channelCreate?.(discordenoChannel); + bot.events.channelCreate(bot, channel); }