Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tickets/tickets_bot.go: return error on reaching category channel limit #1805

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)"
lemm-e marked this conversation as resolved.
Show resolved Hide resolved
)

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