From e13a3f2daa25f9d43a06981c47d9cc016e48ebf6 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sun, 24 Oct 2021 20:05:13 +0000 Subject: [PATCH] fix errors --- src/bot.ts | 20 +++++++++---------- src/handlers/channels/CHANNEL_CREATE.ts | 2 +- src/handlers/channels/CHANNEL_DELETE.ts | 2 +- src/handlers/channels/CHANNEL_PINS_UPDATE.ts | 2 +- src/handlers/channels/CHANNEL_UPDATE.ts | 2 +- .../channels/STAGE_INSTANCE_CREATE.ts | 2 +- .../channels/STAGE_INSTANCE_DELETE.ts | 2 +- .../channels/STAGE_INSTANCE_UPDATE.ts | 2 +- src/handlers/channels/THREAD_CREATE.ts | 14 +++++-------- src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts | 2 +- src/handlers/guilds/GUILD_BAN_ADD.ts | 2 +- src/handlers/guilds/GUILD_BAN_REMOVE.ts | 2 +- src/handlers/guilds/GUILD_CREATE.ts | 2 +- src/handlers/guilds/GUILD_DELETE.ts | 6 +++--- src/handlers/guilds/GUILD_LOADED_DD.ts | 2 +- 15 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 3f937b651..1d462614f 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -57,7 +57,7 @@ import { USER_AGENT, } from "./util/constants.ts"; import { Errors } from "./types/discordeno/errors.ts"; -import { GatewayDispatchEventNames, GatewayPayload } from "./types/gateway/gateway_payload.ts"; +import { DiscordGatewayPayload, GatewayDispatchEventNames, GatewayPayload } from "./types/gateway/gateway_payload.ts"; import { closeWS, handleOnMessage, @@ -663,7 +663,7 @@ export function createGatewayManager(options: Partial): GatewayM resume, handleDiscordPayload: options.handleDiscordPayload || - async function (_, data: GatewayPayload, shardId: number) { + async function (_, data: DiscordGatewayPayload, shardId: number) { // TRIGGER RAW EVENT bot.events.raw(bot as Bot, data, shardId); @@ -671,7 +671,7 @@ export function createGatewayManager(options: Partial): GatewayM // RUN DISPATCH CHECK await bot.events.dispatchRequirements(bot as Bot, data, shardId); - bot.handlers[data.t as GatewayDispatchEventNames]?.(bot, data, shardId); + bot.handlers[data.t as GatewayDispatchEventNames]?.(bot as Bot, data, shardId); }, }; } @@ -1369,7 +1369,7 @@ export interface BotGatewayHandlerOptions { INTEGRATION_DELETE: typeof handleIntegrationDelete; } -export function createBotGatewayHandlers(options: Partial) { +export function createBotGatewayHandlers(options: Partial): Record any> { return { // misc READY: options.READY ?? handleReady, @@ -1378,12 +1378,12 @@ export function createBotGatewayHandlers(options: Partial) { +export async function handleChannelCreate(bot: Bot, payload: DiscordGatewayPayload) { const channel = bot.transformers.channel(bot, { channel: payload.d as SnakeCasedPropertiesDeep }); await bot.cache.channels.set(channel.id, channel); diff --git a/src/handlers/channels/CHANNEL_DELETE.ts b/src/handlers/channels/CHANNEL_DELETE.ts index 57be9c909..1258c5df3 100644 --- a/src/handlers/channels/CHANNEL_DELETE.ts +++ b/src/handlers/channels/CHANNEL_DELETE.ts @@ -4,7 +4,7 @@ import type { Bot } from "../../bot.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export async function handleChannelDelete(bot: Bot, data: SnakeCasedPropertiesDeep) { +export async function handleChannelDelete(bot: Bot, data: DiscordGatewayPayload) { const payload = data.d as SnakeCasedPropertiesDeep; if (!payload.guild_id) return; diff --git a/src/handlers/channels/CHANNEL_PINS_UPDATE.ts b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts index 121da7060..8ee62c07e 100644 --- a/src/handlers/channels/CHANNEL_PINS_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts @@ -3,7 +3,7 @@ import type { ChannelPinsUpdate } from "../../types/channels/channel_pins_update import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export async function handleChannelPinsUpdate(bot: Bot, data: SnakeCasedPropertiesDeep) { +export async function handleChannelPinsUpdate(bot: Bot, data: DiscordGatewayPayload) { const payload = data.d as SnakeCasedPropertiesDeep; bot.events.channelPinsUpdate(bot, { diff --git a/src/handlers/channels/CHANNEL_UPDATE.ts b/src/handlers/channels/CHANNEL_UPDATE.ts index f7e7af816..a17e03776 100644 --- a/src/handlers/channels/CHANNEL_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_UPDATE.ts @@ -3,7 +3,7 @@ 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 handleChannelUpdate(bot: Bot, data: SnakeCasedPropertiesDeep) { +export async function handleChannelUpdate(bot: Bot, data: DiscordGatewayPayload) { const payload = data.d as SnakeCasedPropertiesDeep; const cachedChannel = await bot.cache.channels.get(bot.transformers.snowflake(payload.id)); diff --git a/src/handlers/channels/STAGE_INSTANCE_CREATE.ts b/src/handlers/channels/STAGE_INSTANCE_CREATE.ts index 25e812560..519d97047 100644 --- a/src/handlers/channels/STAGE_INSTANCE_CREATE.ts +++ b/src/handlers/channels/STAGE_INSTANCE_CREATE.ts @@ -3,7 +3,7 @@ import type { StageInstance } from "../../types/channels/stage_instance.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export function handleStageInstanceCreate(bot: Bot, data: SnakeCasedPropertiesDeep) { +export function handleStageInstanceCreate(bot: Bot, data: DiscordGatewayPayload) { const payload = data.d as SnakeCasedPropertiesDeep; bot.events.stageInstanceCreate(bot, { diff --git a/src/handlers/channels/STAGE_INSTANCE_DELETE.ts b/src/handlers/channels/STAGE_INSTANCE_DELETE.ts index e40668923..64ea6d2be 100644 --- a/src/handlers/channels/STAGE_INSTANCE_DELETE.ts +++ b/src/handlers/channels/STAGE_INSTANCE_DELETE.ts @@ -3,7 +3,7 @@ import type { StageInstance } from "../../types/channels/stage_instance.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export function handleStageInstanceDelete(bot: Bot, data: SnakeCasedPropertiesDeep) { +export function handleStageInstanceDelete(bot: Bot, data: DiscordGatewayPayload) { const payload = data.d as SnakeCasedPropertiesDeep; bot.events.stageInstanceDelete(bot, { diff --git a/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts b/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts index 5b497edea..e30ff830d 100644 --- a/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts +++ b/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts @@ -3,7 +3,7 @@ import type { StageInstance } from "../../types/channels/stage_instance.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export function handleStageInstanceUpdate(bot: Bot, data: SnakeCasedPropertiesDeep) { +export function handleStageInstanceUpdate(bot: Bot, data: DiscordGatewayPayload) { const payload = data.d as SnakeCasedPropertiesDeep; bot.events.stageInstanceUpdate(bot, { diff --git a/src/handlers/channels/THREAD_CREATE.ts b/src/handlers/channels/THREAD_CREATE.ts index 7c6c26a70..94bb873e8 100644 --- a/src/handlers/channels/THREAD_CREATE.ts +++ b/src/handlers/channels/THREAD_CREATE.ts @@ -1,14 +1,10 @@ -import { eventHandlers } from "../../bot.ts"; -import { cacheHandlers } from "../../cache.ts"; +import { Bot } from "../../bot.ts"; import { Channel } from "../../types/channels/channel.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { channelToThread } from "../../util/transformers/channel_to_thread.ts"; +import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export async function handleThreadCreate(data: DiscordGatewayPayload) { - const payload = data.d as Channel; +export async function handleThreadCreate(bot: Bot, data: DiscordGatewayPayload) { + const payload = data.d as SnakeCasedPropertiesDeep; - const thread = channelToThread(payload); - await cacheHandlers.set("threads", thread.id, thread); - - eventHandlers.threadCreate?.(thread); + // bot.events.threadCreate(bot, payload); } diff --git a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts index fbc82f69c..48640cf4f 100644 --- a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts +++ b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts @@ -4,7 +4,7 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload. import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { Collection } from "../../util/collection.ts"; -export async function handleGuildEmojisUpdate(bot: Bot, data: SnakeCasedPropertiesDeep) { +export async function handleGuildEmojisUpdate(bot: Bot, data: DiscordGatewayPayload) { const payload = data.d as SnakeCasedPropertiesDeep; const guild = await bot.cache.guilds.get(bot.transformers.snowflake(payload.guild_id)); if (!guild) return; diff --git a/src/handlers/guilds/GUILD_BAN_ADD.ts b/src/handlers/guilds/GUILD_BAN_ADD.ts index 8b1b4ffc4..0ebabfaac 100644 --- a/src/handlers/guilds/GUILD_BAN_ADD.ts +++ b/src/handlers/guilds/GUILD_BAN_ADD.ts @@ -3,7 +3,7 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload. import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export async function handleGuildBanAdd(bot: Bot, data: SnakeCasedPropertiesDeep) { +export async function handleGuildBanAdd(bot: Bot, data: DiscordGatewayPayload) { const payload = data.d as SnakeCasedPropertiesDeep; // FIRST COMPLETE THE END USERS EVENT await bot.events.guildBanAdd( diff --git a/src/handlers/guilds/GUILD_BAN_REMOVE.ts b/src/handlers/guilds/GUILD_BAN_REMOVE.ts index a3f9a9057..45c7d1b74 100644 --- a/src/handlers/guilds/GUILD_BAN_REMOVE.ts +++ b/src/handlers/guilds/GUILD_BAN_REMOVE.ts @@ -3,7 +3,7 @@ import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload. import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export async function handleGuildBanRemove(bot: Bot, data: SnakeCasedPropertiesDeep) { +export async function handleGuildBanRemove(bot: Bot, data: DiscordGatewayPayload) { const payload = data.d as SnakeCasedPropertiesDeep; await bot.events.guildBanRemove( diff --git a/src/handlers/guilds/GUILD_CREATE.ts b/src/handlers/guilds/GUILD_CREATE.ts index de7deb3f4..dacdd8529 100644 --- a/src/handlers/guilds/GUILD_CREATE.ts +++ b/src/handlers/guilds/GUILD_CREATE.ts @@ -5,7 +5,7 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; export async function handleGuildCreate( bot: Bot, - data: SnakeCasedPropertiesDeep, + data: DiscordGatewayPayload, shardId: number ) { const payload = data.d as SnakeCasedPropertiesDeep; diff --git a/src/handlers/guilds/GUILD_DELETE.ts b/src/handlers/guilds/GUILD_DELETE.ts index 91f64641f..d1ac5573b 100644 --- a/src/handlers/guilds/GUILD_DELETE.ts +++ b/src/handlers/guilds/GUILD_DELETE.ts @@ -14,8 +14,8 @@ export async function handleGuildDelete(bot: Bot, data: DiscordGatewayPayload, s await bot.cache.guilds.delete(id); await Promise.all([ - bot.cache.forEach("DELETE_MESSAGES_FROM_GUILD", { guildId: guild.id }), - bot.cache.forEach("DELETE_CHANNELS_FROM_GUILD", { guildId: guild.id }), - bot.cache.forEach("DELETE_GUILD_FROM_MEMBER", { guildId: guild.id }), + bot.cache.execute("DELETE_MESSAGES_FROM_GUILD", { guildId: guild.id }), + bot.cache.execute("DELETE_CHANNELS_FROM_GUILD", { guildId: guild.id }), + bot.cache.execute("DELETE_GUILD_FROM_MEMBER", { guildId: guild.id }), ]); } diff --git a/src/handlers/guilds/GUILD_LOADED_DD.ts b/src/handlers/guilds/GUILD_LOADED_DD.ts index a2c99dc73..20a3fd542 100644 --- a/src/handlers/guilds/GUILD_LOADED_DD.ts +++ b/src/handlers/guilds/GUILD_LOADED_DD.ts @@ -5,7 +5,7 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; export async function handleGuildLoaded( bot: Bot, - data: SnakeCasedPropertiesDeep, + data: DiscordGatewayPayload, shardId: number ) { const payload = data.d as SnakeCasedPropertiesDeep;