mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-19 14:05:03 +08:00
fix: limitedString
减少内存使用
This commit is contained in:
parent
5429292357
commit
5b0c693aba
13
coolq/api.go
13
coolq/api.go
@ -14,12 +14,14 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
|
"github.com/Mrs4s/MiraiGo/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
@ -1378,10 +1380,15 @@ func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) MSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func limitedString(str string) string {
|
func limitedString(str string) string {
|
||||||
if strings.Count(str, "") <= 10 {
|
if utf8.RuneCountInString(str) <= 10 {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
limited := []rune(str)
|
b := utils.S2B(str)
|
||||||
limited = limited[:10]
|
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) + " ..."
|
return string(limited) + " ..."
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user