diff --git a/utils/router.go b/utils/router.go index b3e439b..65ce222 100644 --- a/utils/router.go +++ b/utils/router.go @@ -30,6 +30,8 @@ func Router(data map[string]interface{}) { sender := data["sender"].(map[string]interface{}) role := sender["role"].(string) mid := data["message_id"].(float64) + + // 将消息存入redis redisClient := tools.GetRedisClient() if redisClient != nil { var group_message GroupMessage @@ -47,9 +49,9 @@ func Router(data map[string]interface{}) { return } key := fmt.Sprintf("group_message:%f:%f", gid, uid) - exists, err := tools.CheckKeyExists(fmt.Sprintf("group_message:%f:%f", gid, uid)) + exists, err := tools.CheckKeyExists(fmt.Sprintf("group_message:%d:%d", int64(gid), int64(uid))) if err != nil || !exists { - redisClient.RPush(context.Background(), key, jsonString, 7*24*time.Hour) + redisClient.RPush(context.Background(), key, jsonString, 0) // tools.SetValue(key, string(jsonString), 10*time.Second) } else { @@ -77,24 +79,29 @@ func Router(data map[string]interface{}) { } // fmt.Println("raw_msg:", string(raw_msg)) - if len(raw_msg) > 1 && string(raw_msg[0]) == prefix { - // 去除'!' - raw_msg = raw_msg[1:] - parms := strings.Fields(raw_msg) + if len(raw_msg) > 1 { + if string(raw_msg[0]) == prefix { + // 去除'!' + 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) + 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() - if message == "ok" { + // 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() + if message == "ok" { - message = worker.GetMsg() - worker.SendMsg(message) + message = worker.GetMsg() + worker.SendMsg(message) + } else { + println("权限校验失败") + } } else { - println("权限校验失败") + // 实现触发器功能 + } }