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
43 changes: 43 additions & 0 deletions bot/button/handlers/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package handlers

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

type TestHandler struct{}

func (h *TestHandler) Matcher() matcher.Matcher {
return &matcher.SimpleMatcher{
CustomId: "test_modal",
}
}

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

func (h *TestHandler) Execute(ctx *context.ButtonContext) {
ctx.Modal(button.ResponseModal{
Data: interaction.ModalResponseData{
CustomId: "test_modal",
Title: "Test Modal",
Components: []component.Component{
component.BuildLabel(component.Label{
Label: "Terms & Conditions",
Description: utils.Ptr("Please confirm you accept our terms & conditions"),
Component: component.BuildCheckbox(component.Checkbox{
CustomId: "test_modal_checkbox",
}),
}),
},
},
})
}
1 change: 1 addition & 0 deletions bot/button/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (m *ComponentInteractionManager) RegisterCommands() {
new(handlers.RedeemVoteCreditsHandler),
new(handlers.ViewStaffHandler),
new(handlers.ViewSurveyHandler),
new(handlers.TestHandler),
new(server.AdminDebugServerRecacheHandler),
new(server.AdminDebugServerBlacklistReasonHandler),
new(server.AdminDebugServerEntitlementsHandler),
Expand Down
7 changes: 6 additions & 1 deletion bot/command/impl/general/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (HelpCommand) Properties() registry.Properties {
Category: command.General,
DefaultEphemeral: true,
Timeout: time.Second * 5,
Contexts: []interaction.InteractionContextType{interaction.InteractionContextGuild,interaction.InteractionContextBotDM},
Contexts: []interaction.InteractionContextType{interaction.InteractionContextGuild, interaction.InteractionContextBotDM},
}
}

Expand Down Expand Up @@ -64,6 +64,11 @@ func (c HelpCommand) Execute(ctx registry.CommandContext) {
for _, cmd := range c.Registry {
properties := cmd.Properties()

// hide dev commands
if properties.DevBotOnly {
continue
}

// check bot admin / helper only commands
if (properties.AdminOnly && !utils.IsBotAdmin(ctx.UserId())) || (properties.HelperOnly && !utils.IsBotHelper(ctx.UserId())) {
continue
Expand Down
46 changes: 46 additions & 0 deletions bot/command/impl/general/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package general

import (
"time"

"github.com/TicketsBot-cloud/common/permission"
"github.com/TicketsBot-cloud/gdl/objects/interaction"
"github.com/TicketsBot-cloud/gdl/objects/interaction/component"
"github.com/TicketsBot-cloud/worker/bot/command"
"github.com/TicketsBot-cloud/worker/bot/command/registry"
)

type TestCommand struct {
}

func (TestCommand) Properties() registry.Properties {
return registry.Properties{
Name: "test",
Type: interaction.ApplicationCommandTypeChatInput,
PermissionLevel: permission.Everyone,
Category: command.General,
// AdminOnly: true,
MainBotOnly: true,
DevBotOnly: true,
DefaultEphemeral: true,
Timeout: time.Second * 3,
Contexts: []interaction.InteractionContextType{interaction.InteractionContextGuild},
}
}

func (c TestCommand) GetExecutor() interface{} {
return c.Execute
}

func (TestCommand) Execute(ctx registry.CommandContext) {
// ctx.ReplyRaw(customisation.Green, "Test", "Test")
ctx.ReplyWith(command.NewEphemeralMessageResponseWithComponents([]component.Component{
component.BuildActionRow(
component.BuildButton(component.Button{
Label: "test modal",
CustomId: "test_modal",
Style: component.ButtonStyleDanger,
}),
),
}))
}
7 changes: 6 additions & 1 deletion bot/command/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (cm *CommandManager) RegisterCommands() {

cm.registry["admin"] = admin.AdminCommand{}

cm.registry["test"] = general.TestCommand{}
cm.registry["about"] = general.AboutCommand{}
cm.registry["gdpr"] = general.GDPRCommand{}
cm.registry["invite"] = general.InviteCommand{}
Expand Down Expand Up @@ -77,7 +78,7 @@ func (cm *CommandManager) RunSetupFuncs() {
}
}

func (cm *CommandManager) BuildCreatePayload(isWhitelabel bool, adminCommandGuildId *uint64) (data []rest.CreateCommandData, adminCommands []rest.CreateCommandData) {
func (cm *CommandManager) BuildCreatePayload(isDevBot bool, isWhitelabel bool, adminCommandGuildId *uint64) (data []rest.CreateCommandData, adminCommands []rest.CreateCommandData) {
for _, cmd := range cm.GetCommands() {
properties := cmd.Properties()

Expand All @@ -92,6 +93,10 @@ func (cm *CommandManager) BuildCreatePayload(isWhitelabel bool, adminCommandGuil
description = option.Description
}

if properties.DevBotOnly && !isDevBot {
continue
}

if properties.MainBotOnly && isWhitelabel {
continue
}
Expand Down
1 change: 1 addition & 0 deletions bot/command/registry/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Properties struct {
DisableAutoDefer bool
Timeout time.Duration
IgnoreBlacklist bool
DevBotOnly bool

SetupFunc func()
}
8 changes: 7 additions & 1 deletion cmd/registercommands/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@ var (
GuildId = flag.Uint64("guild", 0, "Guild to create the commands for")
AdminCommandGuildId = flag.Uint64("admin-guild", 0, "Guild to create the admin commands in")
MergeGuildCommands = flag.Bool("merge", true, "Merge new commands with existing ones instead of overwriting")
DevMode = flag.Bool("dev", false, "Enable dev mode")
)

func main() {
devMode := false
flag.Parse()
if *Token == "" {
panic("no token")
}

if DevMode != nil {
devMode = *DevMode
}

applicationId := must(getApplicationId(*Token))

i18n.Init()

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

data, adminCommands := commandManager.BuildCreatePayload(false, AdminCommandGuildId)
data, adminCommands := commandManager.BuildCreatePayload(devMode, false, AdminCommandGuildId)

// Register commands globally or for a specific guild
if *GuildId == 0 {
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type (
Admins []uint64 `env:"WORKER_BOT_ADMINS"`
Helpers []uint64 `env:"WORKER_BOT_HELPERS"`
MonitoredBots []uint64 `env:"MONITORED_BOTS"`
DevMode bool `env:"WORKER_BOT_DEV_MODE" envDefault:"false"`
}

PremiumProxy struct {
Expand Down
3 changes: 3 additions & 0 deletions event/caller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.24.2

//replace github.com/TicketsBot-cloud/database => ../database

//replace github.com/TicketsBot-cloud/gdl => ../gdl
replace github.com/TicketsBot-cloud/gdl => ../gdl

//replace github.com/TicketsBot-cloud/archiverclient => ../archiverclient

Expand Down