Skip to content

Commit

Permalink
🔄 Implementing switches for editing and production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed May 24, 2024
1 parent 8f83963 commit e431cf3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
34 changes: 31 additions & 3 deletions plugins/tickets/src/class/Ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ButtonBuilder } from "@/discord/base/CustomIntetaction"
import Template, { TypeTemplate } from "@/entity/Template.entry"
import { ActionDrawer } from "@/functions/actionDrawer"
import { checkChannel } from "@/functions/checkChannel"
import { ActionRowBuilder, ButtonInteraction, ButtonStyle, CacheType, CommandInteraction, EmbedBuilder, ModalSubmitInteraction } from "discord.js"
import { ActionRowBuilder, ButtonInteraction, ButtonStyle, CacheType, CommandInteraction, EmbedBuilder, ModalSubmitInteraction, TextInputBuilder } from "discord.js"
const template = new Database<Template>({ table: 'Template' })
interface TicketOptions {
interaction: CommandInteraction<CacheType> | ModalSubmitInteraction<CacheType> | ButtonInteraction<CacheType>
Expand Down Expand Up @@ -39,7 +39,7 @@ export class Ticket {
footer: { text: `Equipe ${this.interaction.guild?.name}`, iconURL: (this.interaction?.guild?.iconURL({ size: 64 }) ?? undefined) }
})

const components = await this.generateButtons({})
const components = await this.genEditButtons({})

await channel.send({ embeds: [embed], components }).then(async (message) => {
const create = await template.create({
Expand All @@ -51,7 +51,7 @@ export class Ticket {
})
}

async generateButtons ({ messageId }: GenerateButtons): Promise<ActionRowBuilder<ButtonBuilder>[]> {
async genEditButtons ({ messageId }: GenerateButtons): Promise<ActionRowBuilder<ButtonBuilder>[]> {
const row = [
new ButtonBuilder({
customId: `setTitle`,
Expand Down Expand Up @@ -160,4 +160,32 @@ export class Ticket {

return ActionDrawer(row, 5)
}

async genProductionButtons ({ messageId }: GenerateButtons): Promise<ActionRowBuilder<ButtonBuilder>[]> {
const templateData = (await template.findOne({ where: { messageId } }))
const row = []

switch (templateData?.type ?? TypeTemplate.Button) {
case TypeTemplate.Modal:
case TypeTemplate.Button:
row.push(
new ButtonBuilder({
customId: 'Open',
label: 'Abrir Ticket',
style: ButtonStyle.Success,
emoji: { name: '🎫' }
}),
new ButtonBuilder({
customId: 'Config',
emoji: { name: '⚙️' },
style: ButtonStyle.Secondary
})
)
break
case TypeTemplate.Select:
}

row.push()
return ActionDrawer(row, 5)
}
}
26 changes: 26 additions & 0 deletions plugins/tickets/src/discord/components/Template/Switch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Ticket } from "@/class/Ticket";
import { Component } from "@/discord/base";

new Component({
customId: 'Save',
type: "Button",
async run(interaction) {
await interaction.deferReply({ ephemeral: true })
const components = await (new Ticket({ interaction })).genProductionButtons({ messageId: interaction.message.id })

await interaction.message.edit({ components })
await interaction.deleteReply()
},
})

new Component({
customId: 'Config',
type: "Button",
async run(interaction) {
await interaction.deferReply({ ephemeral: true })
const components = await (new Ticket({ interaction })).genEditButtons({ messageId: interaction.message.id })

await interaction.message.edit({ components })
await interaction.deleteReply()
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ for (const [action, data] of Object.entries(modalData)) {
await template.save(templateData)
.then(async () => {
const ticket = new Ticket({ interaction })
const components = await ticket.generateButtons({ messageId: interaction.message?.id })
const components = await ticket.genEditButtons({ messageId: interaction.message?.id })
interaction.message?.edit({ embeds: [embed], components })

await interaction.editReply({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ for (const [action, type] of Object.entries(actions)) {
}).setColor('Green')]
})

const components = await (new Ticket({ interaction })).generateButtons({ messageId: interaction.message.id })
const components = await (new Ticket({ interaction })).genEditButtons({ messageId: interaction.message.id })

await interaction.message.edit({ components })
})
Expand Down

0 comments on commit e431cf3

Please sign in to comment.