From 817e37c4e4d34ec6d2f34bbfcc5bd84cdc88a0a9 Mon Sep 17 00:00:00 2001 From: "Jaron (aider)" Date: Sat, 15 Feb 2025 11:59:15 -0600 Subject: [PATCH] feat: Add channel hydration support for Message and Context objects --- src/services/hydrator.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/services/hydrator.ts b/src/services/hydrator.ts index 479ef81..37d9781 100644 --- a/src/services/hydrator.ts +++ b/src/services/hydrator.ts @@ -1,11 +1,12 @@ import { Expectation } from "../types/common"; import { Context, type HydratedContext } from "../types/context"; import { Message, type HydratedMessage } from "../types/message"; +import { Channel } from "../types/channel"; import { exists } from "../utils"; import type { API } from "./api"; import type { Client } from "./client"; -export type GatewayObject = Message; +export type GatewayObject = Message | Channel; export type Hydrateable = Context | GatewayObject export type Hydrated> = T extends Message ? HydratedMessage : @@ -44,6 +45,9 @@ export async function hydrate, K exte } else if (expectation === Expectation.Guild && exists(data.guild_id)) { let context = data as unknown as HydratedContext<[Expectation.Guild, ...Expectation[]]>; context.guild = await client.guilds.get(data.guild_id); + } else if (expectation === Expectation.Channel && exists(data.channel_id)) { + let context = data as unknown as HydratedContext<[Expectation.Channel, ...Expectation[]]>; + context.channel = await client.channels.get(data.channel_id); } else { throw new Error(`Invalid expectation requested for Context: ${expectation}`); } @@ -56,6 +60,9 @@ export async function hydrate, K exte } else if (expectation === Expectation.Guild && exists(data.guild_id)) { let message = data as unknown as HydratedMessage<[Expectation.Guild, ...Expectation[]]>; message.guild = await client.guilds.get(data.guild_id); + } else if (expectation === Expectation.Channel && exists(data.channel_id)) { + let message = data as unknown as HydratedMessage<[Expectation.Channel, ...Expectation[]]>; + message.channel = await client.channels.get(data.channel_id); } else { throw new Error(`Invalid expectation requested for Message: ${expectation}`); } @@ -98,4 +105,4 @@ export async function hydrator, K ext return function (data: unknown): data is T extends Hydrated ? Hydrated : Hydrated { return hydrated; } -} \ No newline at end of file +}