Skip to content

Commit

Permalink
😓 fix problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Feb 23, 2024
1 parent 878da28 commit 3ea0a72
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/discord/components/tickets/functions/buttonsFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@ export class TicketButtons implements TicketType {
const sendChannel = guild?.channels.cache.find((c) => c.name === nome)
const status: Record<string, boolean | undefined> | 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 = `<t:${Math.floor(futureTime.getTime() / 1000)}:f>`
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')
]
})
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 3ea0a72

Please sign in to comment.