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
9 changes: 6 additions & 3 deletions bot/button/handlers/addadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/TicketsBot-cloud/gdl/rest/request"
"github.com/TicketsBot-cloud/worker/bot/button/registry"
"github.com/TicketsBot-cloud/worker/bot/button/registry/matcher"
"github.com/TicketsBot-cloud/worker/bot/command"
"github.com/TicketsBot-cloud/worker/bot/command/context"
"github.com/TicketsBot-cloud/worker/bot/customisation"
"github.com/TicketsBot-cloud/worker/bot/dbclient"
Expand Down Expand Up @@ -119,8 +118,12 @@ func (h *AddAdminHandler) Execute(ctx *context.ButtonContext) {
return
}

e := utils.BuildEmbed(ctx, customisation.Green, i18n.TitleAddAdmin, i18n.MessageAddAdminSuccess, nil)
ctx.Edit(command.NewEphemeralEmbedMessageResponse(e))
ctx.EditWithComponentsOnly(utils.Slice(utils.BuildContainerRaw(
ctx.GetColour(customisation.Green),
ctx.GetMessage(i18n.TitleAddAdmin),
ctx.GetMessage(i18n.MessageAddAdminSuccess),
ctx.PremiumTier(),
)))

settings, err := ctx.Settings()
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions bot/button/handlers/addsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/TicketsBot-cloud/gdl/rest/request"
"github.com/TicketsBot-cloud/worker/bot/button/registry"
"github.com/TicketsBot-cloud/worker/bot/button/registry/matcher"
"github.com/TicketsBot-cloud/worker/bot/command"
"github.com/TicketsBot-cloud/worker/bot/command/context"
cmdregistry "github.com/TicketsBot-cloud/worker/bot/command/registry"
"github.com/TicketsBot-cloud/worker/bot/customisation"
Expand Down Expand Up @@ -121,8 +120,12 @@ func (h *AddSupportHandler) Execute(ctx *context.ButtonContext) {
return
}

e := utils.BuildEmbed(ctx, customisation.Green, i18n.TitleAddSupport, i18n.MessageAddSupportSuccess, nil)
ctx.Edit(command.NewEphemeralEmbedMessageResponse(e))
ctx.EditWithComponentsOnly(utils.Slice(utils.BuildContainerRaw(
ctx.GetColour(customisation.Green),
ctx.GetMessage(i18n.TitleAddSupport),
ctx.GetMessage(i18n.MessageAddSupportSuccess),
ctx.PremiumTier(),
)))

updateChannelPermissions(ctx, id, mentionableType)
}
Expand Down
20 changes: 11 additions & 9 deletions bot/button/handlers/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ func (h *ClaimHandler) Execute(ctx *context.ButtonContext) {
}

res := command.MessageIntoMessageResponse(ctx.Interaction.Message)
if len(res.Components) > 0 && res.Components[0].Type == component.ComponentActionRow {
row := res.Components[0].ComponentData.(component.ActionRow)
if len(row.Components) > 1 {
row.Components = row.Components[:len(row.Components)-1]
}

res.Components[0] = component.Component{
Type: component.ComponentActionRow,
ComponentData: row,
for i, comp := range res.Components {
if comp.Type == component.ComponentActionRow {
row := comp.ComponentData.(component.ActionRow)
if len(row.Components) > 1 {
row.Components = row.Components[:len(row.Components)-1]
}
res.Components[i] = component.Component{
Type: component.ComponentActionRow,
ComponentData: row,
}
break
}
}

Expand Down
29 changes: 12 additions & 17 deletions bot/button/handlers/close.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package handlers

import (
"github.com/TicketsBot-cloud/gdl/objects/channel/embed"
"fmt"

"github.com/TicketsBot-cloud/gdl/objects/interaction/component"
"github.com/TicketsBot-cloud/worker/bot/button/registry"
"github.com/TicketsBot-cloud/worker/bot/button/registry/matcher"
Expand Down Expand Up @@ -56,23 +57,17 @@ func (h *CloseHandler) Execute(ctx *cmdcontext.ButtonContext) {
}

if closeConfirmation {
// Send confirmation message
confirmEmbed := utils.BuildEmbed(ctx, customisation.Green, i18n.TitleCloseConfirmation, i18n.MessageCloseConfirmation, nil)
confirmEmbed.SetAuthor(ctx.InteractionUser().Username, "", utils.Ptr(ctx.InteractionUser()).AvatarUrl(256))

msgData := command.MessageResponse{
Embeds: []*embed.Embed{confirmEmbed},
Components: []component.Component{
component.BuildActionRow(component.BuildButton(component.Button{
Label: ctx.GetMessage(i18n.TitleClose),
CustomId: "close_confirm",
Style: component.ButtonStylePrimary,
Emoji: utils.BuildEmoji("✔️"),
})),
},
}
container := utils.BuildContainerWithComponents(ctx, customisation.Green, i18n.TitleCloseConfirmation, []component.Component{
component.BuildTextDisplay(component.TextDisplay{Content: fmt.Sprintf("<@%d>: %s", ctx.InteractionUser().Id, ctx.GetMessage(i18n.MessageCloseConfirmation))}),
component.BuildActionRow(component.BuildButton(component.Button{
Label: ctx.GetMessage(i18n.TitleClose),
CustomId: "close_confirm",
Style: component.ButtonStylePrimary,
Emoji: utils.BuildEmoji("✔️"),
})),
})

if _, err := ctx.ReplyWith(msgData); err != nil {
if _, err := ctx.ReplyWith(command.NewMessageResponseWithComponents(utils.Slice(container))); err != nil {
ctx.HandleError(err)
return
}
Expand Down
5 changes: 1 addition & 4 deletions bot/button/handlers/closerequestaccept.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handlers

import (
"github.com/TicketsBot-cloud/common/premium"
"github.com/TicketsBot-cloud/worker/bot/button/registry"
"github.com/TicketsBot-cloud/worker/bot/button/registry/matcher"
"github.com/TicketsBot-cloud/worker/bot/command"
Expand Down Expand Up @@ -57,9 +56,7 @@ func (h *CloseRequestAcceptHandler) Execute(ctx *context.ButtonContext) {
return
}

ctx.Edit(command.MessageResponse{
Embeds: utils.Slice(utils.BuildEmbedRaw(customisation.DefaultColours[customisation.Green], "Close Request", "Closing ticket...", nil, premium.Whitelabel)), // TODO: Translations, calculate premium level
})
ctx.Edit(command.NewMessageResponseWithComponents(utils.Slice(utils.BuildContainerRaw(ctx.GetColour(customisation.Green), "Close Request", "Closing ticket...", ctx.PremiumTier()))))

// Avoid users cant close issue
// Allow members to close too, for context menu tickets
Expand Down
4 changes: 1 addition & 3 deletions bot/button/handlers/closerequestdeny.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,5 @@ func (h *CloseRequestDenyHandler) Execute(ctx *context.ButtonContext) {
return
}

ctx.Edit(command.MessageResponse{
Embeds: utils.Embeds(utils.BuildEmbed(ctx, customisation.Red, i18n.TitleCloseRequest, i18n.MessageCloseRequestDenied, nil, ctx.UserId())),
})
ctx.Edit(command.NewMessageResponseWithComponents(utils.Slice(utils.BuildContainer(ctx, customisation.Red, i18n.TitleCloseRequest, i18n.MessageCloseRequestDenied, ctx.UserId()))))
}
2 changes: 1 addition & 1 deletion bot/button/handlers/exitsurveysubmit.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,5 @@ func addViewFeedbackButton(ctx context.Context, cmd *cmdcontext.ModalContext, ti
return fmt.Errorf("exit survey was completed, but no rating was found (%d:%d)", ticket.GuildId, ticket.Id)
}

return logic.EditGuildArchiveMessageIfExists(ctx, cmd.Worker(), ticket, settings, true, closedBy, reason, &rating)
return logic.EditGuildArchiveMessageIfExists(ctx, cmd, cmd.Worker(), ticket, settings, true, closedBy, reason, &rating)
}
78 changes: 78 additions & 0 deletions bot/button/handlers/help_category.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package handlers

import (
"math"
"strings"

"github.com/TicketsBot-cloud/gdl/objects/interaction/component"
"github.com/TicketsBot-cloud/worker/bot/button/registry"
"github.com/TicketsBot-cloud/worker/bot/button/registry/matcher"
"github.com/TicketsBot-cloud/worker/bot/command"
"github.com/TicketsBot-cloud/worker/bot/command/context"
"github.com/TicketsBot-cloud/worker/bot/command/manager"
"github.com/TicketsBot-cloud/worker/bot/logic"
)

type HelpCategoryHandler struct{}

func (h *HelpCategoryHandler) Matcher() matcher.Matcher {
return &matcher.FuncMatcher{
Func: func(customId string) bool {
return strings.HasPrefix(customId, "help_")
},
}
}

func (h *HelpCategoryHandler) Properties() registry.Properties {
return registry.Properties{
Flags: registry.SumFlags(registry.GuildAllowed),
}
}

func (h *HelpCategoryHandler) Execute(ctx *context.SelectMenuContext) {
if len(ctx.InteractionData.Values) == 0 {
return
}

commandManager := new(manager.CommandManager)
commandManager.RegisterCommands()

helpCategoryCustomId := ctx.InteractionData.Values[0]

helpCategory := command.General

switch helpCategoryCustomId {
case "help_general":
helpCategory = command.General
case "help_tickets":
helpCategory = command.Tickets
case "help_settings":
helpCategory = command.Settings
case "help_tags":
helpCategory = command.Tags
case "help_statistics":
helpCategory = command.Statistics
default:
return
}

container, err := logic.BuildHelpMessage(helpCategory, 1, ctx, commandManager.GetCommands())
if err != nil {
ctx.HandleError(err)
return
}

// get commands in selected category
commands := commandManager.GetCommandByCategory(helpCategory)
pageCount := float64(len(commands)) / float64(5)

if pageCount == 0 {
pageCount = 1
}

ctx.Edit(command.NewEphemeralMessageResponseWithComponents([]component.Component{
*container,
*logic.BuildHelpMessagePaginationButtons(helpCategory.ToRawString(), 1, int(math.Ceil(pageCount))),
*logic.BuildHelpMessageCategorySelector(commandManager.GetCommands(), ctx, helpCategory),
}))
}
83 changes: 83 additions & 0 deletions bot/button/handlers/help_page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package handlers

import (
"math"
"strconv"
"strings"

"github.com/TicketsBot-cloud/gdl/objects/interaction/component"
"github.com/TicketsBot-cloud/worker/bot/button/registry"
"github.com/TicketsBot-cloud/worker/bot/button/registry/matcher"
"github.com/TicketsBot-cloud/worker/bot/command"
"github.com/TicketsBot-cloud/worker/bot/command/context"
"github.com/TicketsBot-cloud/worker/bot/command/manager"
"github.com/TicketsBot-cloud/worker/bot/logic"
)

type HelpPageHandler struct{}

func (h *HelpPageHandler) Matcher() matcher.Matcher {
return &matcher.FuncMatcher{
Func: func(customId string) bool {
return strings.HasPrefix(customId, "helppage_")
},
}
}

func (h *HelpPageHandler) Properties() registry.Properties {
return registry.Properties{
Flags: registry.SumFlags(registry.GuildAllowed),
}
}

func (h *HelpPageHandler) Execute(ctx *context.ButtonContext) {
if ctx.InteractionData.CustomId == "" {
return
}

var (
customIdParts = strings.Split(ctx.InteractionData.CustomId, "_")
category = customIdParts[1]
page, _ = strconv.ParseInt(customIdParts[2], 10, 64)
)

commandManager := new(manager.CommandManager)
commandManager.RegisterCommands()

helpCategory := command.General

switch category {
case "general":
helpCategory = command.General
case "tickets":
helpCategory = command.Tickets
case "settings":
helpCategory = command.Settings
case "tags":
helpCategory = command.Tags
case "statistics":
helpCategory = command.Statistics
default:
return
}

container, err := logic.BuildHelpMessage(helpCategory, int(page), ctx, commandManager.GetCommands())
if err != nil {
ctx.HandleError(err)
return
}

// get commands in selected category
commands := commandManager.GetCommandByCategory(helpCategory)
pageCount := float64(len(commands)) / float64(5)

if pageCount == 0 {
pageCount = 1
}

ctx.Edit(command.NewEphemeralMessageResponseWithComponents([]component.Component{
*container,
*logic.BuildHelpMessagePaginationButtons(helpCategory.ToRawString(), int(page), int(math.Ceil(pageCount))),
*logic.BuildHelpMessageCategorySelector(commandManager.GetCommands(), ctx, helpCategory),
}))
}
2 changes: 1 addition & 1 deletion bot/button/handlers/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (h *RateHandler) Execute(ctx *cmdcontext.ButtonContext) {
return
}

if err := logic.EditGuildArchiveMessageIfExists(ctx, ctx.Worker(), ticket, settings, hasFeedback, closedBy, reason, &rating); err != nil {
if err := logic.EditGuildArchiveMessageIfExists(ctx, ctx, ctx.Worker(), ticket, settings, hasFeedback, closedBy, reason, &rating); err != nil {
ctx.HandleError(err)
}
}
Loading