fix errors

This commit is contained in:
Skillz4Killz
2021-10-24 20:05:13 +00:00
committed by GitHub
parent 2427a5d2c8
commit e13a3f2daa
15 changed files with 30 additions and 34 deletions

View File

@@ -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<GatewayManager>): 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<GatewayManager>): 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<BotGatewayHandlerOptions>) {
export function createBotGatewayHandlers(options: Partial<BotGatewayHandlerOptions>): Record<GatewayDispatchEventNames | "GUILD_LOADED_DD", (bot: Bot, data: GatewayPayload, shardId: number) => any> {
return {
// misc
READY: options.READY ?? handleReady,
@@ -1378,12 +1378,12 @@ export function createBotGatewayHandlers(options: Partial<BotGatewayHandlerOptio
CHANNEL_DELETE: options.CHANNEL_DELETE ?? handleChannelDelete,
CHANNEL_PINS_UPDATE: options.CHANNEL_PINS_UPDATE ?? handleChannelPinsUpdate,
CHANNEL_UPDATE: options.CHANNEL_UPDATE ?? handleChannelUpdate,
THREAD_CREATE: options.THREAD_CREATE ?? handleThreadCreate,
THREAD_UPDATE: options.THREAD_UPDATE ?? handleThreadUpdate,
THREAD_DELETE: options.THREAD_DELETE ?? handleThreadDelete,
THREAD_LIST_SYNC: options.THREAD_LIST_SYNC ?? handleThreadListSync,
THREAD_MEMBER_UPDATE: options.THREAD_MEMBER_UPDATE ?? handleThreadMemberUpdate,
THREAD_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handleThreadMembersUpdate,
// THREAD_CREATE: options.THREAD_CREATE ?? handleThreadCreate,
// THREAD_UPDATE: options.THREAD_UPDATE ?? handleThreadUpdate,
// THREAD_DELETE: options.THREAD_DELETE ?? handleThreadDelete,
// THREAD_LIST_SYNC: options.THREAD_LIST_SYNC ?? handleThreadListSync,
// THREAD_MEMBER_UPDATE: options.THREAD_MEMBER_UPDATE ?? handleThreadMemberUpdate,
// THREAD_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handleThreadMembersUpdate,
STAGE_INSTANCE_CREATE: options.STAGE_INSTANCE_CREATE ?? handleStageInstanceCreate,
STAGE_INSTANCE_UPDATE: options.STAGE_INSTANCE_UPDATE ?? handleStageInstanceUpdate,
STAGE_INSTANCE_DELETE: options.STAGE_INSTANCE_DELETE ?? handleStageInstanceDelete,

View File

@@ -4,7 +4,7 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
import type { Bot } from "../../bot.ts";
export async function handleChannelCreate(bot: Bot, payload: SnakeCasedPropertiesDeep<DiscordGatewayPayload>) {
export async function handleChannelCreate(bot: Bot, payload: DiscordGatewayPayload) {
const channel = bot.transformers.channel(bot, { channel: payload.d as SnakeCasedPropertiesDeep<Channel> });
await bot.cache.channels.set(channel.id, channel);

View File

@@ -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<DiscordGatewayPayload>) {
export async function handleChannelDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as SnakeCasedPropertiesDeep<Channel>;
if (!payload.guild_id) return;

View File

@@ -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<DiscordGatewayPayload>) {
export async function handleChannelPinsUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as SnakeCasedPropertiesDeep<ChannelPinsUpdate>;
bot.events.channelPinsUpdate(bot, {

View File

@@ -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<DiscordGatewayPayload>) {
export async function handleChannelUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as SnakeCasedPropertiesDeep<Channel>;
const cachedChannel = await bot.cache.channels.get(bot.transformers.snowflake(payload.id));

View File

@@ -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<DiscordGatewayPayload>) {
export function handleStageInstanceCreate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as SnakeCasedPropertiesDeep<StageInstance>;
bot.events.stageInstanceCreate(bot, {

View File

@@ -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<DiscordGatewayPayload>) {
export function handleStageInstanceDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as SnakeCasedPropertiesDeep<StageInstance>;
bot.events.stageInstanceDelete(bot, {

View File

@@ -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<DiscordGatewayPayload>) {
export function handleStageInstanceUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as SnakeCasedPropertiesDeep<StageInstance>;
bot.events.stageInstanceUpdate(bot, {

View File

@@ -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<Channel>;
const thread = channelToThread(payload);
await cacheHandlers.set("threads", thread.id, thread);
eventHandlers.threadCreate?.(thread);
// bot.events.threadCreate(bot, payload);
}

View File

@@ -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<DiscordGatewayPayload>) {
export async function handleGuildEmojisUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as SnakeCasedPropertiesDeep<GuildEmojisUpdate>;
const guild = await bot.cache.guilds.get(bot.transformers.snowflake(payload.guild_id));
if (!guild) return;

View File

@@ -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<DiscordGatewayPayload>) {
export async function handleGuildBanAdd(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as SnakeCasedPropertiesDeep<GuildBanAddRemove>;
// FIRST COMPLETE THE END USERS EVENT
await bot.events.guildBanAdd(

View File

@@ -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<DiscordGatewayPayload>) {
export async function handleGuildBanRemove(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as SnakeCasedPropertiesDeep<GuildBanAddRemove>;
await bot.events.guildBanRemove(

View File

@@ -5,7 +5,7 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
export async function handleGuildCreate(
bot: Bot,
data: SnakeCasedPropertiesDeep<DiscordGatewayPayload>,
data: DiscordGatewayPayload,
shardId: number
) {
const payload = data.d as SnakeCasedPropertiesDeep<Guild>;

View File

@@ -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 }),
]);
}

View File

@@ -5,7 +5,7 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
export async function handleGuildLoaded(
bot: Bot,
data: SnakeCasedPropertiesDeep<DiscordGatewayPayload>,
data: DiscordGatewayPayload,
shardId: number
) {
const payload = data.d as SnakeCasedPropertiesDeep<Guild>;