From 317c428b242b2870b242d6b6e2d04fb13416a675 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: Wed, 5 Jun 2024 23:40:36 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=86=95=20Add=20setData=20and=20addEvent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/tickets/src/class/TicketBuilder.ts | 18 +++++++++++------- plugins/tickets/src/entity/Ticket.entry.ts | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/plugins/tickets/src/class/TicketBuilder.ts b/plugins/tickets/src/class/TicketBuilder.ts index d570ec08..fd771d27 100644 --- a/plugins/tickets/src/class/TicketBuilder.ts +++ b/plugins/tickets/src/class/TicketBuilder.ts @@ -36,7 +36,8 @@ export class TicketBuilder { team: [], users: [], messages: [], - history: [] + history: [], + events: [] } } @@ -46,12 +47,15 @@ export class TicketBuilder { setClosed(isClosed: boolean) { this.options.closed = isClosed ?? false; return this } setVoice(voice: Voice) { this.options.voice = voice; return this } setCategory (category: TicketCategories) { this.options.category = category; return this } - setClaim (message: Message) { this.options.claim = message; return this } + setClaim (message: TicketMessage) { this.options.claim = message; return this } - addUsers (user: User) { this.options.users.push(user); return this } - addTeam (user: User) { this.options.team.push(user); return this } - addMessage (message: Message) { this.options.messages.push(message); return this } + setData(data: Ticket) { this.options = Object.assign(this.options, data); return this } + + addTeam (user: UserTicket) { this.options.team.push(user); return this } + addUsers (user: UserTicket) { this.options.users.push(user); return this } + addEvent (event: Event) { this.options.events.push(event); return this } addHistory (content: History) { this.options.history.push(content); return this } + addMessage (message: TicketMessage) { this.options.messages.push(message); return this } private permissions (): OverwriteResolvable[] { const { guild } = this.interaction @@ -109,8 +113,8 @@ export class TicketBuilder { footer: { text: `Equipe ${guild?.name} | ${new Date().toLocaleString('pt-BR', { timeZone: 'America/Sao_Paulo' })}`, iconURL: (guild?.iconURL({ size: 64 }) ?? undefined) } }) - if (title !== undefined) embed.addFields({ name: '📃 Motivo:', value: codeBlock(title) }) - if (description !== undefined) embed.addFields({ name: '📭 Descrição:', value: codeBlock(description) }) + if (typeof title === 'string') embed.addFields({ name: '📃 Motivo:', value: codeBlock(title) }) + if (typeof description === 'string') embed.addFields({ name: '📭 Descrição:', value: codeBlock(description) }) const buttons: ButtonBuilder[] = [] buttons.push( diff --git a/plugins/tickets/src/entity/Ticket.entry.ts b/plugins/tickets/src/entity/Ticket.entry.ts index 73ef1f35..8b1b700f 100644 --- a/plugins/tickets/src/entity/Ticket.entry.ts +++ b/plugins/tickets/src/entity/Ticket.entry.ts @@ -22,6 +22,15 @@ export interface History { deleted: boolean } +export interface Event { + user: { + id: string + name: string + } + message: string + date: Date +} + export interface Message { channelId: string messageId: string @@ -51,6 +60,7 @@ export interface TicketType { users: User[] history: History[] messages: Message[] + events: Event[] } @Entity({ name: 'tickets' }) @@ -133,6 +143,16 @@ export default class Ticket extends BaseEntity { }) messages!: Message[] + @Column({ + type: 'simple-json', + nullable: true, + transformer: { + to(value: string): string { return JSON.stringify(value) }, + from(value: string): Event[] { return JSON.parse(value) }, + } + }) + events!: Event[] + @Column({ type: 'simple-json', nullable: true,