From 5b0c693aba387e17c98ba0ecc817baae4eb98b2e Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Sun, 28 Mar 2021 19:06:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20limitedString=20=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E5=86=85=E5=AD=98=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/api.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/coolq/api.go b/coolq/api.go index 30d05b0..a3cefca 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -14,12 +14,14 @@ import ( "strconv" "strings" "time" + "unicode/utf8" "github.com/Mrs4s/go-cqhttp/global" "github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/MiraiGo/message" + "github.com/Mrs4s/MiraiGo/utils" log "github.com/sirupsen/logrus" "github.com/tidwall/gjson" ) @@ -1378,10 +1380,15 @@ func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) MSG { } func limitedString(str string) string { - if strings.Count(str, "") <= 10 { + if utf8.RuneCountInString(str) <= 10 { return str } - limited := []rune(str) - limited = limited[:10] + b := utils.S2B(str) + limited := make([]rune, 0, 10) + for i := 0; i < 10; i++ { + decodeRune, size := utf8.DecodeRune(b) + b = b[size:] + limited = append(limited, decodeRune) + } return string(limited) + " ..." }