Skip to content

Commit

Permalink
πŸ‘¨πŸ»β€πŸ’» Implementing new system
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Jun 15, 2024
1 parent 0ef95bb commit e54c5b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 18 additions & 2 deletions plugins/tickets/src/class/TemplateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 }
Expand All @@ -100,6 +115,7 @@ export class TemplateBuilder {
.setProperties(templateData.properties)
.setSelects(templateData.selects)
.setType(templateData.type)
.setSystem(templateData.systems)
.render()

templateData.embed = embed.toJSON()
Expand Down
6 changes: 4 additions & 2 deletions plugins/tickets/src/class/TemplateButtonBuilder.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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<StringSelectMenuBuilder> | ActionRowBuilder<ButtonBuilder>)[] {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e54c5b7

Please sign in to comment.