diff --git a/structures/client/handleEvents.js b/structures/client/handleEvents.js index bd933b7..6d59b16 100644 --- a/structures/client/handleEvents.js +++ b/structures/client/handleEvents.js @@ -1,7 +1,7 @@ import gateWayEvents from '../gateway/dispatch.js' import { message } from '../messages/message.js'; -import {Interaction} from '../interactions/interaction.js'; import Guild from '../guilds/Guild.js'; +import { createInteraction } from '../interactions/createInteraction.js'; /** @@ -28,7 +28,7 @@ export default async function handleEvents(msgObj, token, client) { break; case gateWayEvents.InteractionCreate: - resolve({op: op, t: t, interaction: new Interaction(msgObj["d"], client)}); + resolve({op: op, t: t, interaction: createInteraction(msgObj["d"], client)}); //interaction: new Interaction(msgObj["d"], client) break; case gateWayEvents.GuildCreate: diff --git a/structures/interactions/StringSelectMenu.js b/structures/interactions/MessageSelectMenu.js similarity index 100% rename from structures/interactions/StringSelectMenu.js rename to structures/interactions/MessageSelectMenu.js diff --git a/structures/interactions/Modal.js b/structures/interactions/Modal.js new file mode 100644 index 0000000..27bbacc --- /dev/null +++ b/structures/interactions/Modal.js @@ -0,0 +1,9 @@ +import { Interaction } from "./interaction.js"; + + +export class Modal extends Interaction { + constructor(intRaw, client) { + super(intRaw, client); + console.log(intRaw); + } +} \ No newline at end of file diff --git a/structures/interactions/createInteraction.js b/structures/interactions/createInteraction.js new file mode 100644 index 0000000..766d425 --- /dev/null +++ b/structures/interactions/createInteraction.js @@ -0,0 +1,28 @@ +import { Modal } from "./Modal.js"; +import { Interaction } from "./interaction.js"; +import { interactionTypes } from "./interactionTypes.js"; + + +function selectMenuTypes(inp) { + +} + +export function createInteraction(intRaw, client) { + switch (intRaw.type) { + case interactionTypes.ApplicationCommand: + return new Interaction(intRaw, client); + + case interactionTypes.MessageComponent: + console.log(intRaw.message.components); + return null; + + case interactionTypes.ModalSubmit: + return new Modal(intRaw, client); + + case interactionTypes.Ping: + console.log("pong"); + return null; + + default: console.log(`UNKNOWN INTERACTION:\n`, intRaw); + } +} \ No newline at end of file diff --git a/structures/interactions/interaction.js b/structures/interactions/interaction.js index 6b11f54..caf94de 100644 --- a/structures/interactions/interaction.js +++ b/structures/interactions/interaction.js @@ -21,6 +21,7 @@ class interactionOptions { focused; constructor(o) { + console.log(o); for (const k in this) { if (o[k]) this[k] = o[k]; } diff --git a/structures/interactions/interactionTypes.js b/structures/interactions/interactionTypes.js new file mode 100644 index 0000000..a36911c --- /dev/null +++ b/structures/interactions/interactionTypes.js @@ -0,0 +1,8 @@ +export const interactionTypes = Object.freeze({ + Ping: 1, + ApplicationCommand: 2, + MessageComponent: 3, + ApplicationCommandAutocomplete: 4, + ModalSubmit: 5 +}); + diff --git a/tests/Buttontests.js b/tests/Buttontests.js index e32dc94..72d9967 100644 --- a/tests/Buttontests.js +++ b/tests/Buttontests.js @@ -3,7 +3,7 @@ import { Channel } from "../structures/guilds/Channel.js"; import { message } from "../structures/messages/message.js"; import { MessageButtonStyles } from "../structures/interactions/ButtonStyles.js"; import { MessageActionRow } from "../structures/messages/MessageActionRow.js"; -import { ChannelSelectMenu, StringMenuComponent, StringSelectMenu } from "../structures/interactions/StringSelectMenu.js"; +import { ChannelSelectMenu, StringMenuComponent, StringSelectMenu, userSelectMenu } from "../structures/interactions/MessageSelectMenu.js"; /** * @param {message} mog @@ -21,10 +21,14 @@ export async function buttonTests(mog) { comp2.label = 'llllll'; c.options.push(comp2); c.custom_id = "temp"; + + const comp3 = new userSelectMenu(); + comp3.custom_id = "userMenu"; const row = new MessageActionRow(); // row.addComponent(comp); - row.addComponent(c); + // row.addComponent(c); + row.addComponent(comp3); m.addComponents(row); m.content = "OOGA BOOGA"; diff --git a/tests/interactionTests.js b/tests/interactionTests.js index ae5941d..365331f 100644 --- a/tests/interactionTests.js +++ b/tests/interactionTests.js @@ -1,14 +1,19 @@ +import { interactionTypes } from '../structures/interactions/interactionTypes.js'; import { Interaction } from '../structures/types.js'; const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); /** @param {Interaction} interaction */ export default async (interaction) => { - console.log(interaction.data); - interaction.reply({content: "HELLO WORLD", ephemeral: true}); - await delay(3000); - interaction.update({content: "NOOOOOOOOOOOOOOOOOO"}); - await delay(2000); - const response = await interaction.followUp("followup!"); - await delay(2000); - response.delete(); + if (interaction.type == interactionTypes.ApplicationCommand) { + console.log(interaction.data); + interaction.reply({content: "HELLO WORLD", ephemeral: true}); + await delay(3000); + interaction.update({content: "NOOOOOOOOOOOOOOOOOO"}); + await delay(2000); + const response = await interaction.followUp("followup!"); + await delay(2000); + response.delete(); + } else { + console.log(interaction); + } } \ No newline at end of file