forked from x/icebergs
opt search
This commit is contained in:
parent
855aaac279
commit
20ebcc4754
@ -119,7 +119,6 @@ func init() {
|
|||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
USER: {Name: "user username auto create", Help: "用户", Action: ice.MergeAction(map[string]*ice.Action{
|
USER: {Name: "user username auto create", Help: "用户", Action: ice.MergeAction(map[string]*ice.Action{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey())
|
|
||||||
UserRoot(ice.Pulse)
|
UserRoot(ice.Pulse)
|
||||||
}},
|
}},
|
||||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
@ -80,9 +80,6 @@ const COMMAND = "command"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||||
COMMAND: {Name: "command key auto", Help: "命令", Action: map[string]*ice.Action{
|
COMMAND: {Name: "command key auto", Help: "命令", Action: map[string]*ice.Action{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey())
|
|
||||||
}},
|
|
||||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
if arg[0] == m.CommandKey() || len(arg) > 1 && arg[1] != "" {
|
if arg[0] == m.CommandKey() || len(arg) > 1 && arg[1] != "" {
|
||||||
_command_search(m, arg[0], kit.Select("", arg, 1), kit.Select("", arg, 2))
|
_command_search(m, arg[0], kit.Select("", arg, 1), kit.Select("", arg, 2))
|
||||||
|
@ -235,7 +235,6 @@ func init() {
|
|||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
DIR: {Name: "dir path field... auto upload", Help: "目录", Action: map[string]*ice.Action{
|
DIR: {Name: "dir path field... auto upload", Help: "目录", Action: map[string]*ice.Action{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey())
|
|
||||||
m.Cmd(mdb.RENDER, mdb.CREATE, m.CommandKey(), m.PrefixKey())
|
m.Cmd(mdb.RENDER, mdb.CREATE, m.CommandKey(), m.PrefixKey())
|
||||||
}},
|
}},
|
||||||
mdb.SEARCH: {Name: "search type name", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
mdb.SEARCH: {Name: "search type name", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
@ -56,6 +56,12 @@ func _serve_udp(m *ice.Message, host, port string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func _broad_search(m *ice.Message, kind, name, text string, arg ...string) {
|
||||||
|
m.Richs(BROAD, nil, mdb.FOREACH, func(key string, value map[string]interface{}) {
|
||||||
|
value = kit.GetMeta(value)
|
||||||
|
m.PushSearch(mdb.TYPE, "friend", mdb.TEXT, kit.Format("http://%s:%s", value[tcp.HOST], value[tcp.PORT]), value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const BROAD = "broad"
|
const BROAD = "broad"
|
||||||
|
|
||||||
@ -70,7 +76,6 @@ func init() {
|
|||||||
kit.Format("http://%s:%s", m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
kit.Format("http://%s:%s", m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
||||||
m.Cmd(SPACE, tcp.DIAL, m.OptionSimple(ice.DEV))
|
m.Cmd(SPACE, tcp.DIAL, m.OptionSimple(ice.DEV))
|
||||||
}},
|
}},
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf(BROAD, "", "") }},
|
|
||||||
}, mdb.HashAction(
|
}, mdb.HashAction(
|
||||||
mdb.SHORT, "host,port", mdb.FIELD, "time,hash,host,port",
|
mdb.SHORT, "host,port", mdb.FIELD, "time,hash,host,port",
|
||||||
)), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
)), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
@ -258,6 +258,7 @@ func _space_fork(m *ice.Message) {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
CHROME = "chrome"
|
CHROME = "chrome"
|
||||||
|
FRIEND = "friend"
|
||||||
MASTER = "master"
|
MASTER = "master"
|
||||||
MYSELF = "myself"
|
MYSELF = "myself"
|
||||||
SERVER = "server"
|
SERVER = "server"
|
||||||
@ -284,11 +285,11 @@ func init() {
|
|||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
SPACE: {Name: "space name cmd auto invite", Help: "空间站", Action: ice.MergeAction(map[string]*ice.Action{
|
SPACE: {Name: "space name cmd auto invite", Help: "空间站", Action: ice.MergeAction(map[string]*ice.Action{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey())
|
|
||||||
m.Conf(SPACE, mdb.HASH, "")
|
m.Conf(SPACE, mdb.HASH, "")
|
||||||
}},
|
}},
|
||||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_space_search(m, arg[0], arg[1], kit.Select("", arg, 2))
|
_space_search(m, arg[0], arg[1], kit.Select("", arg, 2))
|
||||||
|
_broad_search(m, arg[0], arg[1], kit.Select("", arg, 2))
|
||||||
}},
|
}},
|
||||||
aaa.INVITE: {Name: "invite", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
aaa.INVITE: {Name: "invite", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||||
for _, k := range []string{ice.MISC, ice.CORE, ice.BASE} {
|
for _, k := range []string{ice.MISC, ice.CORE, ice.BASE} {
|
||||||
|
@ -334,18 +334,15 @@ const SPIDE = "spide"
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||||
SPIDE: {Name: SPIDE, Help: "蜘蛛侠", Value: kit.Data(
|
SPIDE: {Name: SPIDE, Help: "蜘蛛侠", Value: kit.Data(mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,client.name,client.url", LOGHEADERS, ice.FALSE)},
|
||||||
mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,client.name,client.url",
|
|
||||||
LOGHEADERS, ice.FALSE,
|
|
||||||
)},
|
|
||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
SPIDE: {Name: "spide client.name action=raw,msg,save,cache method=GET,PUT,POST,DELETE url format=form,part,json,data,file arg run create", Help: "蜘蛛侠", Action: ice.MergeAction(map[string]*ice.Action{
|
SPIDE: {Name: "spide client.name action=raw,msg,save,cache method=GET,PUT,POST,DELETE url format=form,part,json,data,file arg run create", Help: "蜘蛛侠", Action: ice.MergeAction(map[string]*ice.Action{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
conf := m.Confm(cli.RUNTIME, "conf")
|
conf := m.Confm(cli.RUNTIME, "conf")
|
||||||
m.Cmd(SPIDE, mdb.CREATE, ice.OPS, kit.Select("http://:9020", conf["ctx_ops"]))
|
m.Cmd(SPIDE, mdb.CREATE, ice.OPS, kit.Select("http://127.0.0.1:9020", conf["ctx_ops"]))
|
||||||
m.Cmd(SPIDE, mdb.CREATE, ice.DEV, kit.Select("http://contexts.woa.com:80", conf["ctx_dev"]))
|
m.Cmd(SPIDE, mdb.CREATE, ice.DEV, kit.Select("http://contexts.woa.com:80", conf["ctx_dev"]))
|
||||||
// m.Cmd(SPIDE, mdb.CREATE, ice.SHY, kit.Select("https://contexts.com.cn:443", conf["ctx_shy"]))
|
|
||||||
m.Cmd(SPIDE, mdb.CREATE, ice.SHY, kit.Select("https://shylinux.com:443", conf["ctx_shy"]))
|
m.Cmd(SPIDE, mdb.CREATE, ice.SHY, kit.Select("https://shylinux.com:443", conf["ctx_shy"]))
|
||||||
|
// m.Cmd(SPIDE, mdb.CREATE, ice.SHY, kit.Select("https://contexts.com.cn:443", conf["ctx_shy"]))
|
||||||
}},
|
}},
|
||||||
mdb.CREATE: {Name: "create name address", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
mdb.CREATE: {Name: "create name address", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_spide_create(m, m.Option(mdb.NAME), m.Option(ADDRESS))
|
_spide_create(m, m.Option(mdb.NAME), m.Option(ADDRESS))
|
||||||
|
@ -178,6 +178,11 @@ func _website_render(m *ice.Message, w http.ResponseWriter, r *http.Request, kin
|
|||||||
web.Render(msg, msg.Option(ice.MSG_OUTPUT), msg.Optionv(ice.MSG_ARGS).([]interface{})...)
|
web.Render(msg, msg.Option(ice.MSG_OUTPUT), msg.Optionv(ice.MSG_ARGS).([]interface{})...)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
func _website_search(m *ice.Message, kind, name, text string, arg ...string) {
|
||||||
|
m.Cmd(m.PrefixKey()).Table(func(index int, value map[string]string, head []string) {
|
||||||
|
m.PushSearch(value, mdb.TEXT, m.MergeURL2(path.Join("/chat/website", value[nfs.PATH])))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const WEBSITE = "website"
|
const WEBSITE = "website"
|
||||||
|
|
||||||
@ -216,6 +221,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"inner": {Hand: func(m *ice.Message, arg ...string) {}},
|
"inner": {Hand: func(m *ice.Message, arg ...string) {}},
|
||||||
|
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_website_search(m, arg[0], arg[1], kit.Select("", arg, 2))
|
||||||
|
}},
|
||||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.EchoIFrame(_website_url(m, strings.TrimPrefix(path.Join(arg[2], arg[1]), SRC_WEBSITE)))
|
m.EchoIFrame(_website_url(m, strings.TrimPrefix(path.Join(arg[2], arg[1]), SRC_WEBSITE)))
|
||||||
}},
|
}},
|
||||||
|
@ -178,7 +178,6 @@ func init() {
|
|||||||
Index.Register(&ice.Context{Name: GO, Help: "后端", Commands: map[string]*ice.Command{
|
Index.Register(&ice.Context{Name: GO, Help: "后端", Commands: map[string]*ice.Command{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Cmd(mdb.SEARCH, mdb.CREATE, GODOC, m.Prefix(GO))
|
m.Cmd(mdb.SEARCH, mdb.CREATE, GODOC, m.Prefix(GO))
|
||||||
m.Cmd(mdb.SEARCH, mdb.CREATE, GO, m.Prefix(GO))
|
|
||||||
m.Cmd(mdb.ENGINE, mdb.CREATE, GO, m.Prefix(GO))
|
m.Cmd(mdb.ENGINE, mdb.CREATE, GO, m.Prefix(GO))
|
||||||
|
|
||||||
LoadPlug(m, GO, MOD, SUM)
|
LoadPlug(m, GO, MOD, SUM)
|
||||||
|
@ -111,6 +111,7 @@ func init() {
|
|||||||
_inner_exec(m, arg[0], arg[1], arg[2])
|
_inner_exec(m, arg[0], arg[1], arg[2])
|
||||||
}},
|
}},
|
||||||
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
return
|
||||||
m.Option(nfs.DIR_ROOT, arg[2])
|
m.Option(nfs.DIR_ROOT, arg[2])
|
||||||
m.Option(cli.CMD_DIR, kit.Path(arg[2]))
|
m.Option(cli.CMD_DIR, kit.Path(arg[2]))
|
||||||
m.Cmdy(mdb.SEARCH, arg[0], arg[1], arg[2])
|
m.Cmdy(mdb.SEARCH, arg[0], arg[1], arg[2])
|
||||||
|
@ -36,6 +36,9 @@ func init() {
|
|||||||
m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT)))
|
m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT)))
|
||||||
m.Cmdy(TEMPLATE, nfs.DEFS)
|
m.Cmdy(TEMPLATE, nfs.DEFS)
|
||||||
}},
|
}},
|
||||||
|
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.PushSearch(mdb.TYPE, "go", mdb.NAME, "src/main.go", mdb.TEXT, m.MergeURL2("/chat/cmd/web.code.vimer"))
|
||||||
|
}},
|
||||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||||
switch m.Option(ctx.ACTION) {
|
switch m.Option(ctx.ACTION) {
|
||||||
case web.DREAM:
|
case web.DREAM:
|
||||||
|
@ -38,10 +38,8 @@ func init() {
|
|||||||
)},
|
)},
|
||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
WORD: {Name: "word path=src/main.shy@key auto play", Help: "语言文字", Meta: kit.Dict(ice.DisplayLocal("")), Action: ice.MergeAction(map[string]*ice.Action{
|
WORD: {Name: "word path=src/main.shy@key auto play", Help: "语言文字", Meta: kit.Dict(ice.DisplayLocal("")), Action: ice.MergeAction(map[string]*ice.Action{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey())
|
|
||||||
}},
|
|
||||||
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.PushSearch(mdb.TYPE, "shy", mdb.NAME, "src/main.shy", mdb.TEXT, m.MergeURL2("/chat/cmd/web.wiki.word"))
|
||||||
m.Cmd(mdb.SELECT, m.PrefixKey(), "", mdb.HASH).Table(func(index int, value map[string]string, head []string) {
|
m.Cmd(mdb.SELECT, m.PrefixKey(), "", mdb.HASH).Table(func(index int, value map[string]string, head []string) {
|
||||||
if arg[1] == "" {
|
if arg[1] == "" {
|
||||||
if value[mdb.TYPE] == SPARK {
|
if value[mdb.TYPE] == SPARK {
|
||||||
|
57
type.go
57
type.go
@ -14,6 +14,9 @@ import (
|
|||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CommandHandler func(m *Message, c *Context, key string, arg ...string)
|
||||||
|
type ActionHandler func(m *Message, arg ...string)
|
||||||
|
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
Name string
|
Name string
|
||||||
Help string
|
Help string
|
||||||
@ -35,7 +38,7 @@ type Command struct {
|
|||||||
Help string
|
Help string
|
||||||
Action map[string]*Action
|
Action map[string]*Action
|
||||||
Meta map[string]interface{}
|
Meta map[string]interface{}
|
||||||
Hand func(m *Message, c *Context, key string, arg ...string)
|
Hand CommandHandler
|
||||||
List []interface{}
|
List []interface{}
|
||||||
}
|
}
|
||||||
type Server interface {
|
type Server interface {
|
||||||
@ -95,6 +98,7 @@ func (c *Context) Register(s *Context, x Server, n ...string) *Context {
|
|||||||
s.Merge(s)
|
s.Merge(s)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Merge(s *Context) *Context {
|
func (c *Context) Merge(s *Context) *Context {
|
||||||
if c.Commands == nil {
|
if c.Commands == nil {
|
||||||
c.Commands = map[string]*Command{}
|
c.Commands = map[string]*Command{}
|
||||||
@ -129,25 +133,46 @@ func (c *Context) Merge(s *Context) *Context {
|
|||||||
cmd.List = c.split(cmd.Name)
|
cmd.List = c.split(cmd.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
merge := func(pre *Command, before bool, key string, cmd *Command, cb ...CommandHandler) {
|
||||||
|
last := pre.Hand
|
||||||
|
pre.Hand = func(m *Message, c *Context, _key string, arg ...string) {
|
||||||
|
if before {
|
||||||
|
last(m, c, _key, arg...)
|
||||||
|
}
|
||||||
|
m._key, m._cmd = key, cmd
|
||||||
|
for _, cb := range cb {
|
||||||
|
if cb != nil {
|
||||||
|
cb(m, c, key, arg...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m._key, m._cmd = _key, pre
|
||||||
|
if !before {
|
||||||
|
last(m, c, _key, arg...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for k, a := range cmd.Action {
|
for k, a := range cmd.Action {
|
||||||
// if p, ok := c.Commands[k]; ok && s != c {
|
|
||||||
if p, ok := c.Commands[k]; ok {
|
if p, ok := c.Commands[k]; ok {
|
||||||
key := key
|
switch hand := a.Hand; k {
|
||||||
switch last, next := p.Hand, a.Hand; k {
|
|
||||||
case CTX_INIT:
|
case CTX_INIT:
|
||||||
p.Hand = func(m *Message, c *Context, _key string, arg ...string) {
|
merge(p, true, key, cmd, func(m *Message, c *Context, _key string, arg ...string) {
|
||||||
last(m, c, _key, arg...)
|
hand(m, arg...)
|
||||||
m._key, m._cmd = key, cmd
|
})
|
||||||
next(m, arg...)
|
|
||||||
m._key, m._cmd = _key, p
|
|
||||||
}
|
|
||||||
case CTX_EXIT:
|
case CTX_EXIT:
|
||||||
p.Hand = func(m *Message, c *Context, _key string, arg ...string) {
|
merge(p, false, key, cmd, func(m *Message, c *Context, _key string, arg ...string) {
|
||||||
m._key, m._cmd = key, cmd
|
hand(m, arg...)
|
||||||
next(m, arg...)
|
})
|
||||||
m._key, m._cmd = _key, p
|
}
|
||||||
last(m, c, _key, arg...)
|
}
|
||||||
}
|
if s != c {
|
||||||
|
switch k {
|
||||||
|
case "search":
|
||||||
|
merge(c.Commands[CTX_INIT], true, key, cmd, func(m *Message, c *Context, _key string, arg ...string) {
|
||||||
|
if m.CommandKey() != "search" {
|
||||||
|
m.Cmd("search", "create", m.CommandKey(), m.PrefixKey())
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user