Skip to content

Commit

Permalink
❌ Add close function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Jun 7, 2024
1 parent bd152ab commit 234f709
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions plugins/tickets/src/discord/components/Ticket/ButtonActions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ClaimBuilder } from "@/class/ClaimBuilder";
import { TicketBuilder } from "@/class/TicketBuilder";
import { Database } from "@/controller/database";
import { Component } from "@/discord/base";
import { Error } from "@/discord/base/CustomResponse";
import Claim from "@/entity/Claim.entry";
import Ticket from "@/entity/Ticket.entry";
import { EmbedBuilder } from "discord.js";
const ticket = new Database<Ticket>({ table: 'Ticket' })
const claim = new Database<Claim>({ table: 'Claim' })

new Component({
customId: 'Switch',
Expand Down Expand Up @@ -41,4 +44,24 @@ new Component({
]
})
},
})

new Component({
customId: 'Close',
type: "Button",
async run(interaction) {
if (!interaction.inCachedGuild()) return
const { channelId } = interaction
const ticketData = await ticket.findOne({ where: { channelId } })
if (ticketData === null) return await new Error({ element: 'ticket', interaction }).notFound({ type: "Database" }).reply()

const claimData = await claim.findOne({ where: { ticket: { id: ticketData.id } }, relations: { ticket: true } })
if (claimData === null) return await new Error({ element: 'claim desse ticket', interaction }).notFound({ type: "Database" }).reply()

const ticketBuilder = new TicketBuilder({ interaction })
const claimBuilder = new ClaimBuilder({ interaction })

await ticketBuilder.delete({ id: ticketData.id })
await claimBuilder.delete({ id: claimData.id })
},
})

0 comments on commit 234f709

Please sign in to comment.