diff --git a/structures/Component.ts b/structures/Component.ts new file mode 100644 index 0000000..4999b8c --- /dev/null +++ b/structures/Component.ts @@ -0,0 +1,41 @@ +import type { Session } from "../session/Session.ts"; +import type { DiscordComponent, MessageComponentTypes } from "../vendor/external.ts"; +import Emoji from "./Emoji.ts"; + +export class Component { + constructor(session: Session, data: DiscordComponent) { + this.session = session; + this.customId = data.custom_id; + this.type = data.type + this.components = data.components?.map((component) => new Component(session, component)); + this.disabled = !!data.disabled; + + if (data.emoji) { + this.emoji = new Emoji(session, data.emoji); + } + + this.maxValues = data.max_values; + this.minValues = data.min_values; + this.label = data.label; + this.value = data.value; + this.options = data.options ?? []; + this.placeholder = data.placeholder; + } + + readonly session: Session; + + customId?: string; + type: MessageComponentTypes; + components?: Component[]; + disabled: boolean; + emoji?: Emoji; + maxValues?: number; + minValues?: number; + label?: string; + value?: string; + // deno-lint-ignore no-explicit-any + options: any[]; + placeholder?: string; +} + +export default Component; diff --git a/structures/Interaction.ts b/structures/Interaction.ts new file mode 100644 index 0000000..d120f93 --- /dev/null +++ b/structures/Interaction.ts @@ -0,0 +1,47 @@ +import type { Model } from "./Base.ts"; +import type { Snowflake } from "../util/Snowflake.ts"; +import type { Session } from "../session/Session.ts"; +import type { DiscordInteraction, InteractionTypes } from "../vendor/external.ts"; +import User from "./User.ts"; +// import Member from "./Member.ts"; + +export class Interaction implements Model { + constructor(session: Session, data: DiscordInteraction) { + this.session = session; + this.id = data.id; + this.token = data.token; + this.type = data.type + this.guildId = data.guild_id; + this.channelId = data.channel_id; + this.applicationId = data.application_id; + this.locale = data.locale; + this.data = data.data; + + if (!data.guild_id) { + this.user = new User(session, data.user!); + } + else { + // TODO: member transformer + // pass + } + } + + readonly session: Session; + readonly id: Snowflake; + readonly token: string; + + type: InteractionTypes; + guildId?: Snowflake; + channelId?: Snowflake; + applicationId?: Snowflake; + locale?: string; + // deno-lint-ignore no-explicit-any + data: any; + user?: User; + + // TODO: do methods + async respond() { + } +} + +export default Interaction;