Skip to content
Open
Show file tree
Hide file tree
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
25 changes: 16 additions & 9 deletions bot/button/handlers/addadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func (h *AddAdminHandler) Execute(ctx *context.ButtonContext) {
return
}

if mentionableType == context.MentionableTypeUser {
switch mentionableType {
case context.MentionableTypeUser:
// Guild owner doesn't need to be added
guild, err := ctx.Guild()
if err != nil {
Expand All @@ -99,7 +100,7 @@ func (h *AddAdminHandler) Execute(ctx *context.ButtonContext) {
ctx.HandleError(err)
return
}
} else if mentionableType == context.MentionableTypeRole {
case context.MentionableTypeRole:
if id == ctx.GuildId() {
ctx.Reply(customisation.Red, i18n.Error, i18n.MessageAddSupportEveryone)
return
Expand All @@ -114,15 +115,16 @@ func (h *AddAdminHandler) Execute(ctx *context.ButtonContext) {
ctx.HandleError(err)
return
}
} else {
default:
ctx.HandleError(fmt.Errorf("invalid mentionable type: %d", mentionableType))
return
}

var mention string
if mentionableType == context.MentionableTypeUser {
switch mentionableType {
case context.MentionableTypeUser:
mention = fmt.Sprintf("<@%d>", id)
} else {
case context.MentionableTypeRole:
mention = fmt.Sprintf("<@&%d>", id)
}

Expand All @@ -141,11 +143,12 @@ func (h *AddAdminHandler) Execute(ctx *context.ButtonContext) {

// Get the name of the user/role being added
var targetName string
if mentionableType == context.MentionableTypeUser {
switch mentionableType {
case context.MentionableTypeUser:
if targetMember, err := ctx.Worker().GetGuildMember(ctx.GuildId(), id); err == nil {
targetName = targetMember.User.Username
}
} else if mentionableType == context.MentionableTypeRole {
case context.MentionableTypeRole:
if roles, err := ctx.Worker().GetGuildRoles(ctx.GuildId()); err == nil {
for _, role := range roles {
if role.Id == id {
Expand All @@ -160,7 +163,7 @@ func (h *AddAdminHandler) Execute(ctx *context.ButtonContext) {
if settings.TicketNotificationChannel != nil {
auditReason := "Added admin member/role"
if hasMember && targetName != "" {
auditReason = fmt.Sprintf("Added admin %s (%s) by %s", mentionableType, targetName, member.User.Username)
auditReason = fmt.Sprintf("Added admin %d (%s) by %s", mentionableType, targetName, member.User.Username)
} else if hasMember {
auditReason = fmt.Sprintf("Added admin member/role by %s", member.User.Username)
}
Expand Down Expand Up @@ -214,9 +217,13 @@ func (h *AddAdminHandler) Execute(ctx *context.ButtonContext) {
Deny: 0,
})

pos := 0
if ch.Position != nil {
pos = *ch.Position
}
data := rest.ModifyChannelData{
PermissionOverwrites: overwrites,
Position: ch.Position,
Position: pos,
}

ticketAuditReason := fmt.Sprintf("Added admin to ticket %d", ticket.Id)
Expand Down
48 changes: 14 additions & 34 deletions bot/button/handlers/addsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,49 +74,24 @@ func (h *AddSupportHandler) Execute(ctx *context.ButtonContext) {
return
}

if mentionableType == context.MentionableTypeUser {
switch mentionableType {
case context.MentionableTypeUser:
ctx.ReplyRaw(customisation.Red, "Error", "Users in support teams are now deprecated. Please use roles instead.")
return

/* TODO: Remove if Discord does not resolve the performance issues

// Guild owner doesn't need to be added
guild, err := ctx.Guild()
if err != nil {
ctx.HandleError(err)
return
}

if guild.OwnerId == id {
ctx.Reply(customisation.Red, i18n.Error, i18n.MessageOwnerIsAlreadyAdmin)
return
}

if err := dbclient.Client.Permissions.AddSupport(ctx.GuildId(), id); err != nil {
sentry.ErrorWithContext(err, ctx.ToErrorContext())
}

if err := utils.ToRetriever(ctx.Worker()).Cache().SetCachedPermissionLevel(ctx.GuildId(), id, permcache.Support); err != nil {
ctx.HandleError(err)
return
}
*/
} else if mentionableType == context.MentionableTypeRole {
case context.MentionableTypeRole:
if id == ctx.GuildId() {
ctx.Reply(customisation.Red, i18n.Error, i18n.MessageAddSupportEveryone)
return
}

if err := dbclient.Client.RolePermissions.AddSupport(ctx, ctx.GuildId(), id); err != nil {
ctx.HandleError(err)
return
}

if err := utils.ToRetriever(ctx.Worker()).Cache().SetCachedPermissionLevel(ctx, ctx.GuildId(), id, permcache.Support); err != nil {
ctx.HandleError(err)
return
}
} else {
default:
ctx.HandleError(fmt.Errorf("invalid mentionable type: %d", mentionableType))
return
}
Expand All @@ -142,11 +117,12 @@ func updateChannelPermissions(ctx cmdregistry.CommandContext, id uint64, mention

// Get the name of the user/role being added
var targetName string
if mentionableType == context.MentionableTypeUser {
switch mentionableType {
case context.MentionableTypeUser:
if targetMember, err := ctx.Worker().GetGuildMember(ctx.GuildId(), id); err == nil {
targetName = targetMember.User.Username
}
} else if mentionableType == context.MentionableTypeRole {
case context.MentionableTypeRole:
if roles, err := ctx.Worker().GetGuildRoles(ctx.GuildId()); err == nil {
for _, role := range roles {
if role.Id == id {
Expand All @@ -161,7 +137,7 @@ func updateChannelPermissions(ctx cmdregistry.CommandContext, id uint64, mention
if settings.TicketNotificationChannel != nil {
auditReason := "Added support member/role"
if hasMember && targetName != "" {
auditReason = fmt.Sprintf("Added support %s (%s) by %s", mentionableType, targetName, member.User.Username)
auditReason = fmt.Sprintf("Added support %d (%s) by %s", mentionableType, targetName, member.User.Username)
} else if hasMember {
auditReason = fmt.Sprintf("Added support member/role by %s", member.User.Username)
}
Expand Down Expand Up @@ -239,14 +215,18 @@ func updateChannelPermissions(ctx cmdregistry.CommandContext, id uint64, mention
Deny: 0,
})

pos := 0
if ch.Position != nil {
pos = *ch.Position
}
data := rest.ModifyChannelData{
PermissionOverwrites: overwrites,
Position: ch.Position,
Position: pos,
}

ticketAuditReason := fmt.Sprintf("Added support to ticket %d", ticket.Id)
if hasMember && targetName != "" {
ticketAuditReason = fmt.Sprintf("Added support %s (%s) to ticket %d by %s", mentionableType, targetName, ticket.Id, member.User.Username)
ticketAuditReason = fmt.Sprintf("Added support %d (%s) to ticket %d by %s", mentionableType, targetName, ticket.Id, member.User.Username)
} else if hasMember {
ticketAuditReason = fmt.Sprintf("Added support to ticket %d by %s", ticket.Id, member.User.Username)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func buildPanelSettings(ctx *context.ModalContext, selectedPanel *database.Panel
if selectedPanel.ChannelId != 0 {
channel, err := ctx.Worker().GetChannel(selectedPanel.ChannelId)
if err == nil {
settings = append(settings, fmt.Sprintf("**Panel Channel:** `#%s` (%d)", channel.Name, selectedPanel.ChannelId))
settings = append(settings, fmt.Sprintf("**Panel Channel:** `#%s` (%d)", *channel.Name, selectedPanel.ChannelId))
} else {
settings = append(settings, fmt.Sprintf("**Panel Channel:** `%d` (channel not found)", selectedPanel.ChannelId))
}
Expand All @@ -157,7 +157,7 @@ func buildPanelSettings(ctx *context.ModalContext, selectedPanel *database.Panel
if !selectedPanel.UseThreads && selectedPanel.TargetCategory != 0 {
category, err := ctx.Worker().GetChannel(selectedPanel.TargetCategory)
if err == nil {
settings = append(settings, fmt.Sprintf("**Target Category:** `%s` (%d)", category.Name, selectedPanel.TargetCategory))
settings = append(settings, fmt.Sprintf("**Target Category:** `%s` (%d)", *category.Name, selectedPanel.TargetCategory))
} else {
settings = append(settings, fmt.Sprintf("**Target Category:** `%d` (category not found)", selectedPanel.TargetCategory))
}
Expand All @@ -167,7 +167,7 @@ func buildPanelSettings(ctx *context.ModalContext, selectedPanel *database.Panel
if selectedPanel.TranscriptChannelId != nil {
channel, err := ctx.Worker().GetChannel(*selectedPanel.TranscriptChannelId)
if err == nil {
settings = append(settings, fmt.Sprintf("**Transcript Channel:** `#%s` (%d)", channel.Name, *selectedPanel.TranscriptChannelId))
settings = append(settings, fmt.Sprintf("**Transcript Channel:** `#%s` (%d)", *channel.Name, *selectedPanel.TranscriptChannelId))
} else {
settings = append(settings, fmt.Sprintf("**Transcript Channel:** `%d` (channel not found)", *selectedPanel.TranscriptChannelId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func checkChannelPermissions(worker *w.Context, channelId uint64, botMember memb
}

var result strings.Builder
result.WriteString(fmt.Sprintf("**%s** (`#%s`)\n", label, channel.Name))
result.WriteString(fmt.Sprintf("**%s** (`#%s`)\n", label, *channel.Name))
if len(missing) > 0 {
result.WriteString("**Missing Permissions:**\n")
for _, p := range missing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func checkUserTicketPermissions(ctx *context.ModalContext, worker *w.Context, gu

// Check support roles
supportRoles, err := dbclient.Client.RolePermissions.GetSupportRoles(ctx, guildId)
if err == nil && ticketPermLevel != "**Ticket Permission:** Admin" && ticketPermLevel != "**Ticket Permission:** Server Owner" && ticketPermLevel != "**Ticket Permission:** Admin" {
if err == nil && ticketPermLevel != "**Ticket Permission:** Admin" && ticketPermLevel != "**Ticket Permission:** Server Owner" {
var supportRoleNames []string
for _, roleId := range member.Roles {
if utils.Contains(supportRoles, roleId) {
Expand Down
2 changes: 1 addition & 1 deletion bot/button/handlers/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func parseModalComponents(actionRows []interaction.ModalSubmitInteractionActionR
c := actionRow.Component
var answer string
switch c.Type {
case component.ComponentSelectMenu, component.ComponentCheckboxGroup:
case component.ComponentStringSelect, component.ComponentCheckboxGroup:
answer = strings.Join(c.Values, ", ")
case component.ComponentInputText:
answer = c.Value
Expand Down
76 changes: 4 additions & 72 deletions bot/button/handlers/gdprmodal.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,74 +121,6 @@ func getGuildsWithUserMessages(ctx *cmdcontext.ButtonContext, userId uint64) ([]
return batchFetchGuildsInfo(ctx, guildIds)
}

func batchFetchOwnedGuilds(ctx *cmdcontext.ButtonContext, guildIds []uint64, userId uint64) ([]guildInfo, error) {
retriever := utils.ToRetriever(ctx.Worker())

type result struct {
info guildInfo
ok bool
}

resultChan := make(chan result, len(guildIds))
var wg sync.WaitGroup
semaphore := make(chan struct{}, 10)

for _, guildId := range guildIds {
wg.Add(1)
go func(gId uint64) {
defer wg.Done()

semaphore <- struct{}{}
defer func() { <-semaphore }()

ownerId, err := retriever.GetGuildOwner(ctx, gId)
if err != nil {
resultChan <- result{ok: false}
return
}

if ownerId != userId {
resultChan <- result{ok: false}
return
}

guild, err := ctx.Worker().GetGuild(gId)
if err != nil {
resultChan <- result{
info: guildInfo{
GuildID: gId,
Name: strconv.FormatUint(gId, 10),
},
ok: true,
}
return
}

resultChan <- result{
info: guildInfo{
GuildID: gId,
Name: guild.Name,
},
ok: true,
}
}(guildId)
}

go func() {
wg.Wait()
close(resultChan)
}()

var guilds []guildInfo
for res := range resultChan {
if res.ok {
guilds = append(guilds, res.info)
}
}

return guilds, nil
}

func batchFetchGuildsInfo(ctx *cmdcontext.ButtonContext, guildIds []uint64) ([]guildInfo, error) {
type result struct {
info guildInfo
Expand Down Expand Up @@ -611,7 +543,7 @@ func (h *GDPRModalSpecificTranscriptsHandler) Execute(ctx *context.ModalContext)
if actionRow.Component != nil {
switch actionRow.Component.CustomId {
case "server_id":
if actionRow.Component.Values != nil && len(actionRow.Component.Values) > 0 {
if len(actionRow.Component.Values) > 0 {
serverId = actionRow.Component.Values[0]
} else if actionRow.Component.Value != "" {
serverId = actionRow.Component.Value
Expand All @@ -623,7 +555,7 @@ func (h *GDPRModalSpecificTranscriptsHandler) Execute(ctx *context.ModalContext)
for _, component := range actionRow.Components {
switch component.CustomId {
case "server_id":
if component.Values != nil && len(component.Values) > 0 {
if len(component.Values) > 0 {
serverId = component.Values[0]
} else if component.Value != "" {
serverId = component.Value
Expand Down Expand Up @@ -806,7 +738,7 @@ func (h *GDPRModalSpecificMessagesHandler) Execute(ctx *context.ModalContext) {
if actionRow.Component != nil {
switch actionRow.Component.CustomId {
case "server_id":
if actionRow.Component.Values != nil && len(actionRow.Component.Values) > 0 {
if len(actionRow.Component.Values) > 0 {
serverId = actionRow.Component.Values[0]
} else if actionRow.Component.Value != "" {
serverId = actionRow.Component.Value
Expand All @@ -818,7 +750,7 @@ func (h *GDPRModalSpecificMessagesHandler) Execute(ctx *context.ModalContext) {
for _, component := range actionRow.Components {
switch component.CustomId {
case "server_id":
if component.Values != nil && len(component.Values) > 0 {
if len(component.Values) > 0 {
serverId = component.Values[0]
} else if component.Value != "" {
serverId = component.Value
Expand Down
2 changes: 1 addition & 1 deletion bot/button/handlers/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func buildFormComponents(inputs []database.FormInput, inputOptions map[int][]dat

switch input.Type {
// String Select
case int(component.ComponentSelectMenu):
case int(component.ComponentStringSelect):
opts := make([]component.SelectOption, len(options))
for j, option := range options {
opts[j] = component.SelectOption{
Expand Down
2 changes: 1 addition & 1 deletion bot/button/handlers/tickets/edit/editlabelsbutton.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (h *EditLabelsButtonHandler) Execute(ctx *context.ButtonContext) {
Label: labels[i].Name,
Value: fmt.Sprintf("%d", labels[i].LabelId),
Default: utils.Contains(ticketLabelIds, labels[i].LabelId),
Emoji: &emoji.Emoji{Name: colourEmoji},
Emoji: &emoji.Emoji{Name: utils.Ptr(colourEmoji)},
})
}

Expand Down
8 changes: 4 additions & 4 deletions bot/button/handlers/unclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (h *UnclaimHandler) Execute(ctx *context.ButtonContext) {
if !claimerHasAccess {
filteredOverwrites := make([]channel.PermissionOverwrite, 0, len(overwrites))
for _, ow := range overwrites {
if ow.Id != whoClaimed || ow.Type != channel.PermissionTypeMember {
if ow.Id != whoClaimed || ow.Type != channel.PermissionOverwriteTypeMember {
filteredOverwrites = append(filteredOverwrites, ow)
}
}
Expand All @@ -147,14 +147,14 @@ func (h *UnclaimHandler) Execute(ctx *context.ButtonContext) {
case database.SwitchPanelKeepAccess:
overwrites = append(overwrites, channel.PermissionOverwrite{
Id: whoClaimed,
Type: channel.PermissionTypeMember,
Type: channel.PermissionOverwriteTypeMember,
Allow: discordpermission.BuildPermissions(logic.StandardPermissions[:]...),
Deny: 0,
})
case database.SwitchPanelRemoveOnUnclaim:
overwrites = append(overwrites, channel.PermissionOverwrite{
Id: whoClaimed,
Type: channel.PermissionTypeMember,
Type: channel.PermissionOverwriteTypeMember,
Allow: 0,
Deny: discordpermission.BuildPermissions(discordpermission.ViewChannel),
})
Expand All @@ -172,7 +172,7 @@ func (h *UnclaimHandler) Execute(ctx *context.ButtonContext) {
// Always update the name to match the new panel's naming scheme
shouldUpdateName := true
claimedChannelName, _ := logic.GenerateChannelName(ctx.Context, ctx.Worker(), panel, ticket.GuildId, ticket.Id, ticket.UserId, &whoClaimed)
if ch.Name != claimedChannelName {
if ch.Name == nil || *ch.Name != claimedChannelName {
shouldUpdateName = false
}

Expand Down
Loading
Loading