From 3ea0a72b5c39556a5b559db24288e2acbd2da8cd Mon Sep 17 00:00:00 2001 From: Ashu11-A Date: Fri, 23 Feb 2024 00:01:46 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=93=20fix=20problems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tickets/functions/buttonsFunctions.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/discord/components/tickets/functions/buttonsFunctions.ts b/src/discord/components/tickets/functions/buttonsFunctions.ts index 70de69bc..b66d5821 100644 --- a/src/discord/components/tickets/functions/buttonsFunctions.ts +++ b/src/discord/components/tickets/functions/buttonsFunctions.ts @@ -22,19 +22,24 @@ export class TicketButtons implements TicketType { const sendChannel = guild?.channels.cache.find((c) => c.name === nome) const status: Record | null = await db.system.get(`${guild?.id}.status`) const ticket = await db.guilds.get(`${guild?.id}.ticket`) - const tocketLimit = await db.guilds.get(`${guildId}.config.ticketsLimit`) + const ticketLimit = await db.guilds.get(`${guildId}.config.ticketsLimit`) const usageDay = await db.system.get(`${guildId}.tickets.${user.id}`) as { date: Date, usage: number } | undefined - console.log(usageDay, (new Date(usageDay?.date) < new Date()), tocketLimit) if (usageDay !== undefined) { + const futureTime = new Date(usageDay.date) let muchRequest: boolean = false - if (new Date(usageDay.date) > new Date()) muchRequest = true - if (usageDay.usage >= tocketLimit ?? 1) muchRequest = true + if (futureTime < new Date()) { + await db.system.delete(`${guildId}.tickets.${user.id}`) + } else if (usageDay.usage >= ticketLimit ?? 1) muchRequest = true if (muchRequest) { + const futureTimeString = `` await this.interaction.editReply({ embeds: [ new EmbedBuilder({ - title: 'Você já usou o limite diario de tickets, por favor, não spame!' + title: `❌ | Você já usou o limite diario de tickets (${usageDay.usage}/${ticketLimit}), por favor, não spame!`, + fields: [ + { name: 'Tente novamente em:', value: futureTimeString } + ] }).setColor('Red') ] }) @@ -135,7 +140,9 @@ export class TicketButtons implements TicketType { } else { await ch?.send({ embeds: [embed], components: [botao] }).catch(console.error) } - await db.system.set(`${guildId}.tickets.${user.id}`, { date: new Date(new Date().getDate() + 1), usage: usageDay?.usage !== undefined ? usageDay.usage + 1 : 1 }) + const date = new Date().setDate(new Date().getDate() + 1) + const getUsage = await db.system.get(`${guildId}.tickets.${user.id}`) + await db.system.set(`${guildId}.tickets.${user.id}`, { date, usage: getUsage?.usage !== undefined ? getUsage.usage + 1 : 1 }) } catch (all) { console.error(all) await this.interaction.editReply({