Skip to content
Merged
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
6 changes: 3 additions & 3 deletions bot/button/handlers/viewsurvey.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (h *ViewSurveyHandler) Execute(ctx *context.ButtonContext) {
buttons = append(buttons, logic.TranscriptLinkElement(ticket.HasTranscript)(ctx.Worker(), ticket)...)
buttons = append(buttons, logic.ThreadLinkElement(ticket.ChannelId != nil && ticket.IsThread)(ctx.Worker(), ticket)...)

comps := []component.Component{
innerComponents := []component.Component{
component.BuildTextDisplay(component.TextDisplay{Content: fmt.Sprintf("## Exit Survey for %s", opener.GlobalName)}),
component.BuildSeparator(component.Separator{}),
component.BuildTextDisplay(component.TextDisplay{
Expand All @@ -129,11 +129,11 @@ func (h *ViewSurveyHandler) Execute(ctx *context.ButtonContext) {
}

if len(buttons) > 0 {
comps = append(comps, component.BuildActionRow(buttons...))
innerComponents = append(innerComponents, component.BuildActionRow(buttons...))
}

ctx.ReplyWith(command.NewMessageResponseWithComponents(utils.Slice(component.BuildContainer(component.Container{
AccentColor: utils.Ptr(ctx.GetColour(customisation.Green)),
Components: comps,
Components: innerComponents,
}))))
}
6 changes: 3 additions & 3 deletions bot/command/impl/admin/adminlistguildentitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (AdminListGuildEntitlementsCommand) Execute(ctx registry.CommandContext, gu
return
}

values := []component.Component{}
innerComponents := []component.Component{}

for _, entitlement := range entitlements {
value := fmt.Sprintf(
Expand All @@ -110,15 +110,15 @@ func (AdminListGuildEntitlementsCommand) Execute(ctx registry.CommandContext, gu
entitlement.SkuPriority,
)

values = append(values, component.BuildTextDisplay(component.TextDisplay{Content: value}))
innerComponents = append(innerComponents, component.BuildTextDisplay(component.TextDisplay{Content: value}))
}

ctx.ReplyWith(command.NewMessageResponseWithComponents([]component.Component{
utils.BuildContainerWithComponents(
ctx,
customisation.Orange,
i18n.Admin,
values,
innerComponents,
),
}))
}
6 changes: 3 additions & 3 deletions bot/command/impl/admin/adminlistuserentitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (AdminListUserEntitlementsCommand) Execute(ctx registry.CommandContext, use
return
}

values := []component.Component{}
innerComponents := []component.Component{}

for _, entitlement := range entitlements {

Expand All @@ -64,15 +64,15 @@ func (AdminListUserEntitlementsCommand) Execute(ctx registry.CommandContext, use
entitlement.SkuPriority,
)

values = append(values, component.BuildTextDisplay(component.TextDisplay{Content: value}))
innerComponents = append(innerComponents, component.BuildTextDisplay(component.TextDisplay{Content: value}))
}

ctx.ReplyWith(command.NewMessageResponseWithComponents([]component.Component{
utils.BuildContainerWithComponents(
ctx,
customisation.Orange,
i18n.Admin,
values,
innerComponents,
),
}))
}
4 changes: 2 additions & 2 deletions bot/command/impl/admin/adminwhitelabeldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (AdminWhitelabelDataCommand) Execute(ctx registry.CommandContext, userId ui
tds += fmt.Sprintf("**%s:** %s\n", fields[i].Name, fields[i].Value)
}

comps := []component.Component{
innerComponents := []component.Component{
component.BuildTextDisplay(component.TextDisplay{Content: "## Whitelabel"}),
component.BuildSeparator(component.Separator{}),
component.BuildTextDisplay(component.TextDisplay{
Expand All @@ -137,6 +137,6 @@ func (AdminWhitelabelDataCommand) Execute(ctx registry.CommandContext, userId ui

ctx.ReplyWith(command.NewMessageResponseWithComponents(utils.Slice(component.BuildContainer(component.Container{
AccentColor: utils.Ptr(ctx.GetColour(customisation.Green)),
Components: comps,
Components: innerComponents,
}))))
}
4 changes: 2 additions & 2 deletions bot/command/impl/general/jumptotop.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (JumpToTopCommand) Execute(ctx registry.CommandContext) {
}

messageLink := fmt.Sprintf("https://discord.com/channels/%d/%d/%d", ctx.GuildId(), ctx.ChannelId(), *ticket.WelcomeMessageId)
components := []component.Component{
innerComponents := []component.Component{
component.BuildTextDisplay(component.TextDisplay{Content: ctx.GetMessage(i18n.MessageJumpToTopContent)}),
component.BuildSeparator(component.Separator{Divider: utils.Ptr(false)}),
component.BuildActionRow(component.BuildButton(component.Button{
Expand All @@ -64,7 +64,7 @@ func (JumpToTopCommand) Execute(ctx registry.CommandContext) {
}

if _, err := ctx.ReplyWith(command.NewEphemeralMessageResponseWithComponents([]component.Component{
utils.BuildContainerWithComponents(ctx, customisation.Green, i18n.TitleJumpToTop, components),
utils.BuildContainerWithComponents(ctx, customisation.Green, i18n.TitleJumpToTop, innerComponents),
})); err != nil {
ctx.HandleError(err)
return
Expand Down
212 changes: 111 additions & 101 deletions bot/command/impl/settings/blacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,138 +52,148 @@ func (BlacklistCommand) Execute(ctx registry.CommandContext, id uint64) {
return
}

if mentionableType == context.MentionableTypeUser {
member, err := ctx.Worker().GetGuildMember(ctx.GuildId(), id)
if err != nil {
ctx.HandleError(err)
return
}
switch mentionableType {
case context.MentionableTypeUser:
BlacklistCommand{}.handleUserBlacklist(ctx, id, usageEmbed)
case context.MentionableTypeRole:
BlacklistCommand{}.handleRoleBlacklist(ctx, id, usageEmbed)
default:
ctx.HandleError(fmt.Errorf("invalid mentionable type"))
}
}

func (BlacklistCommand) handleUserBlacklist(ctx registry.CommandContext, id uint64, usageEmbed model.Field) {
member, err := ctx.Worker().GetGuildMember(ctx.GuildId(), id)
if err != nil {
ctx.HandleError(err)
return
}

if ctx.UserId() == id {
ctx.ReplyWithFields(customisation.Red, i18n.Error, i18n.MessageBlacklistSelf, utils.ToSlice(usageEmbed))
return
}

if ctx.UserId() == id {
ctx.ReplyWithFields(customisation.Red, i18n.Error, i18n.MessageBlacklistSelf, utils.ToSlice(usageEmbed))
permLevel, err := permission.GetPermissionLevel(ctx, utils.ToRetriever(ctx.Worker()), member, ctx.GuildId())
if err != nil {
ctx.HandleError(err)
return
}

if permLevel > permission.Everyone {
ctx.ReplyWithFields(customisation.Red, i18n.Error, i18n.MessageBlacklistStaff, utils.ToSlice(usageEmbed))
return
}

isBlacklisted, err := dbclient.Client.Blacklist.IsBlacklisted(ctx, ctx.GuildId(), id)
if err != nil {
sentry.ErrorWithContext(err, ctx.ToErrorContext())
return
}

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

permLevel, err := permission.GetPermissionLevel(ctx, utils.ToRetriever(ctx.Worker()), member, ctx.GuildId())
} else {
// Check user blacklist limit
count, err := dbclient.Client.Blacklist.GetBlacklistedCount(ctx, ctx.GuildId())
if err != nil {
ctx.HandleError(err)
return
}

if permLevel > permission.Everyone {
ctx.ReplyWithFields(customisation.Red, i18n.Error, i18n.MessageBlacklistStaff, utils.ToSlice(usageEmbed))
if count >= 250 {
ctx.Reply(customisation.Red, i18n.Error, i18n.MessageBlacklistLimit, 250)
return
}

isBlacklisted, err := dbclient.Client.Blacklist.IsBlacklisted(ctx, ctx.GuildId(), id)
if err != nil {
sentry.ErrorWithContext(err, ctx.ToErrorContext())
if err := dbclient.Client.Blacklist.Add(ctx, ctx.GuildId(), member.User.Id); err != nil {
ctx.HandleError(err)
return
}
}

blacklistMsg := i18n.MessageBlacklistRemove

if isBlacklisted {
if err := dbclient.Client.Blacklist.Remove(ctx, ctx.GuildId(), id); err != nil {
ctx.HandleError(err)
return
}
} else {
// Limit of 250 *users*
count, err := dbclient.Client.Blacklist.GetBlacklistedCount(ctx, ctx.GuildId())
if err != nil {
ctx.HandleError(err)
return
}

if count >= 250 {
ctx.Reply(customisation.Red, i18n.Error, i18n.MessageBlacklistLimit, 250)
return
}

if err := dbclient.Client.Blacklist.Add(ctx, ctx.GuildId(), member.User.Id); err != nil {
ctx.HandleError(err)
return
}
blacklistMsg = i18n.MessageBlacklistAdd
}
BlacklistCommand{}.sendBlacklistResponse(ctx, id, isBlacklisted, true)
}

ctx.ReplyWith(
command.NewEphemeralMessageResponseWithComponents(
utils.Slice(
utils.BuildContainerRaw(ctx.GetColour(customisation.Green), ctx.GetMessage(i18n.TitleBlacklist), ctx.GetMessage(blacklistMsg, id), ctx.PremiumTier()),
),
),
)
} else if mentionableType == context.MentionableTypeRole {
// Check if role is staff
isSupport, err := dbclient.Client.RolePermissions.IsSupport(ctx, id)
if err != nil {
ctx.HandleError(err)
return
}
func (BlacklistCommand) handleRoleBlacklist(ctx registry.CommandContext, id uint64, usageEmbed model.Field) {
// Check if role is support role
isSupport, err := dbclient.Client.RolePermissions.IsSupport(ctx, id)
if err != nil {
ctx.HandleError(err)
return
}

if isSupport {
ctx.ReplyWithFields(customisation.Red, i18n.Error, i18n.MessageBlacklistStaff, utils.ToSlice(usageEmbed))
return
}

if isSupport {
ctx.ReplyWithFields(customisation.Red, i18n.Error, i18n.MessageBlacklistStaff, utils.ToSlice(usageEmbed)) // TODO: Does this need a new message?
// Check if role is part of any support team
isSupport, err = dbclient.Client.SupportTeamRoles.IsSupport(ctx, ctx.GuildId(), id)
if err != nil {
ctx.HandleError(err)
return
}

if isSupport {
ctx.ReplyWithFields(customisation.Red, i18n.Error, i18n.MessageBlacklistStaff, utils.ToSlice(usageEmbed))
return
}

isBlacklisted, err := dbclient.Client.RoleBlacklist.IsBlacklisted(ctx, ctx.GuildId(), id)
if err != nil {
ctx.HandleError(err)
return
}

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

// Check if staff is part of any team
isSupport, err = dbclient.Client.SupportTeamRoles.IsSupport(ctx, ctx.GuildId(), id)
} else {
// Check role blacklist limit - use RoleBlacklist instead of Blacklist
count, err := dbclient.Client.RoleBlacklist.GetBlacklistedCount(ctx, ctx.GuildId())
if err != nil {
ctx.HandleError(err)
return
}

if isSupport {
ctx.ReplyWithFields(customisation.Red, i18n.Error, i18n.MessageBlacklistStaff, utils.ToSlice(usageEmbed)) // TODO: Does this need a new message?
if count >= 50 {
ctx.Reply(customisation.Red, i18n.Error, i18n.MessageBlacklistRoleLimit, 50)
return
}

isBlacklisted, err := dbclient.Client.RoleBlacklist.IsBlacklisted(ctx, ctx.GuildId(), id)
if err != nil {
if err := dbclient.Client.RoleBlacklist.Add(ctx, ctx.GuildId(), id); err != nil {
ctx.HandleError(err)
return
}
}

blacklistMsg := i18n.MessageBlacklistRemoveRole

if isBlacklisted {
if err := dbclient.Client.RoleBlacklist.Remove(ctx, ctx.GuildId(), id); err != nil {
ctx.HandleError(err)
return
}
} else {
// Limit of 50 *roles*
count, err := dbclient.Client.Blacklist.GetBlacklistedCount(ctx, ctx.GuildId())
if err != nil {
ctx.HandleError(err)
return
}

if count >= 50 {
ctx.Reply(customisation.Red, i18n.Error, i18n.MessageBlacklistRoleLimit, 50)
return
}

if err := dbclient.Client.RoleBlacklist.Add(ctx, ctx.GuildId(), id); err != nil {
ctx.HandleError(err)
return
}
blacklistMsg = i18n.MessageBlacklistAddRole

ctx.Reply(customisation.Green, i18n.TitleBlacklist, i18n.MessageBlacklistAddRole, id)
}
BlacklistCommand{}.sendBlacklistResponse(ctx, id, isBlacklisted, false)
}

ctx.ReplyWith(
command.NewEphemeralMessageResponseWithComponents(
utils.Slice(
utils.BuildContainerRaw(ctx.GetColour(customisation.Green), ctx.GetMessage(i18n.TitleBlacklist), ctx.GetMessage(blacklistMsg, id), ctx.PremiumTier()),
),
),
)
func (BlacklistCommand) sendBlacklistResponse(ctx registry.CommandContext, id uint64, wasBlacklisted, isUser bool) {
blacklistMsg := i18n.MessageBlacklistAdd
if wasBlacklisted {
blacklistMsg = i18n.MessageBlacklistRemove
}

var message string
if isUser {
message = fmt.Sprintf("<@%d> %s", id, ctx.GetMessage(blacklistMsg))
} else {
ctx.HandleError(fmt.Errorf("infallible"))
return
message = fmt.Sprintf("<@&%d> %s", id, ctx.GetMessage(blacklistMsg))
}

ctx.ReplyWith(
command.NewEphemeralMessageResponseWithComponents(
utils.Slice(
utils.BuildContainerRaw(ctx.GetColour(customisation.Green), ctx.GetMessage(i18n.TitleBlacklist), message, ctx.PremiumTier()),
),
),
)
}
6 changes: 3 additions & 3 deletions bot/command/impl/settings/premium.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (PremiumCommand) Execute(ctx registry.CommandContext) {
keyEmoji = utils.BuildEmoji("🔑")
}

components := []component.Component{
innerComponents := []component.Component{
component.BuildSection(component.Section{
Components: utils.Slice(
component.BuildTextDisplay(component.TextDisplay{Content: fmt.Sprintf("## %s", ctx.GetMessage(i18n.TitlePremium))}),
Expand Down Expand Up @@ -152,13 +152,13 @@ func (PremiumCommand) Execute(ctx registry.CommandContext) {
}

if ctx.PremiumTier() == premium.None {
components = utils.AddPremiumFooter(components)
innerComponents = utils.AddPremiumFooter(innerComponents)
}

ctx.ReplyWith(
command.NewEphemeralMessageResponseWithComponents(
utils.Slice(component.BuildContainer(component.Container{
Components: components,
Components: innerComponents,
AccentColor: utils.Ptr(ctx.GetColour(customisation.Green)),
})),
),
Expand Down
Loading