diff --git a/plugins/tickets/src/class/TemplateBuilder.ts b/plugins/tickets/src/class/TemplateBuilder.ts index 6625d111..d0d129b9 100644 --- a/plugins/tickets/src/class/TemplateBuilder.ts +++ b/plugins/tickets/src/class/TemplateBuilder.ts @@ -22,11 +22,12 @@ interface APIEmbed { thumbnail?: string; } - export class TemplateBuilder { private readonly interaction: Interaction private options!: APIEmbed - private mode!: 'debug' | 'production' + private mode?: 'debug' | 'production' + private data!: Template + private switch?: string | string[] constructor ({ interaction }: TemplateBuilderOptions) { this.interaction = interaction @@ -55,6 +56,8 @@ export class TemplateBuilder { return this } + switchData (data: string | string[]) { this.switch = data; return this } + render (original: APIEmbedDiscord): EmbedBuilder { const { color, description, image, thumbnail, title } = this.options const embed = new EmbedBuilder(original) @@ -84,6 +87,18 @@ export class TemplateBuilder { return } + /** + * Controle das funções que podem ser desabilitadas ou habilitadas (Ex: MoreDetails) + */ + if (this.switch !== undefined) { + if (!Array.isArray(this.switch)) this.switch = [this.switch] + for (const name of this.switch) { + const index = (templateData.systems ?? []).findIndex((system) => system.name === name) + if (index !== -1) { templateData.systems[index].isEnabled = !templateData.systems[index].isEnabled; continue } + templateData.systems = [ ...(templateData.systems ?? []), { name, isEnabled: true }] + } + } + if (this.options.image !== undefined) { const [isImageURL] = checkURL(this.options.image) if (!isImageURL) { await new Error({ element: 'Image', interaction: this.interaction }).invalidProperty().reply(); return } @@ -100,6 +115,7 @@ export class TemplateBuilder { .setProperties(templateData.properties) .setSelects(templateData.selects) .setType(templateData.type) + .setSystem(templateData.systems) .render() templateData.embed = embed.toJSON() diff --git a/plugins/tickets/src/class/TemplateButtonBuilder.ts b/plugins/tickets/src/class/TemplateButtonBuilder.ts index d120eb21..62f18b8e 100644 --- a/plugins/tickets/src/class/TemplateButtonBuilder.ts +++ b/plugins/tickets/src/class/TemplateButtonBuilder.ts @@ -1,5 +1,5 @@ import { ButtonBuilder, StringSelectMenuBuilder } from "@/discord/base/CustomIntetaction.js"; -import { Properties, Select, TypeTemplate } from "@/entity/Template.entry.js"; +import { Properties, Select, System, TypeTemplate } from "@/entity/Template.entry.js"; import { ActionDrawer } from "@/functions/actionDrawer.js"; import { ActionRowBuilder, ButtonStyle } from "discord.js"; @@ -9,10 +9,12 @@ export class TemplateButtonBuilder { private properties: Properties = {} private selects: Select[] = [] constructor () {} + private system: System[] = [] setMode(mode: 'production' | 'debug') { this.mode = mode; return this } setType(type: TypeTemplate) { this.type = type; return this } setProperties(elements?: Properties) { this.properties = elements ?? {}; return this } + setSystem(elements?: System[]) { this.system = elements ?? []; return this } setSelects(selects?: Select[]) { this.selects = selects ?? []; return this } render(): (ActionRowBuilder | ActionRowBuilder)[] { @@ -141,7 +143,7 @@ export class TemplateButtonBuilder { const { customId } = button if (customId === undefined) continue const ButtonType = Object.entries(buttonType).find(([key]) => key === button.customId ) // [ 'SetModal', 'modal' ] - + if (this.system.find((module) => module.name === button.customId && module.isEnabled)) button.setStyle(ButtonStyle.Primary) if (ButtonType?.[0] === customId && this.type === ButtonType[1]) button.setStyle(ButtonStyle.Primary) if (customId === 'AddSelect' && this.type === TypeTemplate.Select) button.setDisabled(false) if (this.properties[customId] === true) button.setStyle(ButtonStyle.Primary)