From 3d8854b8382146690be696abec42889aa60450f2 Mon Sep 17 00:00:00 2001 From: shaoying Date: Mon, 29 Jun 2020 11:40:00 +0800 Subject: [PATCH] opt mdb --- base/mdb/render.go | 10 +++---- base/mdb/search.go | 72 ++++++---------------------------------------- type.go | 3 ++ 3 files changed, 17 insertions(+), 68 deletions(-) diff --git a/base/mdb/render.go b/base/mdb/render.go index 88a42e89..c71776ba 100644 --- a/base/mdb/render.go +++ b/base/mdb/render.go @@ -13,13 +13,13 @@ func init() { RENDER: {Name: "render", Help: "渲染引擎", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TYPE)}, }, Commands: map[string]*ice.Command{ - RENDER: {Name: "search type name text arg...", Help: "渲染引擎", Action: map[string]*ice.Action{ - CREATE: {Name: "create type name [text]", Help: "创建", Hand: func(m *ice.Message, arg ...string) { - m.Rich(RENDER, nil, kit.Dict(kit.MDB_TYPE, arg[0], kit.MDB_NAME, arg[1], kit.MDB_TEXT, kit.Select("", arg, 2))) + RENDER: {Name: "render type name text arg...", Help: "渲染引擎", Action: map[string]*ice.Action{ + CREATE: {Name: "create type [cmd [ctx]]", Help: "创建", Hand: func(m *ice.Message, arg ...string) { + m.Rich(RENDER, nil, kit.Dict(kit.MDB_TYPE, arg[0], kit.MDB_NAME, kit.Select(arg[0], arg, 1), kit.MDB_TEXT, kit.Select("", arg, 2))) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Richs(RENDER, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) { - m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), arg[0], arg[1], kit.Select("", arg, 2)) + m.Richs(RENDER, nil, arg[0], func(key string, value map[string]interface{}) { + m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), RENDER, arg[0], arg[1], kit.Select("", arg, 2)) }) }}, }}, nil) diff --git a/base/mdb/search.go b/base/mdb/search.go index 796dbf87..ffc7e52f 100644 --- a/base/mdb/search.go +++ b/base/mdb/search.go @@ -15,12 +15,17 @@ func init() { SEARCH: {Name: "search", Help: "搜索引擎", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TYPE)}, }, Commands: map[string]*ice.Command{ - SEARCH: {Name: "search word type...", Help: "搜索引擎", Action: map[string]*ice.Action{ - CREATE: {Name: "create type name [text]", Help: "创建", Hand: func(m *ice.Message, arg ...string) { - m.Rich(SEARCH, nil, kit.Dict(kit.MDB_TYPE, arg[0], kit.MDB_NAME, arg[1], kit.MDB_TEXT, kit.Select("", arg, 2))) + SEARCH: {Name: "search word text type...", Help: "搜索引擎", Action: map[string]*ice.Action{ + CREATE: {Name: "create type [cmd [ctx]]", Help: "创建", Hand: func(m *ice.Message, arg ...string) { + m.Rich(SEARCH, nil, kit.Dict(kit.MDB_TYPE, arg[0], kit.MDB_NAME, kit.Select(arg[0], arg, 1), kit.MDB_TEXT, kit.Select("", arg, 2))) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - + if len(arg) == 0 || arg[0] == "" { + m.Richs(SEARCH, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) { + m.Push(key, value, []string{kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT}) + }) + return + } if strings.Contains(arg[0], ";") { arg = strings.Split(arg[0], ";") } @@ -35,65 +40,6 @@ func init() { m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, value[kit.MDB_TYPE], arg[0], kit.Select("", arg, 1)) }) } - - return - if len(arg) < 2 { - m.Cmdy("web.label", arg) - return - } - - switch arg[0] { - case "add": - if m.Richs(cmd, nil, arg[1], nil) == nil { - m.Rich(cmd, nil, kit.Data(kit.MDB_NAME, arg[1])) - } - m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) { - m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), kit.Dict( - kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3:], - )) - }) - case "get": - wg := &sync.WaitGroup{} - m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) { - wg.Add(1) - m.Gos(m, func(m *ice.Message) { - m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { - m.Cmdy(value[kit.MDB_TEXT], arg[2:]) - }) - wg.Done() - }) - }) - wg.Wait() - case "set": - if arg[1] != "" { - m.Cmdy("web.space", arg[1], "web.chat.search", "set", "", arg[2:]) - break - } - - m.Richs(cmd, nil, arg[2], func(key string, value map[string]interface{}) { - m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { - m.Cmdy(value[kit.MDB_TEXT], "set", arg[3:]) - }) - }) - default: - if len(arg) < 4 { - m.Richs(cmd, nil, kit.Select(kit.MDB_FOREACH, arg, 2), func(key string, val map[string]interface{}) { - if len(arg) < 3 { - m.Push(key, val[kit.MDB_META], []string{kit.MDB_TIME, kit.MDB_NAME, kit.MDB_COUNT}) - return - } - m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { - m.Push("", value, []string{kit.MDB_TIME}) - m.Push("group", arg[2]) - m.Push("", value, []string{kit.MDB_NAME, kit.MDB_TEXT}) - }) - }) - break - } - m.Option("pod", "") - m.Cmdy("web.label", arg[0], arg[1], "web.chat.search", "get", arg[2:]) - m.Sort("time", "time_r") - } }}, "commend": {Name: "commend label pod engine work auto", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) < 2 { diff --git a/type.go b/type.go index b883ed09..7e4299a9 100644 --- a/type.go +++ b/type.go @@ -109,6 +109,9 @@ func (c *Context) cmd(m *Message, cmd *Command, key string, arg ...string) *Mess } } + if len(arg) > 0 && arg[0] == "render" { + arg = arg[1:] + } m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(cmd.Hand, 3)) cmd.Hand(m, c, key, arg...) return m