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

Commit

Permalink
feat: Merged pagination, embeds and module generation into ui.ts (#35)
Browse files Browse the repository at this point in the history
* feat: Merged pagination, embeds and module generation into ui.ts

* fix: Made main get embed from the file instead of util

---------

Co-authored-by: zleyyij <[email protected]>
  • Loading branch information
Cpt-Dingus and zleyyij authored Sep 9, 2023
1 parent f5348e0 commit 010caba
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 224 deletions.
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

0 comments on commit 010caba

Please sign in to comment.