feat(commands): improve discovery and normalize parameters

This commit is contained in:
tiennm99 committed 2026-07-21 11:45:20 +07:00
1 parent 3316eec74c
commit f5ba9d4032
31 files changed
+479 -56

No files matched your search

+2 -2
View File
@@ -142,8 +142,8 @@ func TestWheelOfNames_UsageWhenMissingOptions(t *testing.T) {
rb, _ := installMisc(t, 999)
rb.Bot.ProcessUpdate(context.Background(), testutil.NewPrivateMessage(7, text))
if got := rb.LastSent().Text(); got != wheelOfNamesUsage {
t.Errorf("wheelofnames reply = %q, want usage %q", got, wheelOfNamesUsage)
if got := rb.LastSent().Text(); got != wheelUsage {
t.Errorf("wheelofnames reply = %q, want usage %q", got, wheelUsage)
}
})
}
+8
View File
@@ -128,10 +128,18 @@ func senderMention(u *models.User) string {
}
func disclaimerCommand(name, description, defaultTarget string, allowCustomTarget bool) modules.Command {
parameters := ""
example := ""
if allowCustomTarget {
parameters = "[target...]"
example = "/" + name + " FBI"
}
return modules.Command{
Name: name,
Visibility: modules.VisibilityPublic,
Description: description,
Parameters: parameters,
Example: example,
Handler: func(ctx context.Context, b *bot.Bot, update *models.Update) error {
if update.Message == nil {
return nil
+3 -1
View File
@@ -12,7 +12,7 @@ import (
"github.com/tiennm99/miti99bot/internal/modules/util/chathelper"
)
const randomUsage = "Usage: /random <option1>, <option2>, ..."
const randomUsage = "Usage: /random <options(comma-separated)>"
func splitWheelOptions(arg string) []string {
parts := strings.Split(arg, ",")
@@ -30,6 +30,8 @@ func randomCommand() modules.Command {
Name: "random",
Visibility: modules.VisibilityPublic,
Description: "Pick one random comma-separated option",
Parameters: "<options(comma-separated)>",
Example: "/random pizza, sushi, pho",
Handler: func(ctx context.Context, b *bot.Bot, update *models.Update) error {
if update.Message == nil {
return nil
@@ -15,7 +15,6 @@ import (
)
const (
wheelOfNamesUsage = "Usage: /wheelofnames <option1>, <option2>, ..."
wheelFilename = "wheelofnames.gif"
wheelResultCaptionMaxRunes = 900
)
@@ -25,13 +24,15 @@ func wheelOfNamesCommand() modules.Command {
Name: "wheelofnames",
Visibility: modules.VisibilityPublic,
Description: "Pick one comma-separated option with wheel GIF when configured",
Parameters: "<options(comma-separated)>",
Example: "/wheelofnames pizza, sushi, pho",
Handler: func(ctx context.Context, b *bot.Bot, update *models.Update) error {
if update.Message == nil {
return nil
}
options := splitWheelOptions(chathelper.ArgAfterCommand(update.Message.Text))
if len(options) == 0 {
return chathelper.Reply(ctx, b, update.Message, wheelOfNamesUsage)
return chathelper.Reply(ctx, b, update.Message, wheelUsage)
}
winner := pickWheelOption(options)
animation, err := renderWheelOfNamesAnimation(ctx, options, winner)
@@ -63,6 +64,8 @@ func wheelOfNamesCommand() modules.Command {
}
}
const wheelUsage = "Usage: /wheelofnames <options(comma-separated)>"
func wheelResultCaption(result string) string {
result = truncateWheelResultCaption(result)
return `Result: <span class="tg-spoiler">` + html.EscapeString(result) + `</span>`