From 56c3ec68e2513e369db94ff3fe11496055213b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A7=81Ash=C3=BB=EA=A7=82?= <30575805+Ashu11-A@users.noreply.github.com> Date: Thu, 6 Jun 2024 19:59:07 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9D=8C=20Remove=20setChannelId,=20=E2=9A=99?= =?UTF-8?q?=EF=B8=8F=20set=20claimId=20in=20create=20channel,=20?= =?UTF-8?q?=F0=9F=86=95=20new=20Delete=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/tickets/src/class/ClaimBuilder.ts | 35 +++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/plugins/tickets/src/class/ClaimBuilder.ts b/plugins/tickets/src/class/ClaimBuilder.ts index 07bc8135..4529d98d 100644 --- a/plugins/tickets/src/class/ClaimBuilder.ts +++ b/plugins/tickets/src/class/ClaimBuilder.ts @@ -32,7 +32,6 @@ export class ClaimBuilder { } setTicketId(ticketId: number) { this.options.ticketId = ticketId ; return this } - setChannelId(channelId: string) { this.options.channelId = channelId ; return this } private permissions (roles: Roles[]): OverwriteResolvable[] { const permissionOverwrites: OverwriteResolvable[] = [] @@ -124,15 +123,15 @@ export class ClaimBuilder { } async create(): Promise { const { guildId, guild } = this.interaction - const configs = await config.findOne({ where: { guild: { id: guildId } }, relations: { guild: true } }) + const configs = await config.findOne({ where: { guild: { id: guildId } }, relations: { guild: true } }) as Config const permissions = this.permissions(configs?.roles ?? []) - - if (this.embed === undefined || this.buttons === undefined) { - await this.render() - } + + if (this.embed === undefined || this.buttons === undefined) await this.render() async function createChannel () { - return await guild.channels.create({ name: 'claim-tickets', type: ChannelType.GuildText }) + const newGuild = await guild.channels.create({ name: 'claim-tickets', type: ChannelType.GuildText }) + await config.update({ id: configs.id }, { claimId: newGuild.id }) + return newGuild } const channel = configs?.claimId !== undefined ? @@ -142,13 +141,31 @@ export class ClaimBuilder { await channel.edit({ permissionOverwrites: permissions }) if (channel.isTextBased()) { const message = await channel.send({ embeds: [this.embed as EmbedBuilder], components: this.buttons }) - const claimData = await claim.create({ ticket: { id: this.options.ticketId }, channelId: this.options.channelId, messageId: message.id }) - await claim.save(claimData) + const claimData = await claim.create({ channelId: channel.id, messageId: message.id }) + const result = await claim.save(claimData) as Claim + await ticket.update({ id: this.options.ticketId }, { claim: { id: result.id } }) return claimData } return } + async delete ({ id }: { id: number }) { + const claimData = await claim.findOne({ where: { id } }) + if (claimData === null) return await new Error({ element: 'claim', interaction: this.interaction }).notFound({ type: 'Database' }).reply() + + const channel = await this.interaction.client.channels.fetch(claimData.channelId).catch(async() => null) + + if (channel === null) return await new Error({ element: 'do claim', interaction: this.interaction }).notFound({ type: "Channel" }).reply() + if (!channel.isTextBased()) return await new Error({ element: 'concluir a ação, pois o channel não é um TextBased', interaction: this.interaction }).notPossible().reply() + + + const message = await channel.messages.fetch(claimData.messageId).catch(() => null) + if (message === null) return await new Error({ element: 'do claim', interaction: this.interaction }).notFound({ type: "Message" }).reply() + if (message.deletable) await message.delete() + + return await claim.delete({ id }) + } + // update({ id }: { id: number }) { // claim // }