channel create handler

This commit is contained in:
Skillz4Killz
2021-10-09 17:07:55 +00:00
committed by GitHub
parent c9d1a15615
commit 8ddd16c61e
2 changed files with 24 additions and 8 deletions

View File

@@ -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<Transformers>;
}
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<bigint, DiscordenoUser>;
channels: Collection<bigint, SnakeCasedPropertiesDeep<Channel>>;
};
export interface Transformers {
snowflake: typeof snowflakeToBigint;
user: typeof transformUser;
member: typeof transformMember;
channel: typeof transformChannel;
}
export function createTransformers(options: Partial<Transformers>) {
@@ -145,4 +162,5 @@ export interface GatewayManager {}
export interface EventHandlers {
debug: (text: string) => unknown;
channelCreate: (bot: Bot, channel: DiscordenoChannel);
}

View File

@@ -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<DiscordGatewayPayload>) {
const channel = bot.transformers.channel(bot, payload.d as SnakeCasedPropertiesDeep<Channel>);
await bot.channels.set(channel.id, channel);
eventHandlers.channelCreate?.(discordenoChannel);
bot.events.channelCreate(bot, channel);
}