diff --git a/bot/button/handlers/test.go b/bot/button/handlers/test.go new file mode 100644 index 0000000..4337311 --- /dev/null +++ b/bot/button/handlers/test.go @@ -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", + }), + }), + }, + }, + }) +} diff --git a/bot/button/manager/manager.go b/bot/button/manager/manager.go index 977b9b1..92d8904 100644 --- a/bot/button/manager/manager.go +++ b/bot/button/manager/manager.go @@ -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), diff --git a/bot/command/impl/general/help.go b/bot/command/impl/general/help.go index 144f9c3..28d662a 100644 --- a/bot/command/impl/general/help.go +++ b/bot/command/impl/general/help.go @@ -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}, } } @@ -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 diff --git a/bot/command/impl/general/test.go b/bot/command/impl/general/test.go new file mode 100644 index 0000000..c369b13 --- /dev/null +++ b/bot/command/impl/general/test.go @@ -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, + }), + ), + })) +} diff --git a/bot/command/manager/manager.go b/bot/command/manager/manager.go index d4c3baa..73a79d2 100644 --- a/bot/command/manager/manager.go +++ b/bot/command/manager/manager.go @@ -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{} @@ -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() @@ -92,6 +93,10 @@ func (cm *CommandManager) BuildCreatePayload(isWhitelabel bool, adminCommandGuil description = option.Description } + if properties.DevBotOnly && !isDevBot { + continue + } + if properties.MainBotOnly && isWhitelabel { continue } diff --git a/bot/command/registry/properties.go b/bot/command/registry/properties.go index 999ba3d..c38ef23 100644 --- a/bot/command/registry/properties.go +++ b/bot/command/registry/properties.go @@ -29,6 +29,7 @@ type Properties struct { DisableAutoDefer bool Timeout time.Duration IgnoreBlacklist bool + DevBotOnly bool SetupFunc func() } diff --git a/cmd/registercommands/main.go b/cmd/registercommands/main.go index 3ae3f23..fa82108 100644 --- a/cmd/registercommands/main.go +++ b/cmd/registercommands/main.go @@ -19,14 +19,20 @@ 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() @@ -34,7 +40,7 @@ func main() { 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 { diff --git a/config/config.go b/config/config.go index a3c7f2a..c8a1776 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/event/caller.go b/event/caller.go index f8a6c32..e47c3dc 100644 --- a/event/caller.go +++ b/event/caller.go @@ -198,6 +198,9 @@ func callCommand( } v.Execute(ctx, arg0) + case general.TestCommand: + + v.Execute(ctx) case general.AboutCommand: v.Execute(ctx) diff --git a/go.mod b/go.mod index 0f32d12..f169ecf 100644 --- a/go.mod +++ b/go.mod @@ -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