l10n and bot command auto generation; v0.6.0

This commit is contained in:
2026-02-18 11:39:27 +03:00
parent b2bda02c0f
commit 746847cf61
2 changed files with 9 additions and 1 deletions

View File

@@ -27,6 +27,9 @@ func generateBotCommand(cmd Command) tgapi.BotCommand {
func generateBotCommandForPlugin(pl Plugin) []tgapi.BotCommand { func generateBotCommandForPlugin(pl Plugin) []tgapi.BotCommand {
commands := make([]tgapi.BotCommand, 0) commands := make([]tgapi.BotCommand, 0)
for _, cmd := range pl.Commands { for _, cmd := range pl.Commands {
if cmd.skipAutoCmd {
continue
}
commands = append(commands, generateBotCommand(cmd)) commands = append(commands, generateBotCommand(cmd))
} }
return commands return commands

View File

@@ -52,10 +52,11 @@ type Command struct {
exec CommandExecutor exec CommandExecutor
args extypes.Slice[CommandArg] args extypes.Slice[CommandArg]
middlewares extypes.Slice[Middleware] middlewares extypes.Slice[Middleware]
skipAutoCmd bool
} }
func NewCommand(exec CommandExecutor, command string, args ...CommandArg) *Command { func NewCommand(exec CommandExecutor, command string, args ...CommandArg) *Command {
return &Command{command, "", exec, args, make(extypes.Slice[Middleware], 0)} return &Command{command, "", exec, args, make(extypes.Slice[Middleware], 0), false}
} }
func (c *Command) Use(m Middleware) *Command { func (c *Command) Use(m Middleware) *Command {
c.middlewares = c.middlewares.Push(m) c.middlewares = c.middlewares.Push(m)
@@ -65,6 +66,10 @@ func (c *Command) SetDescription(desc string) *Command {
c.description = desc c.description = desc
return c return c
} }
func (c *Command) SkipCommandAutoGen() *Command {
c.skipAutoCmd = true
return c
}
func (c *Command) validateArgs(args []string) error { func (c *Command) validateArgs(args []string) error {
cmdArgs := c.args.Filter(func(e CommandArg) bool { return !e.required }) cmdArgs := c.args.Filter(func(e CommandArg) bool { return !e.required })
if len(args) < cmdArgs.Len() { if len(args) < cmdArgs.Len() {