diff --git a/misc/lark/app.go b/misc/lark/app.go index fc8fe481..88be2fff 100644 --- a/misc/lark/app.go +++ b/misc/lark/app.go @@ -5,6 +5,7 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) @@ -20,17 +21,17 @@ const APP = "app" func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ - APP: {Name: APP, Help: "服务配置", Value: kit.Data( - kit.MDB_SHORT, APPID, kit.MDB_FIELD, "time,appid,appmm,duty,token,expire", - LARK, "https://open.feishu.cn/", + APP: {Name: APP, Help: "应用", Value: kit.Data( + kit.MDB_SHORT, APPID, kit.MDB_FIELD, "time,appid,duty,token,expire", + tcp.SERVER, "https://open.feishu.cn/", )}, }, Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmd(web.SPIDE, mdb.CREATE, LARK, m.Conf(APP, kit.Keym(LARK))) - }}, APP: {Name: "app appid auto token login", Help: "应用", Action: ice.MergeAction(map[string]*ice.Action{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + m.Cmd(web.SPIDE, mdb.CREATE, LARK, m.Config(tcp.SERVER)) + }}, LOGIN: {Name: "login appid appmm duty", Help: "登录", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(mdb.INSERT, m.Prefix(APP), "", mdb.HASH, arg) + m.Cmdy(mdb.INSERT, m.PrefixKey(), "", mdb.HASH, arg) }}, TOKEN: {Name: "token appid", Help: "令牌", Hand: func(m *ice.Message, arg ...string) { msg := m.Cmd(APP, m.Option(APPID)) @@ -38,7 +39,7 @@ func init() { res := m.Cmd(web.SPIDE, LARK, "/open-apis/auth/v3/tenant_access_token/internal/", APP_ID, msg.Append(APPID), "app_secret", msg.Append(APPMM)) - m.Cmd(mdb.MODIFY, m.Prefix(APP), "", mdb.HASH, m.OptionSimple(APPID), + m.Cmd(mdb.MODIFY, m.PrefixKey(), "", mdb.HASH, m.OptionSimple(APPID), TOKEN, res.Append("tenant_access_token"), EXPIRE, now+kit.Int64(res.Append(EXPIRE))) m.Echo(res.Append("tenant_access_token")) return @@ -48,6 +49,5 @@ func init() { }, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { mdb.HashSelect(m, arg...) }}, - }, - }) + }}) } diff --git a/misc/lark/duty.go b/misc/lark/duty.go index e8cc9657..e9301a51 100644 --- a/misc/lark/duty.go +++ b/misc/lark/duty.go @@ -9,8 +9,8 @@ const DUTY = "duty" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ DUTY: {Name: "duty [title] text auto", Help: "通告", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { - duty := m.Cmd(APP, m.Option(APP_ID)).Append(DUTY) - m.Cmdy(SEND, arg[0], duty, arg[1:]) + msg := m.Cmd(APP, m.Option(APP_ID)) + m.Cmdy(SEND, msg.Append(APPID), msg.Append(DUTY), arg) }}, }}) } diff --git a/misc/lark/lark.shy b/misc/lark/lark.shy index 8f4877ca..20830ade 100644 --- a/misc/lark/lark.shy +++ b/misc/lark/lark.shy @@ -1,23 +1,22 @@ title "飞书机器人" -refer "官网" ` -官网 https://shylinux.com/chat/lark/sso +refer ` 官网 https://www.feishu.cn/ 文档 https://open.feishu.cn/document/uQjL04CN/ucDOz4yN4MjL3gzM -源码 https://shylinux.com/x/icebergs/blob/master/misc/lark/lark.go 后台管理 https://www.feishu.cn/admin 应用管理 https://open.feishu.cn/app ` qrcode `https://applink.feishu.cn/client/bot/open?appId=cli_9d3b9d146a7cd103` chapter "应用" -field "app" web.chat.lark.app -field "group" web.chat.lark.group -field "company" web.chat.lark.company -field "duty" web.chat.lark.duty +field "应用" web.chat.lark.app +field "群组" web.chat.lark.group +field "组织" web.chat.lark.company +field "值班" web.chat.lark.duty chapter "权限" -field sess aaa.sess -field user aaa.user +field "共享" web.share +field "会话" aaa.sess +field "用户" aaa.user chapter "项目" field "icebergs" web.code.git.trend args `icebergs` diff --git a/misc/lark/send.go b/misc/lark/send.go index 71162703..4a46ae09 100644 --- a/misc/lark/send.go +++ b/misc/lark/send.go @@ -60,7 +60,7 @@ func init() { if _send_text(m, form, arg...) { msg := _lark_post(m, appid, "/open-apis/message/v4/send/", web.SPIDE_DATA, kit.Format(form)) - m.Push("time", m.Time()) + m.Push(kit.MDB_TIME, m.Time()) m.Push("message_id", msg.Append("data.message_id")) } }}, diff --git a/misc/lark/talk.go b/misc/lark/talk.go index d96d25a0..20bf70b2 100644 --- a/misc/lark/talk.go +++ b/misc/lark/talk.go @@ -5,6 +5,7 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/aaa" + "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) @@ -24,7 +25,13 @@ func init() { } // 执行命令 - if m.Cmdy(cmds); len(m.Resultv()) > 0 { + if m.Cmdy(cmds); m.Result() != "" && m.Result(1) != ice.ErrNotFound { + m.Cmd(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Result()) + return + } + if m.Length() == 0 { + m.Set(ice.MSG_RESULT) + m.Cmdy(cli.SYSTEM, cmds) m.Cmd(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Result()) return }