2024-04-01 09:42:29 +08:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"go-bot/workers"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Router(data map[string]interface{}) {
|
|
|
|
|
|
|
|
// 输出格式化后的JSON
|
2024-04-01 11:37:03 +08:00
|
|
|
// fmt.Println(string(jsonString))
|
2024-04-01 09:42:29 +08:00
|
|
|
// 读取字段值
|
|
|
|
uid := data["user_id"].(float64)
|
|
|
|
gid := data["group_id"].(float64)
|
|
|
|
sender := data["sender"].(map[string]interface{})
|
|
|
|
role := sender["role"].(string)
|
|
|
|
mid := data["message_id"].(float64)
|
2024-04-02 16:37:26 +08:00
|
|
|
|
2024-04-20 12:49:16 +08:00
|
|
|
//包含发送消息的'!'
|
|
|
|
raw_msg := data["raw_message"].(string)
|
|
|
|
// fmt.Println("raw_msg:", string(raw_msg[0]))
|
|
|
|
if len(raw_msg) > 1 && raw_msg[0] == '!' {
|
|
|
|
// 去除'!'
|
|
|
|
raw_msg = raw_msg[1:]
|
|
|
|
parms := strings.Fields(raw_msg)
|
|
|
|
|
|
|
|
worker := workers.NewWorker(parms, fmt.Sprintf("%d", int(uid)), fmt.Sprintf("%d", int(gid)), role, fmt.Sprintf("%d", int(mid)), raw_msg)
|
|
|
|
|
|
|
|
// fmt.Println("router:", parms[0])
|
|
|
|
// fmt.Println("CheckPermission:", worker.CheckPermission())
|
|
|
|
// ans := NewStdAns(parms[0], fmt.Sprintf("%d", int(uid)), fmt.Sprintf("%d", int(gid)), role, fmt.Sprintf("%d", int(mid)), raw_msg)
|
|
|
|
message := worker.CheckPermission()
|
2024-07-01 10:32:56 +08:00
|
|
|
if message == "ok" {
|
2024-07-02 13:21:29 +08:00
|
|
|
|
2024-04-20 12:49:16 +08:00
|
|
|
message = worker.GetMsg()
|
|
|
|
worker.SendMsg(message)
|
|
|
|
|
2024-07-02 13:21:29 +08:00
|
|
|
} else {
|
|
|
|
println("权限校验失败")
|
2024-04-20 12:49:16 +08:00
|
|
|
}
|
2024-04-02 20:29:25 +08:00
|
|
|
}
|
2024-04-01 09:42:29 +08:00
|
|
|
|
|
|
|
}
|