Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

modals #327

Merged
merged 11 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ model Config {
antibotFactor Int @map("antibot_factor")
antibotAction String? @map("antibot_action")
currency String?
ticketStaffRole BigInt? @map("ticket_staff_role")

@@map("config")
}
Expand Down
8 changes: 5 additions & 3 deletions src/classes/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from 'node:path';
import process from 'node:process';

import { Logger } from '#classes';
import { CommandHandler, ComponentHandler, CooldownHandler, EventHandler } from '#handlers';
import { CommandHandler, ComponentHandler, CooldownHandler, EventHandler, ModalHandler } from '#handlers';
import { AIModule, CasesModule, EconomyModule, PhishingModule, ShopModule } from '#modules';
import { getDirname } from '#util';

Expand All @@ -21,6 +21,7 @@ export class FluorineClient extends Client {

commands = new CommandHandler(this);
components = new ComponentHandler(this);
modals = new ModalHandler(this);
cooldowns = new CooldownHandler(this);

economy = new EconomyModule(this);
Expand Down Expand Up @@ -51,11 +52,12 @@ export class FluorineClient extends Client {
disableValidators();
}

new EventHandler(this).loadEvents();

this.commands.loadChatInput();
this.commands.loadContextMenu();

this.modals.loadModals();
this.components.loadComponents();
new EventHandler(this).loadEvents();

await this.i18n.use(Backend).init({
fallbackLng: 'en-US',
Expand Down
21 changes: 21 additions & 0 deletions src/classes/handlers/ModalHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { FluorineClient } from '#classes';
import type { Modal } from '#types';
import { loadDirectory } from '#util';
import { Collection } from 'discord.js';

export class ModalHandler extends Collection<string, Modal> {
constructor(private client: FluorineClient) {
super();
}

async loadModals() {
const files = await loadDirectory<Modal>('../modals');

for (const file of files) {
this.set(file.name, file.data);
}

this.client.logger.log(`Loaded ${files.length} modals.`);
return this;
}
}
1 change: 1 addition & 0 deletions src/classes/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './CommandHandler.js';
export * from './ComponentHandler.js';
export * from './CooldownHandler.js';
export * from './EventHandler.js';
export * from './ModalHandler.js';
10 changes: 10 additions & 0 deletions src/commands/tickets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Category } from '#types';
import { SlashCommandBuilder } from 'discord.js';

export const data = new SlashCommandBuilder()
.setName('tickets')
.setNameLocalizations({ pl: 'idk' })
.setDescription('we are in the process of doing ur mom.')
.setDescriptionLocalizations({ pl: 'idk im not that fluent at polska.' });

export const category: Category = 'tools';
43 changes: 43 additions & 0 deletions src/commands/tickets/new.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { FluorineClient } from '#classes';
import {
type ChatInputCommandInteraction,
SlashCommandSubcommandBuilder,
ModalBuilder,
TextInputBuilder,
ActionRowBuilder,
TextInputStyle
} from 'discord.js';

export async function run(client: FluorineClient, interaction: ChatInputCommandInteraction) {
const modal = new ModalBuilder()
.setTitle('Create New Ticket')
.setCustomId('modal:ticketNew')
.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId(`ticketTitle`)
.setLabel('Ticket Title')
.setPlaceholder('A short title that describes the ticket.')
.setStyle(TextInputStyle.Short)
.setMaxLength(256)
.setRequired(true)
),
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId(`ticketContent`)
.setLabel('Ticket Description')
.setPlaceholder('A more indepth description of the ticket.')
.setStyle(TextInputStyle.Paragraph)
.setMaxLength(4000)
.setRequired(false)
)
);

interaction.showModal(modal);
}

export const data = new SlashCommandSubcommandBuilder()
.setName('new')
.setNameLocalizations({ pl: 'idk-either-but-this' })
.setDescription('idk smth abt creating a new user-facing ticket creation point or bullidk')
.setDescriptionLocalizations({ pl: 'do ur mom' });
9 changes: 9 additions & 0 deletions src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export async function run(client: FluorineClient, interaction: Interaction) {

return component?.run(client, interaction, value);
}

if (interaction.isModalSubmit()) {
const [, name] = interaction.customId.split(':');
const modal = client.modals.get(name);

return modal?.run(client, interaction, interaction.fields.fields);
}

if (interaction.isContextMenuCommand()) {
const contextCommand = client.commands.contextMenu.get(interaction.commandName);

Expand All @@ -30,6 +38,7 @@ export async function run(client: FluorineClient, interaction: Interaction) {

return contextCommand.run(client, interaction);
}

if (interaction.isChatInputCommand()) {
const subcommand = interaction.options.getSubcommand(false);
const key = subcommand ? `${interaction.commandName}/${subcommand}` : interaction.commandName;
Expand Down
16 changes: 16 additions & 0 deletions src/modals/ticketNew.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { type FluorineClient, Embed } from '#classes';
import type { Collection, ModalSubmitInteraction, TextInputComponent } from 'discord.js';

export async function run(
client: FluorineClient,
interaction: ModalSubmitInteraction,
fields: Collection<string, TextInputComponent>
) {
return interaction.reply({
embeds: [
new Embed(client, interaction.locale)
.setTitle(fields.get('ticketTitle').value)
.setDescription(fields.get('ticketContent')?.value ?? 'none')
]
});
}
12 changes: 11 additions & 1 deletion src/types/structures.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type { FluorineClient } from '#classes';
import type {
Collection,
CommandInteraction,
ContextMenuCommandBuilder,
ContextMenuCommandInteraction,
MessageComponentInteraction,
ModalSubmitInteraction,
SlashCommandBuilder,
SlashCommandSubcommandBuilder
SlashCommandSubcommandBuilder,
TextInputComponent
} from 'discord.js';

export type Category = 'fun' | 'tools' | 'moderation' | 'economy';
Expand Down Expand Up @@ -36,6 +39,13 @@ export interface Component {
run: (client: FluorineClient, interaction: MessageComponentInteraction, value: string) => void;
}

export interface Modal {
run: (
client: FluorineClient,
interaction: ModalSubmitInteraction,
fields: Collection<string, TextInputComponent>
) => void;
}
export interface Event {
run: (client: FluorineClient, ...args: any) => void;
}
Expand Down