diff --git a/coolq/api.go b/coolq/api.go index 83a5fea..b8c8955 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -4,10 +4,6 @@ import ( "crypto/md5" "encoding/hex" "fmt" - "github.com/Mrs4s/MiraiGo/binary" - "github.com/Mrs4s/MiraiGo/client" - "github.com/Mrs4s/MiraiGo/message" - "github.com/tidwall/gjson" "io/ioutil" "math" "os" @@ -17,9 +13,16 @@ import ( "strconv" "strings" "time" + "unicode/utf8" + + "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" "github.com/Mrs4s/go-cqhttp/global" - log "github.com/sirupsen/logrus" ) // Version go-cqhttp的版本信息,在编译时使用ldflags进行覆盖 @@ -1354,10 +1357,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) + " ..." }