Skip to content

Commit

Permalink
tickets/tickets_bot.go: return meaningful error upon reaching categor…
Browse files Browse the repository at this point in the history
…y channel limit (#1805)
  • Loading branch information
lemm-e authored Jan 2, 2025
1 parent 8148f19 commit abeac76
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tickets/tickets_bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand Down

0 comments on commit abeac76

Please sign in to comment.