fix: keep only setting command entries

This commit is contained in:
姚章浩
2026-08-14 12:35:33 +08:00
parent 19ed4b50df
commit 18c81232ce
4 changed files with 24 additions and 16 deletions
+1 -4
View File
@@ -77,9 +77,6 @@ func (c *Controller) Handle(ctx context.Context, in SettingInput) (string, error
action = s.PendingAction
args = []string{action, strings.TrimSpace(in.Text)}
}
if explicit && cmd.Name == "/help" {
return "设置回答语言:/setting language <auto|zh-CN|en|ja|ko|es>\n例如:/setting language en", nil
}
if explicit && len(args) == 1 && len(args[0]) == 6 && allDigits(args[0]) {
if strings.TrimSpace(in.ConversationType) != "direct" {
return "管理员绑定码只能私聊机器人使用。", nil
@@ -162,7 +159,7 @@ func (c *Controller) Handle(ctx context.Context, in SettingInput) (string, error
}
func settingMenu(admin, direct bool) string {
menu := "⚙️ 个人设置\n" +
menu := "⚙️ 个人设置\n入口:/setting 或 /设置\n" +
"回答语言:/setting language <auto|zh-CN|en|ja|ko|es>\n" +
"- auto:跟随当前提问语言(推荐)\n" +
"- zh-CN:简体中文\n" +
+20 -6
View File
@@ -159,19 +159,33 @@ func TestControllerExplicitlyTestsAndActivatesSupportGroup(t *testing.T) {
t.Fatalf("reply=%q", out)
}
}
func TestControllerHelpIsHandledLocally(t *testing.T) {
func TestControllerOnlyHandlesSettingEntrypoints(t *testing.T) {
r := newMemoryRepo()
c := NewController(r)
if !c.ShouldHandle(context.Background(), "t", "u", "/help") {
t.Fatal("help must be intercepted before QA")
if c.ShouldHandle(context.Background(), "t", "u", "/help") {
t.Fatal("help must not enter the settings controller")
}
out, err := c.Handle(context.Background(), SettingInput{TenantKey: "t", StaffID: "u", Text: "/help", ConversationType: "direct"})
if err != nil {
t.Fatal(err)
}
want := "设置回答语言:/setting language <auto|zh-CN|en|ja|ko|es>\n例如:/setting language en"
if out != want {
t.Fatalf("help=%q want %q", out, want)
if out != "" {
t.Fatalf("help reply=%q must be empty", out)
}
}
func TestControllerChineseSettingAliasRunsSubcommands(t *testing.T) {
r := newMemoryRepo()
c := NewController(r)
if !c.ShouldHandle(context.Background(), "t", "u", "/设置 language ja") {
t.Fatal("Chinese setting alias must be handled")
}
out, err := c.Handle(context.Background(), SettingInput{TenantKey: "t", Channel: "dingtalk", StaffID: "u", Text: "/设置 language ja", ConversationType: "direct"})
if err != nil {
t.Fatal(err)
}
if r.prefs["t/u"] != "ja" || !strings.Contains(out, "ja") {
t.Fatalf("pref=%q reply=%q", r.prefs["t/u"], out)
}
}
+1 -4
View File
@@ -53,12 +53,9 @@ func ParseCommand(raw string) (Command, bool) {
if len(fields) == 0 {
return Command{}, false
}
if strings.HasPrefix(fields[0], "//") {
fields[0] = "/" + strings.TrimLeft(fields[0], "/")
}
name := strings.ToLower(fields[0])
switch name {
case "/setting", "/settings", "/设置", "/help":
case "/setting", "/设置":
default:
return Command{}, false
}
+2 -2
View File
@@ -29,13 +29,13 @@ func TestDetermineState(t *testing.T) {
}
func TestParseCommandStrict(t *testing.T) {
yes := []string{"/setting", "//setting", "/settings", "/设置", "/help", "//help", "/setting 123456", "/setting language ja", "//setting language en", "/setting support", "/setting question https://alidocs.dingtalk.com/i/nodes/abc"}
yes := []string{"/setting", "/设置", "/setting 123456", "/设置 123456", "/setting language ja", "/设置 language ja", "/setting support", "/设置 question https://alidocs.dingtalk.com/i/nodes/abc"}
for _, raw := range yes {
if c, ok := ParseCommand(raw); !ok || c.Name == "" {
t.Fatalf("must match %q", raw)
}
}
no := []string{"如何设置机器人", "abc /setting", "请解释/setting", "/settiing"}
no := []string{"/help", "//help", "/settings", "//setting", "如何设置机器人", "abc /setting", "请解释/setting", "/settiing"}
for _, raw := range no {
if _, ok := ParseCommand(raw); ok {
t.Fatalf("must not match %q", raw)