working on interactions

This commit is contained in:
Yuzu 2022-06-30 10:31:02 -05:00
parent b4d5c236d8
commit b87c0716cc
2 changed files with 88 additions and 0 deletions

41
structures/Component.ts Normal file
View File

@ -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;

47
structures/Interaction.ts Normal file
View File

@ -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;