From 8532c4ecbecebc16b7b7aded389bc8e7265f7c62 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 24 Jan 2021 15:04:09 +0800 Subject: [PATCH] update MiraiGo. --- coolq/api.go | 20 ++++++++++++++------ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/coolq/api.go b/coolq/api.go index 5fdbd7432..b59e538e1 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -4,6 +4,7 @@ import ( "crypto/md5" "encoding/hex" "io/ioutil" + "math" "os" "path" "path/filepath" @@ -851,7 +852,14 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupId int64, seq int64) MSG { if g := bot.Client.FindGroup(groupId); g == nil { return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } - msg, err := bot.Client.GetGroupMessages(groupId, seq-19, seq) + if seq == 0 { + g, err := bot.Client.GetGroupInfo(groupId) + if err != nil { + return Failed(100, "GROUP_INFO_API_ERROR", err.Error()) + } + seq = g.LastMsgSeq + } + msg, err := bot.Client.GetGroupMessages(groupId, int64(math.Max(float64(seq-19), 1)), seq) if err != nil { log.Warnf("获取群历史消息失败: %v", err) return Failed(100, "MESSAGES_API_ERROR", err.Error()) @@ -1011,11 +1019,11 @@ func Failed(code int, msg ...string) MSG { func convertGroupMemberInfo(groupId int64, m *client.GroupMemberInfo) MSG { return MSG{ - "group_id": groupId, - "user_id": m.Uin, - "nickname": m.Nickname, - "card": m.CardName, - "sex": func() string { + "group_id": groupId, + "user_id": m.Uin, + "nickname": m.Nickname, + "card": m.CardName, + "sex": func() string { if m.Gender == 1 { return "female" } else if m.Gender == 0 { diff --git a/go.mod b/go.mod index 760ad9128..36da04512 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.15 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20210124063508-a401ed3ef104 + github.com/Mrs4s/MiraiGo v0.0.0-20210124065645-9549a32d954a github.com/dustin/go-humanize v1.0.0 github.com/gin-contrib/pprof v1.3.0 github.com/gin-gonic/gin v1.6.3 diff --git a/go.sum b/go.sum index 6f50907ef..29bc88168 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Mrs4s/MiraiGo v0.0.0-20210124063508-a401ed3ef104 h1:dIKRhxzCrt/jdWRFdJupIU3BM94IYoicgqRzjN+2Bw4= -github.com/Mrs4s/MiraiGo v0.0.0-20210124063508-a401ed3ef104/go.mod h1:9V7DdSwpEfCKQNvLZhRnFJFkelTU0tPLfwR5l6UFF1Y= +github.com/Mrs4s/MiraiGo v0.0.0-20210124065645-9549a32d954a h1:ov5QCDpZpsr+geKLVON7E63UqrpNF0oTiKuZwbKwEmo= +github.com/Mrs4s/MiraiGo v0.0.0-20210124065645-9549a32d954a/go.mod h1:9V7DdSwpEfCKQNvLZhRnFJFkelTU0tPLfwR5l6UFF1Y= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=