1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-25 17:18:05 +08:00
2021-10-14 03:20:26 +08:00

61 lines
2.1 KiB
Go

package wework
import (
"crypto/aes"
"crypto/cipher"
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"sort"
"strings"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
)
const BOT = "bot"
func init() {
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
BOT: {Name: "bot", Help: "机器人", Value: kit.Data(
kit.MDB_SHORT, "name", kit.MDB_FIELD, "time,name,token,ekey,hook",
)},
}, Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save() }},
web.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
"/bot/": {Name: "/bot", Help: "机器人", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
msg := m.Cmd(BOT, arg[0])
list := []string{msg.Append("token"), m.Option("nonce"), m.Option("timestamp"), m.Option("echostr")}
sort.Strings(list)
res := sha1.Sum([]byte(strings.Join(list, "")))
m.Debug(hex.EncodeToString(res[:]))
aeskey, err := base64.StdEncoding.DecodeString(msg.Append("ekey"))
m.Assert(err)
en_msg, err := base64.StdEncoding.DecodeString(m.Option("echostr"))
m.Assert(err)
block, err := aes.NewCipher(aeskey)
m.Assert(err)
mode := cipher.NewCBCDecrypter(block, aeskey[:aes.BlockSize])
mode.CryptBlocks(en_msg, en_msg)
}},
BOT: {Name: "bot name chat text:textarea auto create", Help: "机器人", Action: ice.MergeAction(map[string]*ice.Action{
mdb.CREATE: {Name: "create name token ekey hook", Help: "创建"},
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if mdb.HashSelect(m, arg...); len(arg) > 2 {
m.SetAppend()
m.Cmd(web.SPIDE, mdb.CREATE, arg[0], m.Append("hook"))
m.Cmdy(web.SPIDE, arg[0], "", kit.Format(kit.Dict(
"chatid", arg[1], "msgtype", "text", "text.content", arg[2],
)))
} else {
m.PushAction(mdb.REMOVE)
}
}},
}})
}