From ca02f5fcf176232688c3b0d2455026de1e1e1d0e Mon Sep 17 00:00:00 2001 From: liyp Date: Sat, 20 Apr 2024 12:49:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=87=E6=BB=A4=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 测试判断字符串开头 修复字符串开头判断 优化消息开头字符 --- utils/router.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/utils/router.go b/utils/router.go index 4c8b4c0..7a9cf2e 100644 --- a/utils/router.go +++ b/utils/router.go @@ -21,20 +21,26 @@ func Router(data map[string]interface{}) { sender := data["sender"].(map[string]interface{}) role := sender["role"].(string) mid := data["message_id"].(float64) - raw_msg := data["raw_message"].(string)[1:] - parms := strings.Fields(raw_msg) + //包含发送消息的'!' + 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) + 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 == "0" { - message = worker.GetMsg() - worker.SendMsg(message) + // 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 == "0" { + message = worker.GetMsg() + worker.SendMsg(message) + } } }