1
0
forked from x/icebergs

opt action

This commit is contained in:
shaoying 2020-06-18 10:12:13 +08:00
parent 6aff305ded
commit 623ca683db
10 changed files with 393 additions and 462 deletions

View File

@ -36,7 +36,7 @@ func UserRoot(m *ice.Message) {
cli.PassWord = cli.UserName cli.PassWord = cli.UserName
_user_create(m, cli.UserName, cli.PassWord) _user_create(m, cli.UserName, cli.PassWord)
} }
func UserRole(m *ice.Message, username string) string { func UserRole(m *ice.Message, username interface{}) string {
if username == cli.UserName { if username == cli.UserName {
return ROOT return ROOT
} }

118
base/ctx/cmd.go Normal file
View File

@ -0,0 +1,118 @@
package ctx
import (
"github.com/shylinux/icebergs"
"github.com/shylinux/toolkits"
"sort"
"strings"
)
func _command_list(m *ice.Message, all bool, name string) {
p := m.Spawn(m.Source())
if all {
p = ice.Pulse
}
if strings.Contains(name, ".") {
p.Search(name, func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
m.Push("key", s.Cap(ice.CTX_FOLLOW))
m.Push("name", kit.Format(cmd.Name))
m.Push("help", kit.Simple(cmd.Help)[0])
if name != "" {
m.Push("meta", kit.Format(cmd.Meta))
if len(cmd.List) == 0 {
_command_make(m, cmd)
}
m.Push("list", kit.Format(cmd.List))
}
})
return
}
// 命令列表
p.Travel(func(p *ice.Context, s *ice.Context) {
list := []string{}
for k := range s.Commands {
if name != "" && k != name {
continue
}
if k[0] == '/' || k[0] == '_' {
// 内部命令
continue
}
list = append(list, k)
}
sort.Strings(list)
for _, k := range list {
v := s.Commands[k]
m.Push("key", s.Cap(ice.CTX_FOLLOW))
m.Push("name", kit.Format(v.Name))
m.Push("help", kit.Simple(v.Help)[0])
if name != "" {
m.Push("meta", kit.Format(v.Meta))
if len(v.List) == 0 {
_command_make(m, v)
}
m.Push("list", kit.Format(v.List))
}
}
})
}
func _command_make(m *ice.Message, cmd *ice.Command) {
var list []string
switch name := cmd.Name.(type) {
case []string, []interface{}:
list = kit.Split(kit.Simple(name)[0])
default:
list = kit.Split(strings.Split(kit.Format(name), ";")[0])
}
button := false
for i, v := range list {
if i > 0 {
switch ls := kit.Split(v, ":="); ls[0] {
case "[", "]":
case "auto":
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "查看", "value", "auto")...)
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "返回", "value", "Last")...)
button = true
default:
kind, value := "text", ""
if len(ls) == 3 {
kind, value = ls[1], ls[2]
} else if len(ls) == 2 {
if strings.Contains(v, "=") {
value = ls[1]
} else {
kind = ls[1]
}
}
if kind == "button" {
button = true
}
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, kind, "name", ls[0], "value", value)...)
}
}
}
if len(cmd.List) == 0 {
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "text", "name", "name")...)
}
if !button {
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "查看")...)
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "返回", "value", "Last")...)
}
}
func init() {
Index.Merge(&ice.Context{
Commands: map[string]*ice.Command{
COMMAND: {Name: "command [all] command", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
all, arg := _parse_arg_all(m, arg...)
_command_list(m, all, kit.Select("", arg, 0))
}},
},
}, nil)
}

110
base/ctx/conf.go Normal file
View File

@ -0,0 +1,110 @@
package ctx
import (
"github.com/shylinux/icebergs"
"github.com/shylinux/toolkits"
"encoding/json"
"os"
"path"
"strings"
)
func _config_list(m *ice.Message, all bool) {
p := m.Spawn(m.Source())
if all {
p = ice.Pulse
}
p.Travel(func(p *ice.Context, s *ice.Context, key string, conf *ice.Config) {
m.Push("key", key)
m.Push("name", conf.Name)
m.Push("value", kit.Format(conf.Value))
})
}
func _config_save(m *ice.Message, name string, arg ...string) {
msg := m.Spawn(m.Source())
// 保存配置
name = path.Join(msg.Conf(ice.CTX_CONFIG, "meta.path"), name)
if f, p, e := kit.Create(name); m.Assert(e) {
data := map[string]interface{}{}
for _, k := range arg {
data[k] = msg.Confv(k)
}
if s, e := json.MarshalIndent(data, "", " "); m.Assert(e) {
if n, e := f.Write(s); m.Assert(e) {
m.Log("info", "save %d %s", n, p)
}
}
m.Echo(p)
}
}
func _config_load(m *ice.Message, name string, arg ...string) {
msg := m.Spawn(m.Source())
// 加载配置
name = path.Join(msg.Conf(ice.CTX_CONFIG, "meta.path"), name)
if f, e := os.Open(name); e == nil {
data := map[string]interface{}{}
json.NewDecoder(f).Decode(&data)
for k, v := range data {
msg.Search(k, func(p *ice.Context, s *ice.Context, key string) {
m.Log("info", "load %s.%s %v", s.Name, key, kit.Format(v))
s.Configs[key].Value = v
})
}
}
}
func _config_make(m *ice.Message, chain string, arg ...string) {
msg := m.Spawn(m.Source())
if len(arg) > 1 {
if strings.HasPrefix(arg[1], "@") {
msg.Conf(chain, arg[0], msg.Cmdx("nfs.cat", arg[1][1:]))
} else {
msg.Conf(chain, arg[0], kit.Parse(nil, "", arg[1:]...))
}
}
if len(arg) > 0 {
// 读取配置
m.Echo(kit.Formats(msg.Confv(chain, arg[0])))
} else {
// 读取配置
m.Echo(kit.Formats(msg.Confv(chain)))
}
}
func _config_rich(m *ice.Message, name string, key string, arg ...string) {
m.Rich(name, key, kit.Dict(arg))
}
func _config_grow(m *ice.Message, name string, key string, arg ...string) {
m.Grow(name, key, kit.Dict(arg))
}
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
CONFIG: {Name: "config", Help: "配置", Value: kit.Data("path", "var/conf")},
},
Commands: map[string]*ice.Command{
ice.CTX_CONFIG: {Name: "config [all] [chain [key [arg...]]]", Help: "配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if all, arg := _parse_arg_all(m, arg...); len(arg) == 0 {
_config_list(m, all)
return
}
switch arg[0] {
case "save":
_config_save(m, arg[1], arg[2:]...)
case "load":
_config_load(m, arg[1], arg[2:]...)
case "grow":
_config_grow(m, arg[1], arg[2], arg[3:]...)
case "rich":
_config_rich(m, arg[1], arg[2], arg[3:]...)
default:
_config_make(m, arg[0], arg[1:]...)
}
}},
},
}, nil)
}

View File

@ -3,12 +3,12 @@ package ctx
import ( import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
)
"encoding/json" const (
"os" CONTEXT = "context"
"path" COMMAND = "command"
"sort" CONFIG = "config"
"strings"
) )
func _parse_arg_all(m *ice.Message, arg ...string) (bool, []string) { func _parse_arg_all(m *ice.Message, arg ...string) (bool, []string) {
@ -16,156 +16,6 @@ func _parse_arg_all(m *ice.Message, arg ...string) (bool, []string) {
return true, arg[1:] return true, arg[1:]
} }
return false, arg return false, arg
}
func _parse_arg_chain(m *ice.Message, arg ...string) (string, []string) {
if len(arg) > 1 {
return kit.Keys(arg[0], arg[1]), arg[2:]
}
return arg[0], arg[1:]
}
func _config_list(m *ice.Message, all bool) {
p := m.Spawn(m.Source())
if all {
p = ice.Pulse
}
p.Travel(func(p *ice.Context, s *ice.Context, key string, conf *ice.Config) {
m.Push("key", key)
m.Push("name", conf.Name)
m.Push("value", kit.Format(conf.Value))
})
}
func _config_save(m *ice.Message, name string, arg ...string) {
msg := m.Spawn(m.Source())
// 保存配置
name = path.Join(msg.Conf(ice.CTX_CONFIG, "meta.path"), name)
if f, p, e := kit.Create(name); m.Assert(e) {
data := map[string]interface{}{}
for _, k := range arg {
data[k] = msg.Confv(k)
}
if s, e := json.MarshalIndent(data, "", " "); m.Assert(e) {
if n, e := f.Write(s); m.Assert(e) {
m.Log("info", "save %d %s", n, p)
}
}
m.Echo(p)
}
}
func _config_load(m *ice.Message, name string, arg ...string) {
msg := m.Spawn(m.Source())
// 加载配置
name = path.Join(msg.Conf(ice.CTX_CONFIG, "meta.path"), name)
if f, e := os.Open(name); e == nil {
data := map[string]interface{}{}
json.NewDecoder(f).Decode(&data)
for k, v := range data {
msg.Search(k, func(p *ice.Context, s *ice.Context, key string) {
m.Log("info", "load %s.%s %v", s.Name, key, kit.Format(v))
s.Configs[key].Value = v
})
}
}
}
func _config_make(m *ice.Message, chain string, arg ...string) {
msg := m.Spawn(m.Source())
if len(arg) > 1 {
if strings.HasPrefix(arg[1], "@") {
msg.Conf(chain, arg[0], msg.Cmdx("nfs.cat", arg[1][1:]))
} else {
msg.Conf(chain, arg[0], kit.Parse(nil, "", arg[1:]...))
}
}
if len(arg) > 0 {
// 读取配置
m.Echo(kit.Formats(msg.Confv(chain, arg[0])))
} else {
// 读取配置
m.Echo(kit.Formats(msg.Confv(chain)))
}
}
func _config_rich(m *ice.Message, name string, key string, arg ...string) {
m.Rich(name, key, kit.Dict(arg))
}
func _config_grow(m *ice.Message, name string, key string, arg ...string) {
m.Grow(name, key, kit.Dict(arg))
}
func _command_list(m *ice.Message, all bool) {
p := m.Spawn(m.Source())
if all {
p = ice.Pulse
}
// 命令列表
p.Travel(func(p *ice.Context, s *ice.Context) {
list := []string{}
for k := range s.Commands {
if k[0] == '/' || k[0] == '_' {
// 内部命令
continue
}
list = append(list, k)
}
sort.Strings(list)
for _, k := range list {
v := s.Commands[k]
m.Push("key", s.Cap(ice.CTX_FOLLOW))
m.Push("index", k)
m.Push("name", kit.Format(v.Name))
m.Push("help", kit.Simple(v.Help)[0])
// m.Push("list", kit.Format(v.List))
}
})
}
func _command_make(m *ice.Message, cmd *ice.Command) {
var list []string
switch name := cmd.Name.(type) {
case []string, []interface{}:
list = kit.Split(kit.Simple(name)[0])
default:
list = kit.Split(strings.Split(kit.Format(name), ";")[0])
}
button := false
for i, v := range list {
if i > 0 {
switch ls := kit.Split(v, ":="); ls[0] {
case "[", "]":
case "auto":
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "查看", "value", "auto")...)
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "返回", "value", "Last")...)
button = true
default:
kind, value := "text", ""
if len(ls) == 3 {
kind, value = ls[1], ls[2]
} else if len(ls) == 2 {
if strings.Contains(v, "=") {
value = ls[1]
} else {
kind = ls[1]
}
}
if kind == "button" {
button = true
}
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, kind, "name", ls[0], "value", value)...)
}
}
}
if len(cmd.List) == 0 {
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "text", "name", "name")...)
}
if !button {
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "查看")...)
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "返回", "value", "Last")...)
}
} }
func _context_list(m *ice.Message, all bool) { func _context_list(m *ice.Message, all bool) {
@ -188,82 +38,29 @@ func _context_list(m *ice.Message, all bool) {
} }
var Index = &ice.Context{Name: "ctx", Help: "配置模块", var Index = &ice.Context{Name: "ctx", Help: "配置模块",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
ice.CTX_CONFIG: {Name: "config", Help: "配置", Value: kit.Data("path", "var/conf")},
},
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.CTX_CONTEXT: {Name: "context [all]", Help: "模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { CONTEXT: {Name: "context [all] [name [command|config arg...]]", Help: "模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if all, arg := _parse_arg_all(m, arg...); len(arg) == 0 { if all, arg := _parse_arg_all(m, arg...); len(arg) == 0 {
_context_list(m, all) _context_list(m, all)
return return
} }
if len(arg) == 1 { if len(arg) == 1 {
m.Cmdy(ice.CTX_COMMAND, arg[0]+".") m.Cmdy(COMMAND, arg[0])
} else { } else {
m.Search(arg[0]+".", func(p *ice.Context, s *ice.Context, key string) { m.Search(arg[0]+".", func(p *ice.Context, s *ice.Context, key string) {
msg := m.Spawn(s) msg := m.Spawn(s)
switch arg[1] { switch arg[1] {
case "command": case "command":
msg.Cmdy(ice.CTX_COMMAND, arg[0], arg[2:]) msg.Cmdy(COMMAND, arg[0], arg[2:])
case "config": case "config":
msg.Cmdy(ice.CTX_CONFIG, arg[2:]) msg.Cmdy(CONFIG, arg[2:])
} }
m.Copy(msg) m.Copy(msg)
}) })
} }
}},
ice.CTX_COMMAND: {Name: "command [all] [context [command run arg...]]", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if all, arg := _parse_arg_all(m, arg...); len(arg) == 0 {
_command_list(m, all)
return
}
chain, arg := _parse_arg_chain(m, arg...)
m.Search(chain, func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
if len(arg) == 0 {
// 命令列表
m.Push("key", key)
m.Push("name", cmd.Name)
m.Push("help", kit.Simple(cmd.Help)[0])
m.Push("meta", kit.Format(cmd.Meta))
if len(cmd.List) == 0 {
_command_make(m, cmd)
}
m.Push("list", kit.Format(cmd.List))
} else {
if you := m.Option(kit.Format(kit.Value(cmd.Meta, "remote"))); you != "" {
// 远程命令
m.Copy(m.Spawns(s).Cmd(ice.WEB_SPACE, you, ice.CTX_COMMAND, chain, "run", arg[1:]))
} else {
// 本地命令
m.Copy(s.Run(m.Spawns(s), cmd, key, arg[1:]...))
}
}
})
}},
ice.CTX_CONFIG: {Name: "config [all] [chain [key [arg...]]]", Help: "配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if all, arg := _parse_arg_all(m, arg...); len(arg) == 0 {
_config_list(m, all)
return
}
switch arg[0] {
case "save":
_config_save(m, arg[1], arg[2:]...)
case "load":
_config_load(m, arg[1], arg[2:]...)
case "grow":
_config_grow(m, arg[1], arg[2], arg[3:]...)
case "rich":
_config_rich(m, arg[1], arg[2], arg[3:]...)
default:
_config_make(m, arg[0], arg[1:]...)
}
}}, }},
}, },
} }
func init() { ice.Index.Register(Index, nil) } func init() { ice.Index.Register(Index, nil, CONTEXT, COMMAND, CONFIG) }

View File

@ -239,8 +239,9 @@ func FavorInsert(m *ice.Message, zone, kind string, name interface{}, text inter
_favor_create(m, zone) _favor_create(m, zone)
_favor_insert(m, zone, kind, name, text, extra...) _favor_insert(m, zone, kind, name, text, extra...)
} }
func FavorList(m *ice.Message, favor, id string, fields ...string) { func FavorList(m *ice.Message, favor, id string, fields ...string) *ice.Message {
_favor_list(m, favor, id, fields...) _favor_list(m, favor, id, fields...)
return m
} }
func FavorShow(m *ice.Message, kind string, name, text interface{}, arg ...string) *ice.Message { func FavorShow(m *ice.Message, kind string, name, text interface{}, arg ...string) *ice.Message {
_favor_show(m, kind, name, text, arg...) _favor_show(m, kind, name, text, arg...)

View File

@ -3,9 +3,11 @@ package chat
import ( import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"strconv"
) )
func _action_share(m *ice.Message, arg ...string) { func _action_share_create(m *ice.Message, arg ...string) {
if m.Option("_index") != "" { if m.Option("_index") != "" {
m.Cmdy(ice.WEB_SHARE, ice.TYPE_ACTION, m.Option("_name"), m.Option("_text"), m.Cmdy(ice.WEB_SHARE, ice.TYPE_ACTION, m.Option("_name"), m.Option("_text"),
"tool.0.pod", kit.Select(m.Option("_pod"), m.Option("_node")), "tool.0.pod", kit.Select(m.Option("_pod"), m.Option("_node")),
@ -26,11 +28,11 @@ func _action_share(m *ice.Message, arg ...string) {
}) })
} }
} }
func _action_share_list(m *ice.Message, c *ice.Context, cmd string, arg ...string) { func _action_share_list(m *ice.Message, river, storm string) {
m.Richs(ice.WEB_SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) { m.Richs(ice.WEB_SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
kit.Fetch(kit.Value(value, "extra.tool"), func(index int, value map[string]interface{}) { kit.Fetch(kit.Value(value, "extra.tool"), func(index int, value map[string]interface{}) {
m.Push("river", arg[0]) m.Push("river", river)
m.Push("storm", arg[1]) m.Push("storm", storm)
m.Push("action", index) m.Push("action", index)
m.Push("node", value["pod"]) m.Push("node", value["pod"])
@ -38,7 +40,7 @@ func _action_share_list(m *ice.Message, c *ice.Context, cmd string, arg ...strin
m.Push("index", value["cmd"]) m.Push("index", value["cmd"])
m.Push("args", value["args"]) m.Push("args", value["args"])
msg := m.Cmd(m.Space(value["pod"]), ice.CTX_COMMAND, value["ctx"], value["cmd"]) msg := m.Cmd(m.Space(value["pod"]), ice.CTX_COMMAND, kit.Keys(value["ctx"], value["cmd"]))
m.Push("name", value["cmd"]) m.Push("name", value["cmd"])
m.Push("help", kit.Select(msg.Append("help"), kit.Format(value["help"]))) m.Push("help", kit.Select(msg.Append("help"), kit.Format(value["help"])))
m.Push("inputs", msg.Append("list")) m.Push("inputs", msg.Append("list"))
@ -46,61 +48,15 @@ func _action_share_list(m *ice.Message, c *ice.Context, cmd string, arg ...strin
}) })
}) })
} }
func _action_share_show(m *ice.Message, c *ice.Context, cmd string, arg ...string) { func _action_share_show(m *ice.Message, river, storm, index string, arg ...string) {
if len(arg) > 3 && arg[3] == "action" && _action_action(m, arg[4], arg[5:]...) { if i, e := strconv.Atoi(index); e == nil {
return m.Richs(ice.WEB_SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
} kit.Fetch(kit.Value(value, kit.Keys("extra.tool", i-1)), func(value map[string]interface{}) {
cmds := kit.Simple(kit.Keys(value["ctx"], value["cmd"]), arg)
m.Richs(ice.WEB_SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) { m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds)
kit.Fetch(kit.Value(value, kit.Keys("extra.tool", arg[2])), func(value map[string]interface{}) { })
cmds := kit.Simple(kit.Keys(value["ctx"], value["cmd"]), arg[3:])
m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds)
}) })
})
}
func _action_order(m *ice.Message, arg ...string) {
if arg[2] == "index" {
for i, v := range arg[3:] {
m.Push("river", arg[0])
m.Push("storm", arg[1])
m.Push("action", i)
m.Push("node", "")
m.Push("group", "")
m.Push("index", v)
m.Push("args", "[]")
msg := m.Cmd(m.Space(m.Option("pod")), ice.CTX_COMMAND, v)
m.Push("name", msg.Append("name"))
m.Push("help", msg.Append("help"))
m.Push("feature", msg.Append("meta"))
m.Push("inputs", msg.Append("list"))
}
} }
if len(arg) > 3 && arg[3] == "action" && _action_action(m, arg[4], arg[5:]...) {
return
}
if m.Option("index") == "" || !m.Right(kit.Keys(m.Option("group"), m.Option("index"))) {
m.Render("status", 403, "not auth")
return
}
cmds := kit.Simple(kit.Keys(m.Option("group"), m.Option("index")), arg[3:])
if m.Set(ice.MSG_RESULT); !m.Right(cmds) {
m.Render("status", 403, "not auth")
return
}
m.Add("option", "_option", "data", "name")
m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds)
}
func _action_proxy(m *ice.Message) (proxy []string) {
if m.Option("pod") != "" {
proxy = append(proxy, ice.WEB_PROXY, m.Option("pod"))
m.Option("pod", "")
}
return proxy
} }
func _action_action(m *ice.Message, action string, arg ...string) bool { func _action_action(m *ice.Message, action string, arg ...string) bool {
switch action { switch action {
@ -111,12 +67,38 @@ func _action_action(m *ice.Message, action string, arg ...string) bool {
} }
return false return false
} }
func _action_select(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
prefix := kit.Keys(kit.MDB_HASH, arg[0], "tool", kit.MDB_HASH, arg[1]) func _action_proxy(m *ice.Message) (proxy []string) {
if m.Option("pod") != "" {
proxy = append(proxy, ice.WEB_PROXY, m.Option("pod"))
m.Option("pod", "")
}
return proxy
}
func _action_order(m *ice.Message, river, storm string, arg ...string) {
for i, v := range arg {
m.Push("river", river)
m.Push("storm", storm)
m.Push("action", i)
m.Push("node", "")
m.Push("group", "")
m.Push("index", v)
m.Push("args", "[]")
msg := m.Cmd(m.Space(m.Option("pod")), ice.CTX_COMMAND, v)
m.Push("name", msg.Append("name"))
m.Push("help", msg.Append("help"))
m.Push("feature", msg.Append("meta"))
m.Push("inputs", msg.Append("list"))
}
}
func _action_list(m *ice.Message, river, storm string) {
prefix := kit.Keys(kit.MDB_HASH, river, "tool", kit.MDB_HASH, storm)
m.Grows(ice.CHAT_RIVER, prefix, "", "", func(index int, value map[string]interface{}) { m.Grows(ice.CHAT_RIVER, prefix, "", "", func(index int, value map[string]interface{}) {
if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok { if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok {
m.Push("river", arg[0]) m.Push("river", river)
m.Push("storm", arg[1]) m.Push("storm", storm)
m.Push("action", index) m.Push("action", index)
m.Push("node", meta["pod"]) m.Push("node", meta["pod"])
@ -124,7 +106,7 @@ func _action_select(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Push("index", meta["cmd"]) m.Push("index", meta["cmd"])
m.Push("args", kit.Select("[]", kit.Format(meta["args"]))) m.Push("args", kit.Select("[]", kit.Format(meta["args"])))
msg := m.Cmd(m.Space(meta["pod"]), ice.CTX_COMMAND, meta["ctx"], meta["cmd"]) msg := m.Cmd(m.Space(meta["pod"]), ice.CTX_COMMAND, kit.Keys(meta["ctx"], meta["cmd"]))
m.Push("name", meta["cmd"]) m.Push("name", meta["cmd"])
m.Push("help", kit.Select(msg.Append("help"), kit.Format(meta["help"]))) m.Push("help", kit.Select(msg.Append("help"), kit.Format(meta["help"])))
m.Push("feature", msg.Append("meta")) m.Push("feature", msg.Append("meta"))
@ -132,120 +114,65 @@ func _action_select(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
} }
}) })
} }
func _action_show(m *ice.Message, river, storm, index string, arg ...string) {
prefix := kit.Keys(kit.MDB_HASH, river, "tool", kit.MDB_HASH, storm)
cmds := []string{}
if i, e := strconv.Atoi(index); e == nil {
m.Grows(ice.CHAT_RIVER, prefix, kit.MDB_ID, kit.Format(i+1), func(index int, value map[string]interface{}) {
if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok {
cmds = kit.Simple(m.Space(meta["pod"]), kit.Keys(meta["ctx"], meta["cmd"]), arg[3:])
}
})
} else if !m.Warn(!m.Right(index), "no right of %v", index) {
cmds = kit.Simple(index, arg)
}
if !m.Right(cmds) {
m.Render("status", 403, "not auth")
return
}
m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds)
}
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
"/action": {Name: "/action", Help: "工作台", Action: map[string]*ice.Action{ "/action": {Name: "/action", Help: "工作台", Action: map[string]*ice.Action{
kit.MDB_SHARE: {Name: "share arg...", Help: "共享", Hand: func(m *ice.Message, arg ...string) { kit.MDB_SHARE: {Name: "share arg...", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
_action_share(m, arg...) _action_share_create(m, arg...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 || arg[0] == "" {
if m.Option("share") != "" {
if len(arg) < 3 {
_action_share_list(m, c, cmd, arg...)
return
}
_action_share_show(m, c, cmd, arg...)
return
}
}
if m.Warn(m.Option(ice.MSG_RIVER) == "" || m.Option(ice.MSG_STORM) == "", "not join") {
_action_order(m, arg...)
return
}
prefix := kit.Keys(kit.MDB_HASH, arg[0], "tool", kit.MDB_HASH, arg[1])
if len(arg) == 2 { if len(arg) == 2 {
if m.Option("share") != "" {
// 共享列表
_action_share_list(m, arg[0], arg[1])
}
if p := m.Option("pod"); p != "" { if p := m.Option("pod"); p != "" {
m.Option("pod", "") m.Option("pod", "")
if m.Cmdy(ice.WEB_SPACE, p, "web.chat./action", arg); len(m.Appendv("river")) > 0 { // 代理列表
// 远程查询 m.Cmdy(ice.WEB_SPACE, p, "web.chat./action", arg)
return
}
} }
// 命令列表 // 命令列表
_action_select(m, c, cmd, arg...) _action_list(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM))
return return
} }
switch arg[2] { switch arg[2] {
case "save": case "index":
if p := m.Option("pod"); p != "" { // 前端列表
// 远程保存 _action_order(m, arg[0], arg[1], arg[3:]...)
m.Option("pod", "")
m.Cmd(ice.WEB_SPACE, p, "web.chat./action", arg)
return
}
// 保存应用
m.Conf(ice.CHAT_RIVER, kit.Keys(prefix, "list"), "")
for i := 3; i < len(arg)-4; i += 5 {
id := m.Grow(ice.CHAT_RIVER, kit.Keys(prefix), kit.Data(
"pod", arg[i], "ctx", arg[i+1], "cmd", arg[i+2],
"help", arg[i+3], "args", arg[i+4],
))
m.Log(ice.LOG_INSERT, "storm: %s %d: %v", arg[1], id, arg[i:i+5])
}
}
// 查询命令
cmds := []string{}
m.Grows(ice.CHAT_RIVER, prefix, kit.MDB_ID, kit.Format(kit.Int(arg[2])+1), func(index int, value map[string]interface{}) {
if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok {
if len(arg) > 3 && arg[3] == "action" {
// 命令补全
switch arg[4] {
case "input":
switch arg[5] {
case "location":
// 查询位置
m.Copy(m.Cmd("aaa.location"), "append", "name")
return
}
case "favor":
m.Cmdy(ice.WEB_FAVOR, arg[5:])
return
case "device":
// 记录位置
m.Cmd(ice.WEB_FAVOR, kit.Select("device", m.Option("hot")), arg[5], arg[6],
kit.Select("", arg, 7), kit.KeyValue(map[string]interface{}{}, "", kit.UnMarshal(kit.Select("{}", arg, 8))))
return
case "upload":
m.Cmdy(ice.WEB_STORY, "upload")
return
case "share":
list := []string{}
for k, v := range meta {
list = append(list, k, kit.Format(v))
}
// 共享命令
m.Cmdy(ice.WEB_SHARE, "action", arg[5], arg[6], list)
return
}
}
// 组装命令
cmds = kit.Simple(m.Space(meta["pod"]), kit.Keys(meta["ctx"], meta["cmd"]), arg[3:])
}
})
if len(cmds) == 0 {
return return
} }
if !m.Right(cmds) { if arg[0] == "" && m.Option("share") != "" {
m.Render("status", 403, "not auth") // 共享命令
_action_share_show(m, arg[0], arg[1], arg[2], arg[3:]...)
return
}
if arg[3] == "action" && _action_action(m, arg[3]) {
// 前置命令
return return
} }
// 执行命令 // 执行命令
m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds) _action_show(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM), kit.Select(arg[2], m.Option("index")), arg[3:]...)
}}, }},
}}, nil) }}, nil)
} }

View File

@ -9,10 +9,14 @@ import (
"sync" "sync"
) )
const (
RIVER = "river"
STORM = "storm"
)
var Index = &ice.Context{Name: "chat", Help: "聊天中心", var Index = &ice.Context{Name: "chat", Help: "聊天中心",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
ice.CHAT_RIVER: {Name: "river", Help: "群组", Value: kit.Data( RIVER: {Name: "river", Help: "群组", Value: kit.Data(
"template", kit.Dict("root", []interface{}{ "template", kit.Dict("root", []interface{}{
[]interface{}{"river", `{{.Option "user.nick"|Format}}@{{.Conf "runtime" "node.name"|Format}}`, "mall"}, []interface{}{"river", `{{.Option "user.nick"|Format}}@{{.Conf "runtime" "node.name"|Format}}`, "mall"},
@ -65,30 +69,28 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
[]interface{}{"storm", "wiki", "wiki"}, []interface{}{"storm", "wiki", "wiki"},
[]interface{}{"field", "note", "web.wiki"}, []interface{}{"field", "note", "web.wiki"},
}), }),
"black", kit.Dict("void", []interface{}{ "black", kit.Dict("tech", []interface{}{
[]interface{}{"/debug"}, "/debug",
[]interface{}{"/river", "add"}, "/river.add",
[]interface{}{"/river", "share"}, "/river.share",
[]interface{}{"/river", "rename"}, "/river.rename",
[]interface{}{"/river", "remove"}, "/river.remove",
[]interface{}{"/storm", "remove"}, "/storm.remove",
[]interface{}{"/storm", "rename"}, "/storm.rename",
[]interface{}{"/storm", "share"}, "/storm.share",
[]interface{}{"/storm", "add"}, "/storm.add",
}), }),
"white", kit.Dict("void", []interface{}{ "white", kit.Dict("void", []interface{}{
[]interface{}{"/toast"}, "/toast",
[]interface{}{"/carte"}, "/carte",
[]interface{}{"/tutor"}, "/tutor",
[]interface{}{"/login"}, "/login",
[]interface{}{"/river"}, "/river",
[]interface{}{"/storm"}, "/storm",
[]interface{}{"/action"}, "/action",
[]interface{}{"web.wiki.note"}, "web.wiki.note",
}), }),
"fe", "volcanos",
)}, )},
"commend": {Name: "commend", Help: "commend", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME, "user", kit.Data(kit.MDB_SHORT, kit.MDB_NAME))},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@ -97,59 +99,50 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
m.Watch(ice.USER_CREATE, m.Prefix("auto")) m.Watch(ice.USER_CREATE, m.Prefix("auto"))
}}, }},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save("river", "search", "commend") m.Save(RIVER)
}}, }},
"init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(m.Confm(ice.CHAT_RIVER, "hash")) == 0 { if len(m.Confm(ice.CHAT_RIVER, kit.MDB_HASH)) == 0 {
if m.Richs(ice.WEB_FAVOR, nil, "river.root", nil) == nil { // 默认群组
// 系统群组 kit.Fetch(m.Confv(ice.CHAT_RIVER, "meta.template"), func(key string, val map[string]interface{}) {
kit.Fetch(m.Confv(ice.CHAT_RIVER, "meta.template.root"), func(index int, value interface{}) { if favor := kit.Keys(c.Cap(ice.CTX_FOLLOW), key); m.Richs(ice.WEB_FAVOR, nil, favor, nil) == nil {
m.Cmd(ice.WEB_FAVOR, "river.root", value) kit.Fetch(val, func(index int, value interface{}) {
}) v := kit.Simple(value)
// 默认群组 web.FavorInsert(m, favor, v[0], v[1], v[2])
kit.Fetch(m.Confv(ice.CHAT_RIVER, "meta.template.void"), func(index int, value interface{}) { })
m.Cmd(ice.WEB_FAVOR, "river.void", value) }
}) })
// 黑名单
kit.Fetch(m.Confv(ice.CHAT_RIVER, "meta.black.void"), func(index int, value interface{}) {
m.Cmd(ice.AAA_ROLE, "black", ice.ROLE_VOID, "enable", value)
})
// 白名单
kit.Fetch(m.Confv(ice.CHAT_RIVER, "meta.white.void"), func(index int, value interface{}) {
m.Cmd(ice.AAA_ROLE, "white", ice.ROLE_VOID, "enable", value)
})
}
// 超级用户
m.Cmd(ice.AAA_USER, "first", m.Conf(ice.CLI_RUNTIME, "boot.username"))
}
// 前端框架 // 黑名单
m.Cmd("web.code.git.repos", m.Conf(ice.CHAT_RIVER, "meta.fe")) kit.Fetch(m.Confv(ice.CHAT_RIVER, "meta.black.tech"), func(index int, value interface{}) {
m.Cap(ice.CTX_STREAM, m.Conf(ice.CHAT_RIVER, "meta.fe")) m.Cmd(aaa.ROLE, aaa.Black, aaa.TECH, value)
})
// 白名单
kit.Fetch(m.Confv(ice.CHAT_RIVER, "meta.white.void"), func(index int, value interface{}) {
m.Cmd(aaa.ROLE, aaa.White, aaa.VOID, value)
})
}
m.Cap(ice.CTX_STATUS, "start") m.Cap(ice.CTX_STATUS, "start")
}}, }},
"auto": {Name: "auto user", Help: "自动化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "auto": {Name: "auto user", Help: "自动化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Richs(ice.AAA_USER, nil, arg[0], func(key string, value map[string]interface{}) { m.Richs(aaa.USER, nil, arg[0], func(key string, value map[string]interface{}) {
m.Option(ice.MSG_USERNICK, value["usernick"]) m.Option(ice.MSG_USERNICK, value[aaa.USERNAME])
m.Option(ice.MSG_USERNAME, value["username"]) m.Option(ice.MSG_USERNAME, value[aaa.USERNAME])
m.Option(ice.MSG_USERROLE, "root")
// 创建应用 // 创建应用
storm, river := "", "" storm, river := "", ""
m.Option("cache.limit", -2) m.Option("cache.limit", -2)
m.Richs(ice.WEB_FAVOR, nil, kit.Keys("river", m.Cmdx(ice.AAA_ROLE, "check", value["username"])), func(key string, value map[string]interface{}) { web.FavorList(m, kit.Keys(c.Cap(ice.CTX_FOLLOW), aaa.UserRole(m, value[aaa.USERNAME])), "").Table(func(index int, value map[string]string, head []string) {
m.Grows(ice.WEB_FAVOR, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) { switch value[kit.MDB_TYPE] {
switch value["type"] { case "river":
case "river": name, _ := kit.Render(kit.Format(value["name"]), m)
name, _ := kit.Render(kit.Format(value["name"]), m) river = m.Option(ice.MSG_RIVER, m.Cmdx("/ocean", "spawn", string(name)))
river = m.Option(ice.MSG_RIVER, m.Cmdx("/ocean", "spawn", string(name))) case "storm":
case "storm": storm = m.Option(ice.MSG_STORM, m.Cmdx("/steam", river, "spawn", value["name"]))
storm = m.Option(ice.MSG_STORM, m.Cmdx("/steam", river, "spawn", value["name"])) case "field":
case "field": m.Cmd("/storm", river, storm, "add", "", kit.Select("", value["text"]), value["name"], "")
m.Cmd("/storm", river, storm, "add", "", kit.Select("", value["text"]), value["name"], "") }
}
})
}) })
}) })
}}, }},
@ -162,15 +155,13 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
switch arg[0] { switch arg[0] {
case "login": case "login":
// 密码登录 // 密码登录
if len(arg) > 2 { if len(arg) > 2 && aaa.UserLogin(m, arg[1], arg[2]) {
if aaa.UserLogin(m, arg[1], arg[2]) { web.Render(m, "cookie", m.Option(ice.MSG_SESSID))
web.Render(m, "cookie", m.Option(ice.MSG_SESSID))
}
} }
default: default:
// 群组检查 // 群组检查
if m.Richs(ice.CHAT_RIVER, nil, arg[0], func(key string, value map[string]interface{}) { m.Richs(ice.CHAT_RIVER, nil, arg[0], func(key string, value map[string]interface{}) {
m.Richs(ice.CHAT_RIVER, kit.Keys(kit.MDB_HASH, arg[0], "user"), m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) { m.Richs(ice.CHAT_RIVER, kit.Keys(kit.MDB_HASH, arg[0], "user"), m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
if m.Option(ice.MSG_RIVER, arg[0]); len(arg) > 1 { if m.Option(ice.MSG_RIVER, arg[0]); len(arg) > 1 {
// 应用检查 // 应用检查
@ -178,29 +169,20 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
m.Option(ice.MSG_STORM, arg[1]) m.Option(ice.MSG_STORM, arg[1])
}) })
} }
m.Logs(ice.LOG_AUTH, "river", m.Option(ice.MSG_RIVER), "storm", m.Option(ice.MSG_STORM)) m.Log_AUTH(RIVER, m.Option(ice.MSG_RIVER), STORM, m.Option(ice.MSG_STORM))
}) })
}) == nil { })
// 前端应用
// m.Option(ice.MSG_RIVER, arg[0])
// m.Option(ice.MSG_STORM, arg[1])
}
} }
} }
switch m.Option(ice.MSG_USERURL) {
case "/login", "/header", "/footer":
return
}
// 登录检查 // 登录检查
if m.Warn(!m.Options(ice.MSG_USERNAME), "not login") { if m.Warn(!m.Options(ice.MSG_USERNAME), "not login") {
if m.Option("share") != "" { if m.Option("share") == "" {
m.Option(ice.MSG_USERNAME, "void") m.Render("status", 401, "not login")
m.Option(ice.MSG_USERURL, "")
return return
} }
m.Render("status", 401, "not login") m.Option(ice.MSG_USERROLE, aaa.VOID)
m.Option(ice.MSG_USERURL, "")
return
} }
// 权限检查 // 权限检查
@ -414,4 +396,4 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
}, },
} }
func init() { web.Index.Register(Index, &web.Frame{}) } func init() { web.Index.Register(Index, &web.Frame{}, RIVER, STORM) }

View File

@ -5,8 +5,6 @@ import (
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
) )
var RIVER = ice.Name("river", Index)
func _river_right(m *ice.Message, action string) bool { func _river_right(m *ice.Message, action string) bool {
if m.Warn(m.Option(ice.MSG_RIVER) == "", "not join") { if m.Warn(m.Option(ice.MSG_RIVER) == "", "not join") {
m.Render("status", 402, "not join") m.Render("status", 402, "not join")

View File

@ -5,8 +5,6 @@ import (
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
) )
var STORM = ice.Name("storm", Index)
func _storm_list(m *ice.Message, river string) { func _storm_list(m *ice.Message, river string) {
m.Richs(ice.CHAT_RIVER, kit.Keys(kit.MDB_HASH, river, "tool"), "*", func(key string, value map[string]interface{}) { m.Richs(ice.CHAT_RIVER, kit.Keys(kit.MDB_HASH, river, "tool"), "*", func(key string, value map[string]interface{}) {
m.Push(key, value["meta"], []string{kit.MDB_KEY, kit.MDB_NAME}) m.Push(key, value["meta"], []string{kit.MDB_KEY, kit.MDB_NAME})

View File

@ -232,7 +232,7 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
_input_save(m, arg[0], arg[1:]...) _input_save(m, arg[0], arg[1:]...)
}}, }},
"load": {Name: "load file lib", Help: "导入词库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "load": {Name: "load file lib", Help: "导入词库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_input_load(m, arg[0]) _input_load(m, kit.Select("usr/wubi-dict/wubi86", arg, 0))
}}, }},
"compare": {Name: "demo list nconn nreq", Help: "导入词库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "compare": {Name: "demo list nconn nreq", Help: "导入词库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {