REPOSITORY / ScuroNeko/Laniakea

Pull Requests

PULL REQUESTS REPOSITORY

v1.0.0 #9

Merged
ScuroNeko merged 101 commits from dev into main 2026-05-20 13:43:34 +03:00
4 changed files with 22 additions and 6 deletions
Showing only changes of commit eda635e72c - Show all commits
+1 -1
View File
@@ -10,7 +10,7 @@ import (
)
// CmdRegexp matches command names allowed for Telegram command registration.
var CmdRegexp = regexp.MustCompile("^[a-zA-Z0-9]+$")
var CmdRegexp = regexp.MustCompile("^[_a-z0-9]+$")
// ErrTooManyCommands is returned when the total number of registered commands
// exceeds Telegram's limit of 100 bot commands per bot.
+4 -4
View File
@@ -127,10 +127,10 @@ func (c *Command[T]) SkipCommandAutoGen() *Command[T] {
// Returns ErrCmdArgCountMismatch if too few arguments are provided.
// Returns ErrCmdArgRegexpMismatch if any argument fails regex validation.
func (c *Command[T]) validateArgs(args []string) error {
// Count required args
requiredCount := c.args.Filter(func(a CommandArg) bool { return a.required }).Len()
if len(args) < requiredCount {
return ErrCmdArgCountMismatch
for i := range c.args.Len() {
if i >= len(args) && c.args.Get(i).required {
return ErrCmdArgCountMismatch
}
}
// Validate each argument against its regex
+16
View File
@@ -22,3 +22,19 @@ func TestValidateArgsRequiresFullMatch(t *testing.T) {
t.Fatalf("expected ErrCmdArgRegexpMismatch for partial bool match, got %v", err)
}
}
func TestValidateArgsEnforcesRequiredArgIndex(t *testing.T) {
cmd := NewCommand[NoDB](
func(ctx *MsgContext, db *NoDB) {},
"mixed",
*NewCommandArg("optional"),
*NewCommandArg("required").SetRequired(),
)
if err := cmd.validateArgs([]string{"only-optional"}); !errors.Is(err, ErrCmdArgCountMismatch) {
t.Fatalf("expected ErrCmdArgCountMismatch when required second arg is missing, got %v", err)
}
if err := cmd.validateArgs([]string{"optional", "required"}); err != nil {
t.Fatalf("expected both args to validate, got %v", err)
}
}
+1 -1
View File
@@ -244,7 +244,7 @@ func (api *API) RemoveMyProfilePhotoWithContext(ctx context.Context) (bool, erro
// SetChatMenuButtonP holds parameters for the setChatMenuButton method.
// See https://core.telegram.org/bots/api#setchatmenubutton
type SetChatMenuButtonP struct {
ChatID int64 `json:"chat_id"`
ChatID int64 `json:"chat_id,omitempty"`
MenuButton MenuButtonType `json:"menu_button"`
}