Skip to content
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
26 changes: 16 additions & 10 deletions bot/logic/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,31 @@ func ApplyClaim(ctx context.Context, cmd registry.CommandContext, ticket databas
shouldUpdateName := true
// But skip if the user has manually renamed the channel (doesn't match old unclaimed name)
oldChannelName, _ := GenerateChannelName(ctx, cmd.Worker(), panel, ticket.GuildId, ticket.Id, ticket.UserId, nil)
if currentChannel.Name != oldChannelName {
if currentChannel.Name != oldChannelName || newChannelName == oldChannelName {
shouldUpdateName = false
}

// Pin the claimer's access at the user level
claimer, err := cmd.Worker().GetGuildMember(ticket.GuildId, userId)
auditReason := fmt.Sprintf("Claimed ticket %d", ticket.Id)
if err == nil {
auditReason = fmt.Sprintf("Claimed ticket %d by %s", ticket.Id, claimer.User.Username)
}

reasonCtx := request.WithAuditReason(context.Background(), auditReason)

if newOverwrites == nil {
claimerOverwrite, err := BuildClaimerOverwrite(ctx, cmd.Worker(), ticket, userId)
if err != nil {
return err
}

newOverwrites = UpsertMemberOverwrite(currentChannel.PermissionOverwrites, claimerOverwrite)
if err := cmd.Worker().EditChannelPermissions(reasonCtx, *ticket.ChannelId, claimerOverwrite); err != nil {
return err
}
}

if newOverwrites == nil && !shouldUpdateName {
return nil
}

// Update channel permissions and name
Expand All @@ -120,13 +133,6 @@ func ApplyClaim(ctx context.Context, cmd registry.CommandContext, ticket databas
data.Name = newChannelName
}

claimer, err := cmd.Worker().GetGuildMember(ticket.GuildId, userId)
auditReason := fmt.Sprintf("Claimed ticket %d", ticket.Id)
if err == nil {
auditReason = fmt.Sprintf("Claimed ticket %d by %s", ticket.Id, claimer.User.Username)
}

reasonCtx := request.WithAuditReason(context.Background(), auditReason)
if _, err = cmd.Worker().ModifyChannel(reasonCtx, *ticket.ChannelId, data); err != nil {
return err
}
Expand Down
Loading