Revert "fix: potential fix for #1036"

This reverts commit 69c18b8c4c.
This commit is contained in:
Skillz4Killz
2021-09-12 19:26:13 +00:00
committed by GitHub
parent 69c18b8c4c
commit 3037cb1be5
6 changed files with 15 additions and 68 deletions

View File

@@ -1,6 +1,6 @@
{
"deno.enable": true,
"deno.lint": false,
"deno.lint": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {

View File

@@ -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) {

View File

@@ -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<BigInteraction, "member">];
interactionDMCreate: [data: Omit<Interaction, "member">];
/** Sent when a lurker joins/leaves/moves stage channels. */
lurkerVoiceStateUpdate: [member: DiscordenoMember, voiceState: VoiceState];
/** Sent when a message is created. */

View File

@@ -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<Interaction, "id" | "applicationId" | "guildId" | "channelId" | "member" | "user" | "message"> {
/** 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<InteractionGuildMember, "roles" | "user"> & {
/** Array of role object ids */
roles: bigint[];
/** The user this guild member represents */
user: Omit<User, "id"> & {
/** The user's id */
id: bigint;
};
};
/** User object for the invoking user, if invoked in a DM */
user: Omit<User, "id"> & { id: bigint };
/** For the message the button was attached to */
message?: DiscordenoMessage;
}

View File

@@ -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 = /^(?<id>\d{17,19})$/;

View File

@@ -1,6 +1,10 @@
import { eventHandlers } from "../bot.ts";
export function loopObject<T = {}>(obj: {}, handler: (value: unknown, key: string) => unknown, log: string) {
export function loopObject<T = Record<string, unknown>>(
obj: Record<string, unknown>,
handler: (value: unknown, key: string) => unknown,
log: string
) {
let res: Record<string, unknown> | unknown[] = {};
if (Array.isArray(obj)) {
@@ -9,7 +13,7 @@ export function loopObject<T = {}>(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<string, unknown>, handler, log));
} else {
res.push(handler(o, "array"));
}
@@ -20,7 +24,7 @@ export function loopObject<T = {}>(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<string, unknown>, handler, log);
} else {
res[key] = handler(value, key);
}