fix: route help and repeated-slash settings locally
This commit is contained in:
@@ -76,6 +76,9 @@ 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 "📖 使用帮助:\n• 直接发送问题:普通提问\n• /setting:查看个人设置\n• /setting language <auto|zh-CN|en|ja|ko|es>:设置回答语言\n• /help:查看本帮助", nil
|
||||
}
|
||||
if explicit && len(args) == 1 && len(args[0]) == 6 && allDigits(args[0]) {
|
||||
if strings.TrimSpace(in.ConversationType) != "direct" {
|
||||
return "管理员绑定码只能私聊机器人使用。", nil
|
||||
|
||||
@@ -80,6 +80,23 @@ func TestControllerBindsAdminSupportGroup(t *testing.T) {
|
||||
t.Fatalf("binding=%+v", r.bindings)
|
||||
}
|
||||
}
|
||||
func TestControllerHelpIsHandledLocally(t *testing.T) {
|
||||
r := newMemoryRepo()
|
||||
c := NewController(r)
|
||||
if !c.ShouldHandle(context.Background(), "t", "u", "/help") {
|
||||
t.Fatal("help must be intercepted before QA")
|
||||
}
|
||||
out, err := c.Handle(context.Background(), SettingInput{TenantKey: "t", StaffID: "u", Text: "/help", ConversationType: "direct"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{"普通提问", "/setting", "/help"} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("help=%q missing %q", out, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerParsesAdminQuestionTable(t *testing.T) {
|
||||
r := newMemoryRepo()
|
||||
r.admins["t/a"] = true
|
||||
|
||||
@@ -53,9 +53,12 @@ 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", "/设置":
|
||||
case "/setting", "/settings", "/设置", "/help":
|
||||
default:
|
||||
return Command{}, false
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestDetermineState(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseCommandStrict(t *testing.T) {
|
||||
yes := []string{"/setting", "/settings", "/设置", "/setting 123456", "/setting language ja", "/setting support", "/setting question https://alidocs.dingtalk.com/i/nodes/abc"}
|
||||
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"}
|
||||
for _, raw := range yes {
|
||||
if c, ok := ParseCommand(raw); !ok || c.Name == "" {
|
||||
t.Fatalf("must match %q", raw)
|
||||
|
||||
Reference in New Issue
Block a user