1
0
forked from x/icebergs
This commit is contained in:
shylinux 2020-07-23 14:17:04 +08:00
parent 7d3dcb2670
commit ccc7fe2d58
9 changed files with 27 additions and 10 deletions

View File

@ -5,6 +5,9 @@ import (
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
) )
const (
ErrNotAuth = "not auth: "
)
const ( const (
USERNICK = "usernick" USERNICK = "usernick"
USERNAME = "username" USERNAME = "username"

View File

@ -72,7 +72,7 @@ func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
ok = true ok = true
} }
} }
if m.Warn(!ok, "%s no right %s", userrole, keys) { if m.Warn(!ok, ErrNotAuth, userrole, " of ", keys) {
return return
} }
// 普通用户 // 普通用户

View File

@ -124,9 +124,11 @@ func _action_show(m *ice.Message, river, storm, index string, arg ...string) {
cmds = kit.Simple(kit.Keys(value[CTX], value[CMD]), arg) cmds = kit.Simple(kit.Keys(value[CTX], value[CMD]), arg)
} }
}) })
} else if !m.Warn(!m.Right(index), "no right of %v", index) { } else if m.Right(index) {
// 定制命令 // 定制命令
cmds = kit.Simple(index, arg) cmds = kit.Simple(index, arg)
} else {
return
} }
if len(cmds) == 0 { if len(cmds) == 0 {
m.Render("status", 404, "not found") m.Render("status", 404, "not found")

View File

@ -37,6 +37,9 @@ func _inner_show(m *ice.Message, ext, file, dir string, arg ...string) {
} }
} }
func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) { func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) {
if !m.Right(strings.Split(dir, "/"), file) {
return
}
if m.Cmdy(mdb.RENDER, ext, file, dir, arg); m.Result() == "" { if m.Cmdy(mdb.RENDER, ext, file, dir, arg); m.Result() == "" {
if m.Conf(INNER, kit.Keys("meta.source", ext)) == "true" { if m.Conf(INNER, kit.Keys("meta.source", ext)) == "true" {
if m.Cmdy(mdb.RENDER, nfs.FILE, file, dir, arg); m.Result() == "" { if m.Cmdy(mdb.RENDER, nfs.FILE, file, dir, arg); m.Result() == "" {

View File

@ -353,7 +353,9 @@ func init() {
}}, }},
FIELD: {Name: "field name cmd", Help: "插件", Action: map[string]*ice.Action{ FIELD: {Name: "field name cmd", Help: "插件", Action: map[string]*ice.Action{
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) { "run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
if m.Right(arg[1:]) {
m.Cmdy(arg[1:]) m.Cmdy(arg[1:])
}
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_field_show(m, arg[0], arg[1], arg[2:]...) _field_show(m, arg[0], arg[1], arg[2:]...)

View File

@ -9,7 +9,8 @@ import (
) )
var ErrWarn = "warn: " var ErrWarn = "warn: "
var ErrNotFound = "not found " var ErrNotAuth = "not auth: "
var ErrNotFound = "not found: "
func (m *Message) log(level string, str string, arg ...interface{}) *Message { func (m *Message) log(level string, str string, arg ...interface{}) *Message {
if str = strings.TrimSpace(kit.Format(str, arg...)); Log != nil { if str = strings.TrimSpace(kit.Format(str, arg...)); Log != nil {

View File

@ -4,6 +4,7 @@ import (
kit "github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
"fmt" "fmt"
"strings"
"sync/atomic" "sync/atomic"
) )
@ -39,7 +40,7 @@ func (m *Message) Event(key string, arg ...string) *Message {
return m return m
} }
func (m *Message) Right(arg ...interface{}) bool { func (m *Message) Right(arg ...interface{}) bool {
return m.Option(MSG_USERROLE) == "root" || !m.Warn(m.Cmdx("aaa.role", "right", m.Option(MSG_USERROLE), kit.Keys(arg...)) != "ok", "no right") return m.Option(MSG_USERROLE) == "root" || !m.Warn(m.Cmdx("aaa.role", "right", m.Option(MSG_USERROLE), kit.Keys(arg...)) != "ok", ErrNotAuth, strings.Join(kit.Simple(arg), "."))
} }
func (m *Message) Space(arg interface{}) []string { func (m *Message) Space(arg interface{}) []string {
if arg == nil || arg == "" || kit.Format(arg) == m.Conf("cli.runtime", "node.name") { if arg == nil || arg == "" || kit.Format(arg) == m.Conf("cli.runtime", "node.name") {

View File

@ -151,7 +151,7 @@ var Index = &ice.Context{Name: "lark", Help: "机器人",
kit.Fetch(kit.Value(data, "data.user_list"), func(index int, value map[string]interface{}) { kit.Fetch(kit.Value(data, "data.user_list"), func(index int, value map[string]interface{}) {
msg := m.Cmd(m.Prefix(USER), value[OPEN_ID]) msg := m.Cmd(m.Prefix(USER), value[OPEN_ID])
m.Push("avatar", m.Cmdx(mdb.RENDER, web.RENDER.IMG, msg.Append("avatar_72"))) m.Push("avatar", m.Cmdx(mdb.RENDER, web.RENDER.IMG, msg.Append("avatar_72")))
m.Push("gender", kit.Select("男", "女", msg.Append("gender") == "1")) m.Push("gender", kit.Select("男", "女", msg.Append("gender") == "2"))
m.Push(kit.MDB_NAME, msg.Append(kit.MDB_NAME)) m.Push(kit.MDB_NAME, msg.Append(kit.MDB_NAME))
m.Push("description", msg.Append("description")) m.Push("description", msg.Append("description"))
m.Push(OPEN_ID, msg.Append(OPEN_ID)) m.Push(OPEN_ID, msg.Append(OPEN_ID))
@ -436,7 +436,8 @@ var Index = &ice.Context{Name: "lark", Help: "机器人",
// }}, // }},
web.LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, web.LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
"/msg": {Name: "/msg", Help: "聊天消息", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { "/msg": {Name: "/msg", Help: "聊天消息", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if data := m.Optionv(ice.MSG_USERDATA); kit.Value(data, "action") != nil { data := m.Optionv(ice.MSG_USERDATA)
if kit.Value(data, "action") != nil {
kit.Fetch(kit.Value(data, "action.value"), func(key string, value string) { kit.Fetch(kit.Value(data, "action.value"), func(key string, value string) {
m.Option(key, value) m.Option(key, value)
}) })
@ -485,9 +486,13 @@ var Index = &ice.Context{Name: "lark", Help: "机器人",
if m.Cmdy(TALK, strings.TrimSpace(m.Option("text_without_at_bot"))); len(m.Resultv()) > 0 { if m.Cmdy(TALK, strings.TrimSpace(m.Option("text_without_at_bot"))); len(m.Resultv()) > 0 {
m.Cmd(SEND, m.Option(OPEN_CHAT_ID), m.Result()) m.Cmd(SEND, m.Option(OPEN_CHAT_ID), m.Result())
} }
} else {
m.Cmd(DUTY, m.Option("msg.type"), kit.Formats(data))
} }
} }
} }
default:
m.Cmd(DUTY, m.Option("msg.type"), kit.Formats(data))
} }
}}, }},
"/sso": {Name: "/sso", Help: "网页", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { "/sso": {Name: "/sso", Help: "网页", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {

View File

@ -11,9 +11,9 @@ refer "官网" `
field "ship" web.chat.lark.ship field "ship" web.chat.lark.ship
field "group" web.chat.lark.group field "group" web.chat.lark.group
field "date" web.chat.lark.date # field "date" web.chat.lark.date
field "meta" web.chat.lark.meta # field "meta" web.chat.lark.meta
#
section "icebergs" section "icebergs"
field "icebergs_统计" web.code.git.trend args `[ icebergs ]` action `{ height 200 speed 20 }` field "icebergs_统计" web.code.git.trend args `[ icebergs ]` action `{ height 200 speed 20 }`
field "icebergs_源码" web.code.inner args `[ usr/icebergs misc/lark/lark.go 74 ]` field "icebergs_源码" web.code.inner args `[ usr/icebergs misc/lark/lark.go 74 ]`