From 79a41bc5adbd3cf8045f0f3d82065a8894aaea72 Mon Sep 17 00:00:00 2001 From: liyp Date: Sun, 20 Oct 2024 16:29:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor(router):=20=E4=BC=98=E5=8C=96=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=AD=98=E5=82=A8=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DRedis=E9=94=AE=E6=A0=BC=E5=BC=8F=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=B9=B6=E7=A7=BB=E9=99=A4=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/router.go | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) 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("权限校验失败") + // 实现触发器功能 + } }