diff --git a/base/aaa/aaa.go b/base/aaa/aaa.go index 3f879d9f..33581cbf 100644 --- a/base/aaa/aaa.go +++ b/base/aaa/aaa.go @@ -3,26 +3,16 @@ package aaa import ( "github.com/shylinux/icebergs" "github.com/shylinux/toolkits" - "math" + "strings" ) -func distance(lat1, long1, lat2, long2 float64) float64 { - lat1 = lat1 * math.Pi / 180 - long1 = long1 * math.Pi / 180 - lat2 = lat2 * math.Pi / 180 - long2 = long2 * math.Pi / 180 - return 2 * 6371 * math.Asin(math.Sqrt(math.Pow(math.Sin(math.Abs(lat1-lat2)/2), 2)+math.Cos(lat1)*math.Cos(lat2)*math.Pow(math.Sin(math.Abs(long1-long2)/2), 2))) -} - var Index = &ice.Context{Name: "aaa", Help: "认证模块", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ ice.AAA_ROLE: {Name: "role", Help: "角色", Value: kit.Data(kit.MDB_SHORT, "chain")}, ice.AAA_USER: {Name: "user", Help: "用户", Value: kit.Data(kit.MDB_SHORT, "username")}, ice.AAA_SESS: {Name: "sess", Help: "会话", Value: kit.Data(kit.MDB_SHORT, "uniq", "expire", "720h")}, - - "location": {Name: "location", Help: "定位", Value: kit.Data(kit.MDB_SHORT, "name")}, }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -34,52 +24,16 @@ var Index = &ice.Context{Name: "aaa", Help: "认证模块", m.Conf(ice.AAA_ROLE, "white.void.meta.short", "chain") }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Save(ice.AAA_ROLE, ice.AAA_USER, ice.AAA_SESS, m.Prefix("location")) + m.Save(ice.AAA_ROLE, ice.AAA_USER, ice.AAA_SESS) }}, - "location": {Name: "location", Help: "location", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) == 0 { - m.Grows("location", nil, "", "", func(index int, value map[string]interface{}) { - m.Push("", value) - }) - return - } - if len(arg) == 1 { - m.Richs("location", nil, arg[0], func(key string, value map[string]interface{}) { - m.Info("what %v", value) - m.Push("detail", value) - }) - return - } - if len(arg) == 2 { - m.Richs("aaa.location", nil, "*", func(key string, value map[string]interface{}) { - m.Push("name", value["name"]) - m.Push("distance", kit.Int(distance( - float64(kit.Int(arg[0]))/100000, - float64(kit.Int(arg[1]))/100000, - float64(kit.Int(value["latitude"]))/100000, - float64(kit.Int(value["longitude"]))/100000, - )*1000)) - }) - m.Sort("distance", "int") - return - } - - data := m.Richs("location", nil, arg[0], nil) - if data != nil { - data["count"] = kit.Int(data["count"]) + 1 - } else { - data = kit.Dict("name", arg[0], "address", arg[1], "latitude", arg[2], "longitude", arg[3], "count", 1) - m.Rich("location", nil, data) - } - m.Grow("location", nil, data) - }}, - - ice.AAA_ROLE: {Name: "role", Help: "角色", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ice.AAA_ROLE: {Name: "role check|black|white|right", Help: "角色", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch arg[0] { case "check": // 用户角色 - m.Echo(kit.Select(kit.Select("void", "tech", m.Confs(ice.AAA_ROLE, kit.Keys("meta.tech", arg[1]))), "root", m.Confs(ice.AAA_ROLE, kit.Keys("meta.root", arg[1])))) + m.Echo(kit.Select(kit.Select("void", + "tech", m.Confs(ice.AAA_ROLE, kit.Keys("meta.tech", arg[1]))), + "root", m.Confs(ice.AAA_ROLE, kit.Keys("meta.root", arg[1])))) case "black", "white": // 黑白名单 @@ -130,13 +84,15 @@ var Index = &ice.Context{Name: "aaa", Help: "认证模块", } // 普通用户 m.Echo("ok") + default: m.Conf(ice.AAA_ROLE, kit.Keys("meta", arg[0], arg[1]), "true") } }}, - ice.AAA_USER: {Name: "user", Help: "用户", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ice.AAA_USER: {Name: "user first|login", Help: "用户", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch arg[0] { case "first": + // 初始用户 if m.Richs(ice.AAA_USER, nil, "%", nil) == nil { m.Rich(ice.AAA_USER, nil, kit.Dict("username", arg[1], "usernode", m.Conf(ice.CLI_RUNTIME, "boot.hostname"), @@ -149,23 +105,25 @@ var Index = &ice.Context{Name: "aaa", Help: "认证模块", case "login": // 用户认证 user := m.Richs(ice.AAA_USER, nil, arg[1], nil) - if user == nil { + if word := kit.Select("", arg, 2); user == nil { // 创建用户 m.Rich(ice.AAA_USER, nil, kit.Dict( - "username", arg[1], "password", arg[2], + "username", arg[1], "password", word, "usernode", m.Conf(ice.CLI_RUNTIME, "boot.hostname"), )) user = m.Richs(ice.AAA_USER, nil, arg[1], nil) - m.Info("create user: %s %s", arg[1], kit.Format(user)) + m.Log(ice.LOG_CREATE, "%s: %s", arg[1], kit.Format(user)) m.Event(ice.USER_CREATE, arg[1]) - } else if kit.Format(user["password"]) == "" { - user["password"] = arg[2] - - } else if kit.Format(user["password"]) != arg[2] { - // 认证失败 - m.Info("login fail user: %s", arg[1]) - break + } else if word != "" { + if kit.Format(user["password"]) == "" { + // 设置密码 + user["password"] = word + } else if kit.Format(user["password"]) != word { + // 认证失败 + m.Info("login fail user: %s", arg[1]) + break + } } if m.Options(ice.MSG_SESSID) && m.Cmdx(ice.AAA_SESS, "check", m.Option(ice.MSG_SESSID)) == arg[1] { @@ -185,6 +143,7 @@ var Index = &ice.Context{Name: "aaa", Help: "认证模块", }}, ice.AAA_SESS: {Name: "sess check|login", Help: "会话", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { + // 会话列表 m.Richs(ice.AAA_SESS, nil, "", func(key string, value map[string]interface{}) { m.Push(key, value, []string{"key", "time", "username", "userrole"}) }) @@ -193,11 +152,14 @@ var Index = &ice.Context{Name: "aaa", Help: "认证模块", switch arg[0] { case "check": + // 查看会话 m.Richs(ice.AAA_SESS, nil, arg[1], func(value map[string]interface{}) { m.Push(arg[1], value, []string{"username", "userrole"}) m.Echo("%s", value["username"]) }) + case "create": + // 创建会话 h := m.Rich(ice.AAA_SESS, nil, kit.Dict( "username", arg[1], "userrole", kit.Select("", arg, 2), )) diff --git a/base/ctx/ctx.go b/base/ctx/ctx.go index 063885a7..85b0fdf0 100644 --- a/base/ctx/ctx.go +++ b/base/ctx/ctx.go @@ -83,7 +83,7 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块", m.Push("key", s.Cap(ice.CTX_FOLLOW)) m.Push("index", k) m.Push("name", v.Name) - m.Push("help", kit.Format(v.Help)) + m.Push("help", kit.Simple(v.Help)[0]) } }) return @@ -100,7 +100,7 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块", // 命令列表 m.Push("key", key) m.Push("name", cmd.Name) - m.Push("help", kit.Format(cmd.Help)) + m.Push("help", kit.Simple(cmd.Help)[0]) m.Push("meta", kit.Format(cmd.Meta)) m.Push("list", kit.Format(cmd.List)) } else { diff --git a/base/mdb/mdb.go b/base/mdb/mdb.go index d0d91779..d3c6bf39 100644 --- a/base/mdb/mdb.go +++ b/base/mdb/mdb.go @@ -7,15 +7,70 @@ import ( "bytes" "encoding/csv" "encoding/json" + "math" "os" "sort" "strings" ) +func distance(lat1, long1, lat2, long2 float64) float64 { + lat1 = lat1 * math.Pi / 180 + long1 = long1 * math.Pi / 180 + lat2 = lat2 * math.Pi / 180 + long2 = long2 * math.Pi / 180 + return 2 * 6371 * math.Asin(math.Sqrt(math.Pow(math.Sin(math.Abs(lat1-lat2)/2), 2)+math.Cos(lat1)*math.Cos(lat2)*math.Pow(math.Sin(math.Abs(long1-long2)/2), 2))) +} + var Index = &ice.Context{Name: "mdb", Help: "数据模块", - Caches: map[string]*ice.Cache{}, - Configs: map[string]*ice.Config{}, + Caches: map[string]*ice.Cache{}, + Configs: map[string]*ice.Config{ + "location": {Name: "location", Help: "定位", Value: kit.Data(kit.MDB_SHORT, "name")}, + }, Commands: map[string]*ice.Command{ + ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Load() + }}, + ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Save(m.Prefix("location")) + }}, + "location": {Name: "location", Help: "location", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) == 0 { + m.Grows("location", nil, "", "", func(index int, value map[string]interface{}) { + m.Push("", value) + }) + return + } + if len(arg) == 1 { + m.Richs("location", nil, arg[0], func(key string, value map[string]interface{}) { + m.Info("what %v", value) + m.Push("detail", value) + }) + return + } + if len(arg) == 2 { + m.Richs("aaa.location", nil, "*", func(key string, value map[string]interface{}) { + m.Push("name", value["name"]) + m.Push("distance", kit.Int(distance( + float64(kit.Int(arg[0]))/100000, + float64(kit.Int(arg[1]))/100000, + float64(kit.Int(value["latitude"]))/100000, + float64(kit.Int(value["longitude"]))/100000, + )*1000)) + }) + m.Sort("distance", "int") + return + } + + data := m.Richs("location", nil, arg[0], nil) + if data != nil { + data["count"] = kit.Int(data["count"]) + 1 + } else { + data = kit.Dict("name", arg[0], "address", arg[1], "latitude", arg[2], "longitude", arg[3], "count", 1) + m.Rich("location", nil, data) + } + m.Grow("location", nil, data) + }}, + "update": {Name: "update config table index key value", Help: "修改数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { meta := m.Confm(arg[0], arg[1]+".meta") index := kit.Int(arg[2]) - kit.Int(meta["offset"]) - 1 diff --git a/base/web/web.go b/base/web/web.go index dc9ba0a0..e14c3129 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -46,6 +46,19 @@ func Cookie(msg *ice.Message, sessid string) string { http.SetCookie(msg.W, &http.Cookie{Name: ice.WEB_SESS, Value: sessid, Path: "/", Expires: expire}) return sessid } +func Upload(m *ice.Message, name string) string { + m.Cmdy(ice.WEB_STORY, "upload") + if s, e := os.Stat(name); e == nil && s.IsDir() { + name = path.Join(name, m.Append("name")) + } + m.Cmd(ice.WEB_STORY, ice.STORY_WATCH, m.Append("data"), name) + return name +} +func Count(m *ice.Message, cmd, key, name string) int { + count := kit.Int(m.Conf(cmd, kit.Keys(key, name))) + m.Conf(cmd, kit.Keys(key, name), count+1) + return count +} func IsLocalIP(ip string) bool { return ip == "::1" || strings.HasPrefix(ip, "127.") } diff --git a/core/chat/chat.go b/core/chat/chat.go index 24f917fc..d7e165e2 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -14,15 +14,16 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", "template", kit.Dict("root", []interface{}{ []interface{}{"storm", "mall", "mall"}, []interface{}{"field", "asset", "web.mall"}, - []interface{}{"field", "bonus", "web.mall"}, - []interface{}{"field", "trans", "web.mall"}, []interface{}{"field", "spend", "web.mall"}, + []interface{}{"field", "trans", "web.mall"}, + []interface{}{"field", "bonus", "web.mall"}, + []interface{}{"field", "month", "web.mall"}, []interface{}{"storm", "team", "team"}, + []interface{}{"field", "plan", "web.team"}, + []interface{}{"field", "stat", "web.team"}, []interface{}{"field", "miss", "web.team"}, []interface{}{"field", "task", "web.team"}, - []interface{}{"field", "stat", "web.team"}, - []interface{}{"field", "plan", "web.team"}, []interface{}{"storm", "wiki", "wiki"}, []interface{}{"field", "draw", "web.wiki"}, @@ -261,6 +262,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", m.Push(key, value["meta"], []string{kit.MDB_KEY, kit.MDB_NAME}) }) }) + m.Log(ice.LOG_SELECT, "%s", m.Format("append")) case 1: // 群组详情 m.Richs(ice.CHAT_RIVER, nil, arg[0], func(key string, value map[string]interface{}) { @@ -304,6 +306,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", m.Richs(ice.CHAT_RIVER, prefix, "*", func(key string, value map[string]interface{}) { m.Push(key, value["meta"], []string{kit.MDB_KEY, kit.MDB_NAME}) }) + m.Log(ice.LOG_SELECT, "%s", m.Format("append")) m.Sort(kit.MDB_NAME) return } @@ -443,6 +446,9 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", // 记录位置 m.Cmdy("aaa.location", arg[5:]) return + case "upload": + m.Cmdy(ice.WEB_STORY, "upload") + case "share": list := []string{} for k, v := range meta { diff --git a/core/mall/mall.go b/core/mall/mall.go index a87e2fdd..8eac9f52 100644 --- a/core/mall/mall.go +++ b/core/mall/mall.go @@ -13,18 +13,41 @@ import ( "time" ) +func input(m *ice.Message, arg ...string) bool { + if len(arg) > 0 && arg[0] == "action" { + switch arg[1] { + case "input": + switch arg[2] { + case "account", "to": + m.Richs("asset", nil, "*", func(key string, value map[string]interface{}) { + m.Push(arg[2], kit.Value(value, "meta.account")) + m.Push("count", kit.Value(value, "meta.count")) + }) + m.Sort("count", "int_r") + return true + case "type", "name", "text", "value": + m.Confm("asset", kit.Keys("meta.word", arg[2]), func(key string, value string) { + m.Push(arg[2], key) + m.Push("count", value) + }) + m.Sort("count", "int_r") + return true + } + } + } + return false +} + var Index = &ice.Context{Name: "mall", Help: "贸易中心", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ "railway": {Name: "railway", Help: "12306", Value: kit.Data()}, - "asset": {Name: "asset", Help: "资产", Value: kit.Data( - kit.MDB_SHORT, "account", "limit", "5000", - "site", kit.Dict( - "个税", "https://its.beijing.chinatax.gov.cn:8443/zmsqjl.html", - "社保", "http://fuwu.rsj.beijing.gov.cn/csibiz/indinfo/index.jsp", - "公积金", "https://grwsyw.gjj.beijing.gov.cn/ish/flow/menu/PPLGRZH0102?_r=0.6644871172745264", - ), - )}, + + "asset": {Name: "asset", Help: "资产", Value: kit.Data(kit.MDB_SHORT, "account", "site", kit.Dict( + "公积金", "https://grwsyw.gjj.beijing.gov.cn/ish/flow/menu/PPLGRZH0102?_r=0.6644871172745264", + "社保", "http://fuwu.rsj.beijing.gov.cn/csibiz/indinfo/index.jsp", + "个税", "https://its.beijing.chinatax.gov.cn:8443/zmsqjl.html", + ))}, }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -42,32 +65,43 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心", }}, "spend": {Name: "spend", Help: "支出", List: kit.List( - kit.MDB_INPUT, "text", "name", "account", - kit.MDB_INPUT, "text", "name", "name", - kit.MDB_INPUT, "text", "name", "text", - kit.MDB_INPUT, "text", "name", "value", + kit.MDB_INPUT, "text", "name", "account", "figure", "key", + kit.MDB_INPUT, "text", "name", "name", "figure", "key", + kit.MDB_INPUT, "text", "name", "value", "cb", "money", kit.MDB_INPUT, "button", "name", "记录", + kit.MDB_INPUT, "textarea", "name", "text", "figure", "key", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if input(m, arg...) { + return + } if len(arg) < 2 { + // 查看流水 m.Cmdy("asset", arg) return } + // 添加流水 amount := kit.Int(arg[3]) m.Cmdy("asset", arg[0], "", "支出", arg[1], arg[2], -amount, arg[4:]) m.Cmdy("asset", "流水", "", "支出", arg[1], arg[2], -amount, arg[4:]) }}, "trans": {Name: "trans", Help: "转账", List: kit.List( - kit.MDB_INPUT, "text", "name", "account", - kit.MDB_INPUT, "text", "name", "to", - kit.MDB_INPUT, "text", "name", "name", - kit.MDB_INPUT, "text", "name", "text", - kit.MDB_INPUT, "text", "name", "value", + kit.MDB_INPUT, "text", "name", "account", "figure", "key", + kit.MDB_INPUT, "text", "name", "to", "figure", "key", + kit.MDB_INPUT, "text", "name", "name", "figure", "key", + kit.MDB_INPUT, "text", "name", "text", "figure", "key", + kit.MDB_INPUT, "text", "name", "value", "cb", "money", kit.MDB_INPUT, "button", "name", "记录", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + // 输入补全 + if input(m, arg...) { + return + } if len(arg) < 2 { + // 查看流水 m.Cmdy("asset", arg) return } + // 添加流水 amount := kit.Int(arg[4]) m.Cmdy("asset", arg[0], "", "转出", arg[2], arg[3], -amount, arg[5:]) m.Cmd("asset", arg[1], "", "转入", arg[2], arg[3], amount, arg[5:]) @@ -75,16 +109,22 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心", m.Cmd("asset", "流水", "", "转入", arg[2], arg[3], amount, arg[5:]) }}, "bonus": {Name: "bonus", Help: "收入", List: kit.List( - kit.MDB_INPUT, "text", "name", "account", - kit.MDB_INPUT, "text", "name", "name", - kit.MDB_INPUT, "text", "name", "text", - kit.MDB_INPUT, "text", "name", "value", + kit.MDB_INPUT, "text", "name", "account", "figure", "key", + kit.MDB_INPUT, "text", "name", "name", "figure", "key", + kit.MDB_INPUT, "text", "name", "text", "figure", "key", + kit.MDB_INPUT, "text", "name", "value", "cb", "money", kit.MDB_INPUT, "button", "name", "记录", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + // 输入补全 + if input(m, arg...) { + return + } if len(arg) < 2 { + // 查看流水 m.Cmdy("asset", arg) return } + // 添加流水 m.Cmdy("asset", arg[0], "", "收入", arg[1:]) m.Cmdy("asset", "流水", "", "收入", arg[1:]) }}, @@ -235,10 +275,9 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心", }, List: kit.List( kit.MDB_INPUT, "text", "name", "account", "action", "auto", kit.MDB_INPUT, "text", "name", "id", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", + kit.MDB_INPUT, "button", "name", "查看", "action", "auto", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Option("cache.limit", "10000") if len(arg) == 0 { // 账户列表 m.Richs("asset", nil, "*", func(key string, value map[string]interface{}) { @@ -251,14 +290,17 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心", if len(arg) > 0 && arg[0] == "action" { switch arg[1] { case "modify": + // 修改数据 m.Richs("asset", nil, m.Option("account"), func(key string, account map[string]interface{}) { m.Grows("asset", kit.Keys("hash", key), "id", arg[5], func(index int, current map[string]interface{}) { + m.Log(ice.LOG_MODIFY, "%s: %d %s: %s->%s", key, index, kit.Value(current, arg[2]), arg[2], arg[3]) kit.Value(current, arg[2], arg[3]) }) }) case "save": - m.Option("cache.limit", "10000") + // 保存数据 + m.Option("cache.limit", -2) if f, p, e := kit.Create(arg[2]); m.Assert(e) { defer f.Close() @@ -285,7 +327,7 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心", } case "load": - m.Option("cache.limit", "10000") + // 加载数据 m.CSV(m.Cmdx("nfs.cat", arg[2])).Table(func(index int, data map[string]string, head []string) { v, _ := strconv.ParseFloat(data["金额"], 64) for _, account := range []string{kit.Select(data["账户"], arg, 3), "流水"} { @@ -331,8 +373,8 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心", m.Log(ice.LOG_CREATE, "account: %s", arg[0]) } + field := []string{"time", "id", "value", "type", "name", "text"} m.Richs("asset", nil, arg[0], func(key string, value map[string]interface{}) { - field := []string{"time", "id", "value", "type", "name", "text"} if len(arg) == 1 { // 消费流水 m.Grows("asset", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) { @@ -369,7 +411,12 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心", return } - // 添加流水 + // 词汇统计 + web.Count(m, cmd, "meta.word.type", arg[2]) + web.Count(m, cmd, "meta.word.name", arg[3]) + web.Count(m, cmd, "meta.word.text", arg[4]) + + // 数据结构 amount := kit.Int(arg[5]) extra := map[string]interface{}{} data := kit.Dict( @@ -382,14 +429,16 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心", kit.Value(extra, arg[i], arg[i+1]) } } - m.Grow("asset", kit.Keys("hash", key), data) + // 添加流水 + n := m.Grow("asset", kit.Keys("hash", key), data) // 账户结余 amount = kit.Int(kit.Value(value, "meta.amount")) + amount m.Log(ice.LOG_INSERT, "%s: %v", key, amount) kit.Value(value, "meta.amount", amount) - m.Echo("%d", amount) + m.Echo("%s: %d %d\n", arg[0], n, amount) + // 收支统计 switch data["type"] { case "收入": bonus := kit.Int(kit.Value(value, "meta.bonus")) + amount diff --git a/core/team/team.go b/core/team/team.go index c6005c66..29bba43c 100644 --- a/core/team/team.go +++ b/core/team/team.go @@ -185,10 +185,8 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", } // 词汇统计 - count := kit.Int(m.Conf(cmd, kit.Keys("meta.word", "type", arg[2]))) - m.Conf(cmd, kit.Keys("meta.word", "type", arg[2]), count+1) - count = kit.Int(m.Conf(cmd, kit.Keys("meta.word", "name", arg[3]))) - m.Conf(cmd, kit.Keys("meta.word", "name", arg[3]), count+1) + web.Count(m, cmd, "meta.word.type", arg[2]) + web.Count(m, cmd, "meta.word.name", arg[3]) // 数据结构 extra := kit.Dict() @@ -460,7 +458,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", kit.MDB_INPUT, "text", "name", "name", "figure", "key", kit.MDB_INPUT, "button", "name", "添加", kit.MDB_INPUT, "textarea", "name", "text", - kit.MDB_INPUT, "text", "name", "location", "figure", "key", "cb", "location", + kit.MDB_INPUT, "text", "name", "location", "figure", "key", "cb", "location", "className", "opts", ), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { if len(arg) > 0 && arg[0] == "action" { switch arg[1] { diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index 5d5fc9bb..1f341d17 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -444,15 +444,10 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", kit.MDB_INPUT, "text", "name", "name", kit.MDB_INPUT, "button", "name", "执行", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - kit.MDB_INPUT, "button", "name", "上传", "cb", "upload", + kit.MDB_INPUT, "button", "name", "上传", "figure", "upload", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if m.Option("_action") == "上传" { - if len(arg) == 0 { - arg = append(arg, "/") - } - m.Cmdy(ice.WEB_STORY, "upload") - m.Cmd(ice.WEB_STORY, ice.STORY_WATCH, m.Append("data"), - path.Join(m.Conf(cmd, "meta.path"), arg[0], kit.Select("", m.Append("name"), strings.HasSuffix(arg[0], "/")))) + web.Upload(m, path.Join(m.Conf(cmd, "meta.path"), kit.Select("", arg, 0))) return } @@ -523,7 +518,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Echo(path.Join(m.Conf(cmd, "meta.path"), arg[0])) }}, "walk": {Name: "walk", Help: "走遍世界", Meta: kit.Dict("display", "wiki/walk"), List: kit.List( - kit.MDB_INPUT, "text", "name", "file", + kit.MDB_INPUT, "text", "name", "file", "figure", "province", kit.MDB_INPUT, "button", "name", "执行", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/misc/chrome/chrome.go b/misc/chrome/chrome.go index f0df2374..9f5704c2 100644 --- a/misc/chrome/chrome.go +++ b/misc/chrome/chrome.go @@ -7,7 +7,7 @@ import ( "github.com/shylinux/toolkits" ) -var Index = &ice.Context{Name: "chrome", Help: "chrome", +var Index = &ice.Context{Name: "chrome", Help: "浏览器", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ "chrome": {Name: "chrome", Help: "chrome", Value: kit.Data(kit.MDB_SHORT, "name")}, @@ -27,7 +27,7 @@ var Index = &ice.Context{Name: "chrome", Help: "chrome", m.Cmdy("history", arg[1:]) } }}, - "chrome": {Name: "chrome", Help: "标签", List: kit.List( + "chrome": {Name: "chrome", Help: "浏览器", List: kit.List( kit.MDB_INPUT, "text", "name", "name", "action", "auto", kit.MDB_INPUT, "text", "name", "wid", "action", "auto", kit.MDB_INPUT, "text", "name", "url", @@ -35,6 +35,7 @@ var Index = &ice.Context{Name: "chrome", Help: "chrome", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", ), Meta: kit.Dict("detail", []string{"编辑", "goBack", "goForward", "duplicate", "reload", "remove"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { + // 窗口列表 m.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) { if kit.Format(value["type"]) == "chrome" { m.Push(key, value, []string{"time", "name"}) @@ -42,12 +43,12 @@ var Index = &ice.Context{Name: "chrome", Help: "chrome", }) return } - if arg[0] == "action" { + // 命令转换 m.Cmdy(ice.WEB_SPACE, m.Option("name"), "tabs", m.Option("tid"), arg[1]) arg = []string{m.Option("name"), m.Option("wid")} } - + // 下发命令 m.Cmdy(ice.WEB_SPACE, arg[0], "wins", arg[1:]) }}, "cookie": {Name: "cookie", Help: "数据", List: kit.List( @@ -57,29 +58,28 @@ var Index = &ice.Context{Name: "chrome", Help: "chrome", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", ), Meta: kit.Dict("detail", []string{"编辑", "删除"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { - m.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) { - if kit.Format(value["type"]) == "chrome" { - m.Push(key, value, []string{"time", "name"}) - } - }) + // 窗口列表 + m.Cmdy("chrome") return } - if arg[0] == "action" { + // 命令转换 m.Cmdy(ice.WEB_SPACE, m.Option("name"), "cookie", arg[1:]) arg = []string{m.Option("name"), m.Option("id")} } - + // 下发命令 m.Cmdy(ice.WEB_SPACE, arg[0], "cookie", arg[1:]) }}, "history": {Name: "history id url title", Help: "历史", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { + // 查看记录 m.Grows("history", nil, "", "", func(index int, value map[string]interface{}) { m.Push("", value) }) m.Sort("id", "int_r") return } + // 添加记录 m.Grow("history", nil, kit.Dict("hid", arg[0], "url", arg[1], "title", arg[2])) }}, "bookmark": {Name: "bookmark", Help: "书签", List: kit.List( @@ -89,19 +89,16 @@ var Index = &ice.Context{Name: "chrome", Help: "chrome", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", ), Meta: kit.Dict("detail", []string{"编辑", "删除"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { - m.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) { - if kit.Format(value["type"]) == "chrome" { - m.Push(key, value, []string{"time", "name"}) - } - }) + // 窗口列表 + m.Cmdy("chrome") return } - if arg[0] == "action" { + // 命令转换 m.Cmdy(ice.WEB_SPACE, m.Option("name"), "bookmark", arg[1:]) arg = []string{m.Option("name"), m.Option("id")} } - + // 下发命令 m.Cmdy(ice.WEB_SPACE, arg[0], "bookmark", arg[1:]) }}, }, diff --git a/misc/chrome/chrome.md b/misc/chrome/chrome.md deleted file mode 100644 index bced8432..00000000 --- a/misc/chrome/chrome.md +++ /dev/null @@ -1 +0,0 @@ -# {{title "crx"}} diff --git a/misc/chrome/shy.log b/misc/chrome/shy.log deleted file mode 100644 index 84636502..00000000 --- a/misc/chrome/shy.log +++ /dev/null @@ -1,140 +0,0 @@ -2020-02-05 02:22:41 input v 21 53 -2020-02-05 02:22:41 input o 21 54 -2020-02-05 02:22:41 input l 21 55 -2020-02-05 02:22:41 input c 21 56 -2020-02-05 02:22:41 input a 21 57 -2020-02-05 02:22:42 input n 21 58 -2020-02-05 02:22:42 input o 21 59 -2020-02-05 02:22:42 input s 21 60 -2020-02-05 02:22:50 input l 22 46 -2020-02-05 02:22:50 input o 22 47 -2020-02-05 02:22:50 input c 22 48 -2020-02-05 02:22:50 input a 22 49 -2020-02-05 02:22:50 input l 22 50 -2020-02-05 02:22:50 input h 22 51 -2020-02-05 02:22:50 input o 22 52 -2020-02-05 02:22:51 input s 22 53 -2020-02-05 02:22:51 input t 22 54 -2020-02-05 02:22:51 input : 22 55 -2020-02-05 02:22:52 input 9 22 56 -2020-02-05 02:22:52 input 0 22 57 -2020-02-05 02:22:52 input 2 22 58 -2020-02-05 02:22:52 input 0 22 59 -2020-02-05 10:48:58 input c 10 33 -2020-02-05 10:48:58 input r 10 34 -2020-02-05 10:48:59 input h 10 35 -2020-02-05 10:48:59 input o 10 36 -2020-02-05 10:48:59 input m 10 37 -2020-02-05 10:48:59 input e 10 38 -2020-02-05 10:49:00 input c 10 33 -2020-02-05 10:49:00 input h 10 34 -2020-02-05 10:49:01 input r 10 35 -2020-02-05 10:49:01 input o 10 36 -2020-02-05 10:49:01 input m 10 37 -2020-02-05 10:49:01 input e 10 38 -2020-02-05 10:49:02 input c 10 49 -2020-02-05 10:49:02 input r 10 50 -2020-02-05 10:49:02 input h 10 51 -2020-02-05 10:49:02 input o 10 52 -2020-02-05 10:49:02 input m 10 53 -2020-02-05 10:49:02 input e 10 54 -2020-02-05 10:49:02 input c 10 49 -2020-02-05 10:49:02 input h 10 50 -2020-02-05 10:49:02 input r 10 51 -2020-02-05 10:49:02 input o 10 52 -2020-02-05 10:49:02 input m 10 53 -2020-02-05 10:49:02 input e 10 54 -2020-02-05 10:49:04 input c 13 4 -2020-02-05 10:49:04 input r 13 5 -2020-02-05 10:49:04 input h 13 6 -2020-02-05 10:49:04 input o 13 7 -2020-02-05 10:49:04 input m 13 8 -2020-02-05 10:49:04 input e 13 9 -2020-02-05 10:49:04 input c 13 4 -2020-02-05 10:49:04 input h 13 5 -2020-02-05 10:49:04 input r 13 6 -2020-02-05 10:49:04 input o 13 7 -2020-02-05 10:49:04 input m 13 8 -2020-02-05 10:49:04 input e 13 9 -2020-02-05 10:49:05 input c 13 21 -2020-02-05 10:49:05 input r 13 22 -2020-02-05 10:49:05 input h 13 23 -2020-02-05 10:49:05 input o 13 24 -2020-02-05 10:49:05 input m 13 25 -2020-02-05 10:49:05 input e 13 26 -2020-02-05 10:49:05 input c 13 21 -2020-02-05 10:49:05 input h 13 22 -2020-02-05 10:49:05 input r 13 23 -2020-02-05 10:49:05 input o 13 24 -2020-02-05 10:49:05 input m 13 25 -2020-02-05 10:49:05 input e 13 26 -2020-02-05 10:49:05 input c 13 37 -2020-02-05 10:49:05 input r 13 38 -2020-02-05 10:49:05 input h 13 39 -2020-02-05 10:49:05 input o 13 40 -2020-02-05 10:49:05 input m 13 41 -2020-02-05 10:49:05 input e 13 42 -2020-02-05 10:49:05 input c 13 37 -2020-02-05 10:49:05 input h 13 38 -2020-02-05 10:49:05 input r 13 39 -2020-02-05 10:49:05 input o 13 40 -2020-02-05 10:49:05 input m 13 41 -2020-02-05 10:49:05 input e 13 42 -2020-02-05 10:49:06 input c 19 31 -2020-02-05 10:49:06 input r 19 32 -2020-02-05 10:49:06 input h 19 33 -2020-02-05 10:49:06 input o 19 34 -2020-02-05 10:49:06 input m 19 35 -2020-02-05 10:49:06 input e 19 36 -2020-02-05 10:49:06 input c 19 31 -2020-02-05 10:49:06 input h 19 32 -2020-02-05 10:49:06 input r 19 33 -2020-02-05 10:49:06 input o 19 34 -2020-02-05 10:49:06 input m 19 35 -2020-02-05 10:49:06 input e 19 36 -2020-02-05 10:49:07 input c 22 4 -2020-02-05 10:49:07 input r 22 5 -2020-02-05 10:49:07 input h 22 6 -2020-02-05 10:49:07 input o 22 7 -2020-02-05 10:49:07 input m 22 8 -2020-02-05 10:49:07 input e 22 9 -2020-02-05 10:49:07 input c 22 4 -2020-02-05 10:49:07 input h 22 5 -2020-02-05 10:49:07 input r 22 6 -2020-02-05 10:49:07 input o 22 7 -2020-02-05 10:49:07 input m 22 8 -2020-02-05 10:49:07 input e 22 9 -2020-02-05 10:49:07 input c 22 21 -2020-02-05 10:49:07 input r 22 22 -2020-02-05 10:49:07 input h 22 23 -2020-02-05 10:49:07 input o 22 24 -2020-02-05 10:49:07 input m 22 25 -2020-02-05 10:49:07 input e 22 26 -2020-02-05 10:49:07 input c 22 21 -2020-02-05 10:49:07 input h 22 22 -2020-02-05 10:49:07 input r 22 23 -2020-02-05 10:49:07 input o 22 24 -2020-02-05 10:49:07 input m 22 25 -2020-02-05 10:49:07 input e 22 26 -2020-02-05 10:49:08 input c 22 37 -2020-02-05 10:49:08 input r 22 38 -2020-02-05 10:49:08 input h 22 39 -2020-02-05 10:49:08 input o 22 40 -2020-02-05 10:49:08 input m 22 41 -2020-02-05 10:49:08 input e 22 42 -2020-02-05 10:49:08 input c 22 37 -2020-02-05 10:49:08 input h 22 38 -2020-02-05 10:49:08 input r 22 39 -2020-02-05 10:49:08 input o 22 40 -2020-02-05 10:49:08 input m 22 41 -2020-02-05 10:49:08 input e 22 42 -2020-02-05 10:49:13 input c 19 5 -2020-02-05 10:49:14 input r 19 6 -2020-02-05 10:49:14 input x 19 7 -2020-02-05 10:49:17 input c 19 20 -2020-02-05 10:49:17 input r 19 21 -2020-02-05 10:49:18 input x 19 22 -2020-02-05 10:49:22 input / 19 33 -2020-02-05 10:49:22 input c 19 34 -2020-02-05 10:49:22 input r 19 35 -2020-02-05 10:49:23 input x 19 36 diff --git a/misc/docker/docker.go b/misc/docker/docker.go index 1cc26ad3..05b90e64 100644 --- a/misc/docker/docker.go +++ b/misc/docker/docker.go @@ -7,10 +7,10 @@ import ( "strings" ) -var Index = &ice.Context{Name: "docker", Help: "容器管理", +var Index = &ice.Context{Name: "docker", Help: "虚拟机", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ - "docker": {Name: "docker", Help: "docker", Value: kit.Data(kit.MDB_SHORT, "name")}, + "docker": {Name: "docker", Help: "虚拟机", Value: kit.Data(kit.MDB_SHORT, "name")}, }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/misc/git/git.go b/misc/git/git.go index ca3ca1a2..3c71b500 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -11,7 +11,7 @@ import ( "time" ) -var Index = &ice.Context{Name: "git", Help: "代码管理", +var Index = &ice.Context{Name: "git", Help: "代码库", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ "repos": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "owner", "https://github.com/shylinux")}, @@ -123,10 +123,21 @@ var Index = &ice.Context{Name: "git", Help: "代码管理", } }) }}, - "total": {Name: "total", Help: "统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "total": {Name: "total", Help: "统计", List: kit.List( + kit.MDB_INPUT, "text", "name", "repos", "action", "auto", + kit.MDB_INPUT, "button", "name", "查看", "action", "auto", + kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", + ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) > 0 { + m.Richs("repos", nil, arg[0], func(key string, value map[string]interface{}) { + m.Cmdy("sum", kit.Value(value, "meta.path"), arg[1:]) + }) + return + } + days := 0 commit, adds, dels, rest := 0, 0, 0, 0 - m.Richs("repos", nil, kit.Select("*", arg, 0), func(key string, value map[string]interface{}) { + m.Richs("repos", nil, "*", func(key string, value map[string]interface{}) { m.Push("repos", kit.Value(value, "meta.name")) m.Copy(m.Cmd("sum", kit.Value(value, "meta.path"), "total", "10000").Table(func(index int, value map[string]string, head []string) { if kit.Int(value["days"]) > days { @@ -176,7 +187,7 @@ var Index = &ice.Context{Name: "git", Help: "代码管理", if len(arg) > 0 { args = append(args, kit.Select("-n", "--since", strings.Contains(arg[0], "-"))) if strings.Contains(arg[0], "-") && !strings.Contains(arg[0], ":") { - arg[1] = arg[1] + " 00:00:00" + arg[0] = arg[0] + " 00:00:00" } args = append(args, arg[0:]...) } else { diff --git a/misc/input/input.md b/misc/input/input.md deleted file mode 100644 index a7505685..00000000 --- a/misc/input/input.md +++ /dev/null @@ -1 +0,0 @@ -# {{title "input"}} diff --git a/misc/input/input.vim b/misc/input/input.vim deleted file mode 100644 index 3110f36d..00000000 --- a/misc/input/input.vim +++ /dev/null @@ -1,45 +0,0 @@ - -" 变量定义 -func! InputDefine(name, value) - if !exists("name") | exec "let " . a:name . " = \"" . a:value . "\"" | endif -endfunc - -" 输出日志 -call InputDefine("g:InputLog", "input.log") -fun! InputLog(txt) - call writefile([strftime("%Y-%m-%d %H:%M:%S ") . join(a:txt, "")], g:InputLog, "a") -endfun - -" 输入转换 -call InputDefine("g:InputTrans", "localhost:9020/code/input/") -fun! InputTrans(code) - let res = [] - for line in split(system("curl -s " . g:InputTrans . a:code), "\n") - let word = split(line, " ") - if len(word) > 1 | call extend(res, [word[1]]) | endif - endfor - let res = extend(res, [a:code]) - return l:res -endfun - -" 输入补全 -fun! InputComplete(firststart, base) - call InputLog(["complete", a:base, "(", col("."), ",", line("."), ")", getline(".")]) - if a:firststart - " locate the start of the word - let line = getline('.') - let start = col('.') - 1 - while start > 0 && line[start - 1] =~ '\a' - let start -= 1 - endwhile - return start - else - " find months matching with "a:base" - " retu - return InputTrans(a:base) - endif -endfun -set completefunc=InputComplete - -" autocmd InsertEnter * call ShySync("insert") -" autocmd InsertCharPre * call InputCheck() diff --git a/misc/lark/lark.go b/misc/lark/lark.go index c3665144..dbbbc96d 100644 --- a/misc/lark/lark.go +++ b/misc/lark/lark.go @@ -48,7 +48,7 @@ func parse(m *ice.Message) { m.Info("msg: %v", kit.Formats(data)) } -var Index = &ice.Context{Name: "lark", Help: "lark", +var Index = &ice.Context{Name: "lark", Help: "机器人", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ "app": &ice.Config{Name: "app", Help: "服务配置", Value: kit.Data(kit.MDB_SHORT, "name", "lark", "https://open.feishu.cn")}, @@ -63,13 +63,14 @@ var Index = &ice.Context{Name: "lark", Help: "lark", m.Cmd(ice.WEB_SPIDE, "add", "lark", m.Conf("app", "meta.lark")) }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Save("app") + m.Save("app", "user") }}, "app": {Name: "app login|token bot", Help: "应用", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { if len(arg) == 0 { + // 应用列表 m.Richs("app", nil, "*", func(key string, value map[string]interface{}) { - m.Push("key", value) + m.Push("key", value, []string{"time", "name", "id", "expire"}) }) return } @@ -90,6 +91,7 @@ var Index = &ice.Context{Name: "lark", Help: "lark", }) case "watch": + // 消息通知 for _, v := range arg[3:] { m.Watch(v, "web.chat.lark.send", arg[1], arg[2], v) } @@ -168,7 +170,6 @@ var Index = &ice.Context{Name: "lark", Help: "lark", post(m, "bot", "GET", "/open-apis/user/v1/batch_get_id", us) } - return }}, "send": {Name: "send [chat_id|open_id|user_id|email] who [menu] [title] text", Help: "消息", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { var form = map[string]interface{}{"content": map[string]interface{}{}} @@ -271,11 +272,10 @@ var Index = &ice.Context{Name: "lark", Help: "lark", post(m, "bot", "/open-apis/message/v4/send/", "data", kit.Formats(form)) return }}, - "/msg": {Name: "/msg", Help: "消息", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { - parse(m) - - switch m.Option("msg.type") { + "/msg": {Name: "/msg", Help: "聊天消息", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { + switch parse(m); m.Option("msg.type") { case "url_verification": + // 绑定验证 m.Push("_output", "result") m.Echo(kit.Format(map[string]interface{}{"challenge": m.Option("msg.challenge")})) @@ -283,26 +283,41 @@ var Index = &ice.Context{Name: "lark", Help: "lark", switch m.Option("type") { case "chat_disband": case "p2p_chat_create": + // 创建对话 if m.Options("open_chat_id") { - m.Cmdy(".send", m.Option("open_chat_id"), "我们做朋友吧~") + m.Cmdy("send", m.Option("open_chat_id"), "我们做朋友吧~") } case "add_bot": + // 加入群聊 if m.Options("open_chat_id") { - m.Cmdy(".send", m.Option("open_chat_id"), "我来也~") + m.Cmdy("send", m.Option("open_chat_id"), "我来也~") } default: if m.Options("open_chat_id") { + // 用户登录 m.Option(ice.MSG_USERNAME, m.Option("open_id")) m.Option(ice.MSG_USERROLE, m.Cmdx(ice.AAA_ROLE, "check", m.Option(ice.MSG_USERNAME))) - if cmd := kit.Split(m.Option("text_without_at_bot")); m.Right(cmd) { - m.Cmdy(cmd) - } else { + m.Info("%s: %s", m.Option(ice.MSG_USERROLE), m.Option(ice.MSG_USERNAME)) + m.Option(ice.MSG_SESSID, m.Cmdx(ice.AAA_USER, "login", m.Option(ice.MSG_USERNAME))) + + if cmd := kit.Split(m.Option("text_without_at_bot")); !m.Right(cmd) { m.Echo("no right") + } else { + // 执行命令 + msg := m.Cmd(cmd) + if m.Hand = false; !msg.Hand { + msg = m.Cmd(ice.CLI_SYSTEM, cmd) + } + if msg.Result() == "" { + msg.Table() + } + // 返回结果 + m.Cmdy("send", m.Option("open_chat_id"), kit.Select("你好", msg.Result())) } - m.Cmdy("send", m.Option("open_chat_id"), kit.Select("你好", m.Result())) } } case "event_click": + // 消息卡片 m.Echo(kit.Format(map[string]interface{}{ "header": map[string]interface{}{ "title": map[string]interface{}{ diff --git a/misc/lark/lark.md b/misc/lark/lark.md deleted file mode 100644 index 2b91953a..00000000 --- a/misc/lark/lark.md +++ /dev/null @@ -1 +0,0 @@ -# {{title "lk"}} diff --git a/misc/mp/mp.go b/misc/mp/mp.go index 118b6193..00770396 100644 --- a/misc/mp/mp.go +++ b/misc/mp/mp.go @@ -5,7 +5,6 @@ import ( "github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/core/chat" "github.com/shylinux/toolkits" - "time" ) var Index = &ice.Context{Name: "mp", Help: "小程序", @@ -35,34 +34,16 @@ var Index = &ice.Context{Name: "mp", Help: "小程序", msg := m.Cmd(ice.WEB_SPIDE, "weixin", "GET", m.Conf("login", "meta.auth"), "js_code", m.Option("code"), "appid", m.Conf("login", "meta.appid"), "secret", m.Conf("login", "meta.appmm")) - if m.Richs(ice.AAA_USER, nil, msg.Append("openid"), nil) == nil { - // 创建用户 - m.Rich(ice.AAA_USER, nil, kit.Dict( - "username", msg.Append("openid"), - "expires_in", time.Now().Unix()+kit.Int64(msg.Append("expires_in")), - "session_key", msg.Append("session_key"), - "usernode", m.Conf(ice.CLI_RUNTIME, "boot.hostname"), - )) - m.Event(ice.USER_CREATE, msg.Append("openid")) - } - - if m.Options(ice.MSG_SESSID) && m.Cmdx(ice.AAA_SESS, "check", m.Option(ice.MSG_SESSID)) == msg.Append("openid") { - // 复用会话 - m.Echo(m.Option(ice.MSG_SESSID)) - } else { - // 创建会话 - role := m.Conf("login", kit.Keys("meta.userrole", msg.Append("openid"))) - sessid := m.Rich(ice.AAA_SESS, nil, kit.Dict( - "username", msg.Append("openid"), "userrole", role, - )) - m.Info("user: %s role: %s sess: %s", msg.Append("openid"), role, sessid) - m.Echo(msg.Option(ice.MSG_SESSID, sessid)) - } + // 用户登录 + m.Option(ice.MSG_USERNAME, msg.Append("openid")) + m.Option(ice.MSG_USERROLE, m.Cmdx(ice.AAA_ROLE, "check", m.Option("FromUserName"))) + m.Info("%s: %s", m.Option(ice.MSG_USERROLE), m.Option(ice.MSG_USERNAME)) + m.Echo(m.Option(ice.MSG_SESSID, m.Cmdx(ice.AAA_USER, "login", m.Option(ice.MSG_USERNAME)))) case "info": + // 用户信息 m.Richs(ice.AAA_SESS, nil, m.Option(ice.MSG_SESSID), func(key string, value map[string]interface{}) { m.Richs(ice.AAA_USER, nil, value["username"], func(key string, value map[string]interface{}) { - // 注册用户 value["gender"] = m.Option("gender") value["avatar"] = m.Option("avatarUrl") value["nickname"] = m.Option("nickName") @@ -81,15 +62,21 @@ var Index = &ice.Context{Name: "mp", Help: "小程序", m.Echo("401").Push("_output", "status") break } - m.Cmd(ice.WEB_SPACE, "auth", m.Option("auth"), m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERROLE)) + switch m.Option("type") { + case "active": + // 授权登录 + m.Cmd(ice.WEB_SPACE, "auth", m.Option("auth"), m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERROLE)) + } case "cmds": - if arg = kit.Split(arg[1]); m.Right(arg) { - m.Hand = false - if m.Cmdy(arg); !m.Hand { - m.Set("result") - m.Cmdy(ice.CLI_SYSTEM, arg) - } + if arg = kit.Split(arg[1]); !m.Right(arg) { + return + } + + // 执行命令 + msg := m.Cmd(arg) + if m.Hand = false; !msg.Hand { + msg = m.Cmd(ice.CLI_SYSTEM, arg) } } }}, diff --git a/misc/pi/pi.go b/misc/pi/pi.go index 0fc30e58..fe102043 100644 --- a/misc/pi/pi.go +++ b/misc/pi/pi.go @@ -8,7 +8,7 @@ import ( "path" ) -var Index = &ice.Context{Name: "pi", Help: "pi", +var Index = &ice.Context{Name: "pi", Help: "开发板", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ "pi": {Name: "pi", Help: "pi", Value: kit.Data(kit.MDB_SHORT, "name")}, diff --git a/misc/tmux/tmux.go b/misc/tmux/tmux.go index bd3cef95..1fe33a92 100644 --- a/misc/tmux/tmux.go +++ b/misc/tmux/tmux.go @@ -26,7 +26,7 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool { return true } -var Index = &ice.Context{Name: "tmux", Help: "终端管理", +var Index = &ice.Context{Name: "tmux", Help: "命令行", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ "buffer": {Name: "buffer", Help: "缓存", Value: kit.Data()}, diff --git a/misc/wx/wx.go b/misc/wx/wx.go index 2f6ba964..66af56f0 100644 --- a/misc/wx/wx.go +++ b/misc/wx/wx.go @@ -1,17 +1,36 @@ package wx import ( - "crypto/sha1" - "encoding/hex" - "encoding/xml" "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/core/chat" "github.com/shylinux/toolkits" + + "crypto/sha1" + "encoding/hex" + "encoding/xml" "sort" "strings" ) +func parse(m *ice.Message) { + data := struct { + ToUserName string + FromUserName string + CreateTime int + MsgId int64 + MsgType string + Content string + }{} + xml.NewDecoder(m.R.Body).Decode(&data) + m.Option("ToUserName", data.ToUserName) + m.Option("FromUserName", data.FromUserName) + m.Option("CreateTime", data.CreateTime) + + m.Option("MsgType", data.MsgType) + m.Option("Content", data.Content) +} + func reply(m *ice.Message) { m.Push("_output", "result") m.Render(m.Conf("login", "meta.template.text")) @@ -89,58 +108,37 @@ var Index = &ice.Context{Name: "wx", Help: "公众号", "/login/": {Name: "/login/", Help: "认证", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { check := []string{m.Conf("login", "meta.token"), m.Option("timestamp"), m.Option("nonce")} sort.Strings(check) - b := sha1.Sum([]byte(strings.Join(check, ""))) - if m.Warn(m.Option("signature") != hex.EncodeToString(b[:]), "error") { + if b := sha1.Sum([]byte(strings.Join(check, ""))); m.Warn(m.Option("signature") != hex.EncodeToString(b[:]), "error") { // 验证失败 return } if m.Option("echostr") != "" { + // 绑定验证 m.Push("_output", "result") m.Echo(m.Option("echostr")) - // 绑定验证 return } // 解析数据 - data := struct { - ToUserName string - FromUserName string - CreateTime int - MsgType string - Content string - MsgId int64 - }{} - xml.NewDecoder(m.R.Body).Decode(&data) - m.Option("ToUserName", data.ToUserName) - m.Option("FromUserName", data.FromUserName) - m.Option("CreateTime", data.CreateTime) + parse(m) - m.Option(ice.MSG_USERNAME, data.FromUserName) - if m.Richs(ice.AAA_USER, nil, m.Option(ice.MSG_USERNAME), nil) == nil { - // 创建用户 - m.Rich(ice.AAA_USER, nil, kit.Dict( - "username", m.Option(ice.MSG_USERNAME), - "usernode", m.Conf(ice.CLI_RUNTIME, "boot.hostname"), - )) - m.Event(ice.USER_CREATE, m.Option(ice.MSG_USERNAME)) - } - - m.Option(ice.MSG_USERROLE, m.Cmdx(ice.AAA_ROLE, "check", data.FromUserName)) + // 用户登录 + m.Option(ice.MSG_USERNAME, m.Option("FromUserName")) + m.Option(ice.MSG_USERROLE, m.Cmdx(ice.AAA_ROLE, "check", m.Option("FromUserName"))) m.Info("%s: %s", m.Option(ice.MSG_USERROLE), m.Option(ice.MSG_USERNAME)) + m.Option(ice.MSG_SESSID, m.Cmdx(ice.AAA_USER, "login", m.Option(ice.MSG_USERNAME))) - m.Option(ice.MSG_SESSID, m.Cmdx(ice.AAA_SESS, "create", m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERROLE))) - m.Info("sessid: %s", m.Option(ice.MSG_SESSID)) - - switch m.Option("MsgType", data.MsgType) { + switch m.Option("MsgType") { case "text": - if cmds := kit.Split(data.Content); !m.Right(cmds) { + if cmds := kit.Split(m.Option("Content")); !m.Right(cmds) { action(m.Cmdy("menu")) } else { switch cmds[0] { case "menu": action(m.Cmdy("menu")) default: + // 执行命令 msg := m.Cmd(cmds) if m.Hand = false; !msg.Hand { msg = m.Cmd(ice.CLI_SYSTEM, cmds) @@ -148,6 +146,8 @@ var Index = &ice.Context{Name: "wx", Help: "公众号", if msg.Result() == "" { msg.Table() } + + // 返回结果 reply(m.Push("reply", msg.Result())) } } diff --git a/misc/wx/wx.md b/misc/wx/wx.md deleted file mode 100644 index 6e1bb64b..00000000 --- a/misc/wx/wx.md +++ /dev/null @@ -1 +0,0 @@ -# {{title "wx"}}