From 3037cb1be57ea9c85606409b365309eb2641cb4f Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sun, 12 Sep 2021 19:26:13 +0000 Subject: [PATCH] Revert "fix: potential fix for #1036" This reverts commit 69c18b8c4c0f9a7683c3a7ddd4d9eb4bc38d99ab. --- .vscode/settings.json | 2 +- .../interactions/INTERACTION_CREATE.ts | 35 ++----------------- src/types/discordeno/event_handlers.ts | 8 ++--- src/types/interactions/interaction.ts | 27 -------------- src/util/constants.ts | 1 - src/util/loop_object.ts | 10 ++++-- 6 files changed, 15 insertions(+), 68 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 18bff7280..492b7791a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "deno.enable": true, - "deno.lint": false, + "deno.lint": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true, "editor.codeActionsOnSave": { diff --git a/src/handlers/interactions/INTERACTION_CREATE.ts b/src/handlers/interactions/INTERACTION_CREATE.ts index 4188056bd..6d7da483c 100644 --- a/src/handlers/interactions/INTERACTION_CREATE.ts +++ b/src/handlers/interactions/INTERACTION_CREATE.ts @@ -1,44 +1,15 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; -import { createDiscordenoMessage, DiscordenoMessage } from "../../structures/message.ts"; import { structures } from "../../structures/mod.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { BigInteraction, Interaction } from "../../types/interactions/interaction.ts"; +import type { Interaction } from "../../types/interactions/interaction.ts"; import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleInteractionCreate(data: DiscordGatewayPayload) { - const basePayload = data.d as Interaction; - - const payload = { - ...basePayload, - id: snowflakeToBigint(basePayload.id), - applicationId: snowflakeToBigint(basePayload.applicationId), - guildId: basePayload.guildId ? snowflakeToBigint(basePayload.guildId) : undefined, - channelId: basePayload.channelId ? snowflakeToBigint(basePayload.channelId) : undefined, - member: basePayload.member - ? { - ...basePayload.member, - roles: basePayload.member.roles.map((id) => snowflakeToBigint(id)), - user: { - ...basePayload.member.user, - id: snowflakeToBigint(basePayload.member.user.id), - }, - } - : undefined, - user: basePayload.user - ? { - ...basePayload.user, - id: snowflakeToBigint(basePayload.user.id), - } - : undefined, - message: basePayload.message ? createDiscordenoMessage(basePayload.message) : undefined, - } as BigInteraction; - - if (payload.member) payload.user = payload.member.user; - + const payload = data.d as Interaction; const discordenoMember = payload.guildId - ? await structures.createDiscordenoMember(payload.member as GuildMemberWithUser, payload.guildId) + ? await structures.createDiscordenoMember(payload.member as GuildMemberWithUser, snowflakeToBigint(payload.guildId)) : undefined; if (discordenoMember) { diff --git a/src/types/discordeno/event_handlers.ts b/src/types/discordeno/event_handlers.ts index 7834cfc86..3562b1c7b 100644 --- a/src/types/discordeno/event_handlers.ts +++ b/src/types/discordeno/event_handlers.ts @@ -15,7 +15,7 @@ import type { DiscordGatewayPayload } from "../gateway/gateway_payload.ts"; import type { IntegrationCreateUpdate } from "../integrations/integration_create_update.ts"; import type { IntegrationDelete } from "../integrations/integration_delete.ts"; import type { ApplicationCommandCreateUpdateDelete } from "../interactions/commands/application_command_create_update_delete.ts"; -import type { BigInteraction, Interaction } from "../interactions/interaction.ts"; +import type { Interaction } from "../interactions/interaction.ts"; import type { InviteCreate } from "../invites/invite_create.ts"; import type { InviteDelete } from "../invites/invite_delete.ts"; import type { MessageReactionAdd } from "../messages/message_reaction_add.ts"; @@ -82,11 +82,11 @@ export type EventHandlersDefinitions = { /** Sent when a guild member is updated. This will also fire when the user object of a guild member changes. */ guildMemberUpdate: [guild: DiscordenoGuild, member: DiscordenoMember, oldMember?: DiscordenoMember]; /** Sent when a user uses a Slash Command (type 2) or clicks a button (type 3). */ - interactionCreate: [data: BigInteraction, member?: DiscordenoMember]; + interactionCreate: [data: Interaction, member?: DiscordenoMember]; /** Sent when a user uses a Slash Command in a guild (type 2) or clicks a button (type 3). */ - interactionGuildCreate: [data: BigInteraction, member: DiscordenoMember]; + interactionGuildCreate: [data: Interaction, member: DiscordenoMember]; /** Sent when a user uses a Slash Command in a dm (type 2) or clicks a button (type 3). */ - interactionDMCreate: [data: Omit]; + interactionDMCreate: [data: Omit]; /** Sent when a lurker joins/leaves/moves stage channels. */ lurkerVoiceStateUpdate: [member: DiscordenoMember, voiceState: VoiceState]; /** Sent when a message is created. */ diff --git a/src/types/interactions/interaction.ts b/src/types/interactions/interaction.ts index 8e408d2ef..0ef8bafe4 100644 --- a/src/types/interactions/interaction.ts +++ b/src/types/interactions/interaction.ts @@ -5,7 +5,6 @@ import { InteractionGuildMember } from "./interaction_guild_member.ts"; import { DiscordInteractionTypes } from "./interaction_types.ts"; import { SelectMenuData } from "../messages/components/select_data.ts"; import { ButtonData } from "../messages/components/button_data.ts"; -import { DiscordenoMessage } from "../../structures/message.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction */ export type Interaction = PingInteraction | SlashCommandInteraction | ComponentInteraction; @@ -49,29 +48,3 @@ export interface BaseInteraction< data?: D; } - -export interface BigInteraction - extends Omit { - /** Id of the interaction */ - id: bigint; - /** Id of the application this interaction is for */ - applicationId: bigint; - /** The guild it was sent from */ - guildId?: bigint; - /** The channel it was sent from */ - channelId?: bigint; - /** Guild member data for the invoking user, including permissions */ - member?: Omit & { - /** Array of role object ids */ - roles: bigint[]; - /** The user this guild member represents */ - user: Omit & { - /** The user's id */ - id: bigint; - }; - }; - /** User object for the invoking user, if invoked in a DM */ - user: Omit & { id: bigint }; - /** For the message the button was attached to */ - message?: DiscordenoMessage; -} diff --git a/src/util/constants.ts b/src/util/constants.ts index 8305e79de..4f4c69794 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -170,4 +170,3 @@ export const endpoints = { export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/; export const CONTEXT_MENU_COMMANDS_NAME_REGEX = /^[\w-\s]{1,32}$/; export const CHANNEL_MENTION_REGEX = /<#[0-9]+>/g; -export const DISCORD_SNOWFLAKE_REGEX = /^(?\d{17,19})$/; diff --git a/src/util/loop_object.ts b/src/util/loop_object.ts index c3d45c004..e91ddcbf7 100644 --- a/src/util/loop_object.ts +++ b/src/util/loop_object.ts @@ -1,6 +1,10 @@ import { eventHandlers } from "../bot.ts"; -export function loopObject(obj: {}, handler: (value: unknown, key: string) => unknown, log: string) { +export function loopObject>( + obj: Record, + handler: (value: unknown, key: string) => unknown, + log: string +) { let res: Record | unknown[] = {}; if (Array.isArray(obj)) { @@ -9,7 +13,7 @@ export function loopObject(obj: {}, handler: (value: unknown, key: strin for (const o of obj) { if (typeof o === "object" && !Array.isArray(o) && o !== null) { // A nested object - res.push(loopObject(o as {}, handler, log)); + res.push(loopObject(o as Record, handler, log)); } else { res.push(handler(o, "array")); } @@ -20,7 +24,7 @@ export function loopObject(obj: {}, handler: (value: unknown, key: strin if (typeof value === "object" && !Array.isArray(value) && value !== null && !(value instanceof Blob)) { // A nested object - res[key] = loopObject(value as {}, handler, log); + res[key] = loopObject(value as Record, handler, log); } else { res[key] = handler(value, key); }