From 15eef95fdd95a6d75937701911bff90443e7f2c2 Mon Sep 17 00:00:00 2001 From: DJj123dj <80536295+DJj123dj@users.noreply.github.com> Date: Wed, 19 Feb 2025 15:43:43 +0100 Subject: [PATCH] Decreased /clear speed to reduce ratelimit chances --- src/actions/clearTickets.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/actions/clearTickets.ts b/src/actions/clearTickets.ts index c654557..f2fac57 100644 --- a/src/actions/clearTickets.ts +++ b/src/actions/clearTickets.ts @@ -14,12 +14,32 @@ export const registerActions = async () => { await opendiscord.events.get("onTicketsClear").emit([list,user,channel,filter]) const nameList: string[] = [] - for (const ticket of list){ - const ticketChannel = await opendiscord.tickets.getTicketChannel(ticket) - if (!ticketChannel) return - nameList.push("#"+ticketChannel.name) - await opendiscord.actions.get("opendiscord:delete-ticket").run("clear",{guild,channel:ticketChannel,user,ticket,reason:"Cleared Ticket",sendMessage:true,withoutTranscript:false}) + + //split tickets into smaller groups of 10 (to decrease ratelimit chances for HTML Transcripts & discord API) + const subGroupList: api.ODTicket[][] = [] + let tempSubGroup: api.ODTicket[] = [] + list.forEach((ticket,index) => { + tempSubGroup.push(ticket) + if (tempSubGroup.length >= 10){ + subGroupList.push(tempSubGroup) + tempSubGroup = [] + } + }) + if (tempSubGroup.length > 0) subGroupList.push(tempSubGroup) + + let groupIndex = 0 + for (const ticketGroup of subGroupList){ + for (const ticket of ticketGroup){ + const ticketChannel = await opendiscord.tickets.getTicketChannel(ticket) + if (!ticketChannel) return + nameList.push("#"+ticketChannel.name) + await opendiscord.actions.get("opendiscord:delete-ticket").run("clear",{guild,channel:ticketChannel,user,ticket,reason:"Cleared Ticket",sendMessage:true,withoutTranscript:false}) + await utilities.timer(2000) //wait 2sec between each deletion + } + if (groupIndex < subGroupList.length-1) await utilities.timer(45*1000) //wait 45sec between each group deletion (10 tickets) + groupIndex++ } + instance.list = nameList await opendiscord.events.get("afterTicketsCleared").emit([list,user,channel,filter]) }),