diff --git a/src/handlers/interactions/INTERACTION_CREATE.ts b/src/handlers/interactions/INTERACTION_CREATE.ts index 510f46a60..78c292cd4 100644 --- a/src/handlers/interactions/INTERACTION_CREATE.ts +++ b/src/handlers/interactions/INTERACTION_CREATE.ts @@ -1,4 +1,3 @@ -// TODO: DM support idk need to discuss how we solve this import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; @@ -8,16 +7,18 @@ import { DiscordInteraction } from "../../types/interactions/interaction.ts"; export async function handleInteractionCreate(data: DiscordGatewayPayload) { const payload = data.d as DiscordInteraction; - const discordenoMember = await structures.createDiscordenoMember( - payload.member as DiscordGuildMemberWithUser, - payload.guild_id ?? "", - ); - await cacheHandlers.set("members", discordenoMember.id, discordenoMember); + const discordenoMember = payload.guild_id + ? await structures.createDiscordenoMember( + payload.member as DiscordGuildMemberWithUser, + payload.guild_id, + ) + : undefined; + if (discordenoMember) { + await cacheHandlers.set("members", discordenoMember.id, discordenoMember); + eventHandlers.interactionGuildCreate?.(payload, discordenoMember); + } else { + eventHandlers.interactionDMCreate?.(payload); + } - eventHandlers.interactionCreate?.( - { - ...payload, - member: discordenoMember, - }, - ); + eventHandlers.interactionCreate?.(payload, discordenoMember); } diff --git a/src/types/discordeno/eventHandlers.ts b/src/types/discordeno/eventHandlers.ts index 4933c4e92..f60fda6e2 100644 --- a/src/types/discordeno/eventHandlers.ts +++ b/src/types/discordeno/eventHandlers.ts @@ -121,11 +121,19 @@ export interface EventHandlers { member: DiscordenoMember, oldMember?: DiscordenoMember, ) => unknown; - // TODO: remove this? - //heartbeat?: () => unknown; - /** Sent when a user in a guild uses a Slash Command. */ + /** Sent when a user uses a Slash Command. */ interactionCreate?: ( - data: Omit & { member: DiscordenoMember }, + data: Omit, + member?: DiscordenoMember, + ) => unknown; + /** Sent when a user uses a Slash Command in a guild. */ + interactionGuildCreate?: ( + data: Omit, + member: DiscordenoMember, + ) => unknown; + /** Sent when a user uses a Slash Command in a dm. */ + interactionDMCreate?: ( + data: Omit, ) => unknown; /** Sent when a message is created. */ messageCreate?: (message: DiscordenoMessage) => unknown; diff --git a/src/ws/tell_cluster_to_identify.ts b/src/ws/tell_cluster_to_identify.ts index d1c4e25e7..ec212fcc7 100644 --- a/src/ws/tell_cluster_to_identify.ts +++ b/src/ws/tell_cluster_to_identify.ts @@ -8,7 +8,6 @@ export async function tellClusterToIdentify( ) { // When resharding this may exist already const oldShard = ws.shards.get(shardId); - // TODO: Use workers await ws.identify(shardId, ws.maxShards); if (oldShard) { diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts index 275fb8d6d..02c952fb4 100644 --- a/tests/channels/create_channel.ts +++ b/tests/channels/create_channel.ts @@ -173,5 +173,3 @@ Deno.test({ // TODO: Need to validate tests for these options // /** Sorting position of the channel */ // position?: number; -// /** The channel's permission overwrites */ -// permissionOverwrites?: Overwrite[]; diff --git a/tests/ws/start_bot.ts b/tests/ws/start_bot.ts index 1790f81e7..d0e77c55a 100644 --- a/tests/ws/start_bot.ts +++ b/tests/ws/start_bot.ts @@ -58,237 +58,3 @@ Deno.test({ }, ...defaultTestOptions, }); - -// // Role - -// Deno.test({ -// name: "[role] create a role in a guild", -// async fn() { -// if (!tempData.guildId) { -// throw new Error("guildId not present in temporary data"); -// } - -// const name = "Discordeno Test"; -// const role = await createRole(tempData.guildId, { -// name, -// }); - -// // Assertions -// assertExists(role); -// assertEquals(role.name, name); - -// tempData.roleId = role.id; -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[role] edit a role in a guild", -// async fn() { -// const name = "Discordeno Test Edited"; -// const color = 4320244; -// const role = await editRole(tempData.guildId, tempData.roleId, { -// name, -// color, -// hoist: false, -// mentionable: false, -// }) as Role; - -// // Assertions -// assertExists(role); -// assertEquals(role.name, name); -// assertEquals(role.color, color); -// assertEquals(role.hoist, false); -// assertEquals(role.mentionable, false); - -// tempData.roleId = role.id; -// }, -// ...defaultTestOptions, -// }); - -// // Channel - -// Deno.test({ -// name: "[channel] create a channel in a guild", -// async fn() { -// const channel = await createChannel(tempData.guildId, "test"); - -// // Assertions -// assertExists(channel); - -// tempData.channelId = channel.id; -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[channel] get a channel in a guild", -// async fn() { -// const channel = await getChannel(tempData.channelId); - -// // Assertions -// assertExists(channel); -// assertEquals(channel.id, tempData.channelId); -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[channel] edit a channel in a guild", -// async fn() { -// const channel = await editChannel(tempData.channelId, { -// name: "discordeno-test-edited", -// overwrites: [ -// { -// id: tempData.roleId, -// type: OverwriteType.ROLE, -// allow: ["VIEW_CHANNEL", "SEND_MESSAGES"], -// deny: ["USE_EXTERNAL_EMOJIS"], -// }, -// ], -// }) as Channel; - -// // Wait 5s for CHANNEL_UPDATE to fire -// await delay(3000); - -// // Assertions -// assertExists(channel); -// assertEquals(channel.name, "discordeno-test-edited"); -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[channel] channel overwrite has permission", -// fn() { -// const channel = cache.channels.get(tempData.channelId); -// if (!channel) throw new Error("Channel not found"); -// if (!channel.permissionOverwrites) { -// throw new Error("permissionOverwrites not found"); -// } - -// const hasPerm = channelOverwriteHasPermission( -// tempData.guildId, -// tempData.roleId, -// channel.permissionOverwrites, -// ["VIEW_CHANNEL", "SEND_MESSAGES"], -// ); -// const missingPerm = channelOverwriteHasPermission( -// tempData.guildId, -// tempData.roleId, -// channel.permissionOverwrites, -// ["USE_EXTERNAL_EMOJIS"], -// ); - -// assertEquals(hasPerm, true); -// assertEquals(missingPerm, false); -// }, -// ...defaultTestOptions, -// }); - -// // Message - -// Deno.test({ -// name: "[message] send a message in a text channel", -// async fn() { -// const message = await sendMessage(tempData.channelId, { -// embed: { -// title: "Discordeno Test", -// }, -// }); - -// // Assertions -// assertExists(message); -// assertEquals(message.embeds[0].title, "Discordeno Test"); - -// tempData.messageId = message.id; -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[message] get a message in a guild", -// async fn() { -// const message = await getMessage(tempData.channelId, tempData.messageId); - -// // Assertions -// assertExists(message); -// assertEquals(message.embeds[0].title, "Discordeno Test"); -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[message] pin a message in a channel", -// async fn() { -// await pinMessage(tempData.channelId, tempData.messageId); -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[message] get pinned message in a channel", -// async fn() { -// const [msg] = await getPins(tempData.channelId); - -// // Assertions -// assertExists(msg); -// assertEquals(msg.id, tempData.messageId); -// assertEquals(msg.pinned, true); -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[message] unpin a message", -// async fn() { -// await unpinMessage(tempData.channelId, tempData.messageId); -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[message] add a reaction to a message", -// async fn() { -// // TODO: add tests for a guild emoji ― <:name:id> - -// await addReaction(tempData.channelId, tempData.messageId, "👍"); -// }, -// ...defaultTestOptions, -// }); - -// // TODO(ayntee): add unit tests for getReactions() - -// Deno.test({ -// name: "[message] remove a reaction to a message", -// async fn() { -// await removeReaction(tempData.channelId, tempData.messageId, "👍"); -// }, -// ...defaultTestOptions, -// }); - -// // Cleanup - -// Deno.test({ -// name: "[message] delete a message by channel Id", -// async fn() { -// await deleteMessage(tempData.channelId, tempData.messageId); -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[channel] delete a channel in a guild", -// async fn() { -// await deleteChannel(tempData.guildId, tempData.channelId); -// }, -// ...defaultTestOptions, -// }); - -// Deno.test({ -// name: "[role] delete a role in a guild", -// async fn() { -// await deleteRole(tempData.guildId, tempData.roleId); -// }, -// ...defaultTestOptions, -// });