From 9248548ba4593f7fc49adc817d671062fa134108 Mon Sep 17 00:00:00 2001 From: lemm-e <67655446+lemm-e@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:39:56 +0530 Subject: [PATCH] tickets/tickets_bot.go: return meaningful error upon reaching category channel limit --- tickets/tickets_bot.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tickets/tickets_bot.go b/tickets/tickets_bot.go index 58b9c2733..dba8ca804 100644 --- a/tickets/tickets_bot.go +++ b/tickets/tickets_bot.go @@ -50,9 +50,10 @@ func (t TicketUserError) Error() string { } const ( - ErrNoTicketCateogry TicketUserError = "No category for ticket channels set" - ErrTitleTooLong TicketUserError = "Title is too long (max 90 characters.) Please shorten it down, you can add more details in the ticket after it has been created" - ErrMaxOpenTickets TicketUserError = "You're currently in over 10 open tickets on this server, please close some of the ones you're in." + ErrNoTicketCategory TicketUserError = "No category for ticket channels set" + ErrTitleTooLong TicketUserError = "Title is too long (max 90 characters.) Please shorten it down, you can add more details in the ticket after it has been created" + ErrMaxOpenTickets TicketUserError = "You're currently in over 10 open tickets on this server, please close some of the ones you're in." + ErrMaxCategoryChannels TicketUserError = "Max channels in category reached (50)" ) const ( @@ -62,7 +63,18 @@ const ( func CreateTicket(ctx context.Context, gs *dstate.GuildSet, ms *dstate.MemberState, conf *models.TicketConfig, topic string, checkMaxTickets, executedByCommandTemplate bool) (*dstate.GuildSet, *models.Ticket, error) { if gs.GetChannel(conf.TicketsChannelCategory) == nil { - return gs, nil, ErrNoTicketCateogry + return gs, nil, ErrNoTicketCategory + } + + categoryChannels := 0 + for _, v := range gs.Channels { + if v.ParentID == conf.TicketsChannelCategory { + categoryChannels++ + } + + if categoryChannels == 50 { + return gs, nil, ErrMaxCategoryChannels + } } if hasPerms, _ := bot.BotHasPermissionGS(gs, conf.TicketsChannelCategory, InTicketPerms); !hasPerms {