go-bot/utils/router.go

41 lines
1.1 KiB
Go
Raw Normal View History

2024-04-01 09:42:29 +08:00
package utils
import (
"fmt"
"go-bot/workers"
"strings"
)
func Router(data map[string]interface{}) {
// 将map转换为格式化的JSON字符串
2024-04-01 11:37:03 +08:00
// jsonString, err := json.MarshalIndent(data, "", " ")
// if err != nil {
// panic(err)
// }
2024-04-01 09:42:29 +08:00
// 输出格式化后的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)
raw_msg := data["raw_message"].(string)[1:]
2024-04-14 15:18:23 +08:00
2024-04-14 22:08:50 +08:00
parms := strings.Fields(raw_msg)
2024-04-01 09:42:29 +08:00
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])
2024-04-03 22:04:03 +08:00
// fmt.Println("CheckPermission:", worker.CheckPermission())
2024-04-01 09:42:29 +08:00
// 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()
if message == "0" {
message = worker.GetMsg()
2024-04-01 09:42:29 +08:00
worker.SendMsg(message)
}
2024-04-01 09:42:29 +08:00
}