Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

feat: Merged pagination, embeds and module generation into ui.ts #35

Merged
merged 3 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 0 additions & 149 deletions src/core/embed.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/core/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {DependencyStatus, RootModule, SubModule, modules} from './modules.js';
import {client} from './api.js';
import path from 'path';
import {fileURLToPath} from 'url';
import {embed} from './embed.js';
import {embed} from './ui.js';
import {
generateSlashCommandForModule,
registerSlashCommandSet,
Expand Down
63 changes: 0 additions & 63 deletions src/core/slash_commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ import {
BaseMessageOptions,
Message,
InteractionResponse,
TextInputBuilder,
ModalBuilder,
TextInputStyle,
ActionRowBuilder,
RestOrArray,
ModalActionRowComponentBuilder,
} from 'discord.js';
import {client} from './api.js';
import {botConfig} from './config.js';
Expand Down Expand Up @@ -337,60 +331,3 @@ export async function replyToInteraction(

return await interaction.reply(payload);
}

/**
* A single input field of a modal
* @param id The ID to refer to the input field as
* @param label The label of the input field
* @param style The style to use (Short or Paragraph)
* @param maxLength The maximum input length
*/
interface inputFieldOptions {
id: string;
label: string;
style: TextInputStyle;
maxLength: number;
}

/**
* The modal generation options
* @param id The ID to refer to the modal as
* @param title The title of the modal
* @param fields An array of inputFieldOptions
*/
interface modalOptions {
id: string;
title: string;
fields: inputFieldOptions[];
}

/**
* Generates a modal from args
* Takes a {@link inputFieldOptions} object as an argument
* @returns The finished modal object
*/
export function generateModal({id, title, fields}: modalOptions): ModalBuilder {
const modal: ModalBuilder = new ModalBuilder()
.setCustomId(id)
.setTitle(title);

const components: RestOrArray<ActionRowBuilder<TextInputBuilder>> = [];

// Adds all components to the modal
for (const field of fields) {
const modalComponent: TextInputBuilder = new TextInputBuilder()
.setCustomId(field.id)
.setLabel(field.label)
.setStyle(field.style)
.setMaxLength(field.maxLength);

const actionRow =
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
modalComponent
);
components.push(actionRow);
}
modal.addComponents(components);

return modal;
}
Loading