Compare commits

...

3 Commits

Author SHA1 Message Date
a08966d454 Merge pull request 'hotfix' (#78) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m34s
Reviewed-on: #78
2024-07-12 10:04:23 +08:00
24ddb1befe Merge remote-tracking branch 'origin/hotfix' into hotfix 2024-07-12 10:03:51 +08:00
bb58b5090b 🎨 优化被移除群聊之后的处理逻辑 2024-07-12 10:03:45 +08:00
2 changed files with 33 additions and 0 deletions

View File

@ -34,6 +34,9 @@ func NotifyInvitationJoinGroup(m *plugin.MessageContext) {
func NotifyRemoveFromChatroom(m *plugin.MessageContext) { func NotifyRemoveFromChatroom(m *plugin.MessageContext) {
// 如果是被移出群聊,推送到配置的用户 // 如果是被移出群聊,推送到配置的用户
if strings.HasPrefix(m.Content, "你被\"") && strings.HasSuffix(m.Content, "\"移出群聊") { if strings.HasPrefix(m.Content, "你被\"") && strings.HasSuffix(m.Content, "\"移出群聊") {
// 调用一下退出群聊接口,防止被移出后还能从好友列表接口拉到相关信息
utils.QuitChatroom(m.FromUser, 0)
// 取出群名称 // 取出群名称
groupInfo, err := service.GetFriendInfoById(m.FromUser) groupInfo, err := service.GetFriendInfoById(m.FromUser)
if err != nil { if err != nil {

View File

@ -158,3 +158,33 @@ func DeleteGroupMember(chatRoomId, memberIds string, retryCount int, isSure bool
DeleteGroupMember(chatRoomId, memberIds, 5, true) DeleteGroupMember(chatRoomId, memberIds, 5, true)
} }
} }
// QuitChatroom
// @description: 退出群聊
// @param chatRoomId string 群Id
// @param retryCount int 重试次数
func QuitChatroom(chatRoomId string, retryCount int) {
if retryCount > 5 {
log.Printf("重试五次失败,停止发送")
return
}
// 组装参数
param := map[string]any{
"chatRoomId": chatRoomId, // 群Id
}
pbs, _ := json.Marshal(param)
res := resty.New()
resp, err := res.R().
SetHeader("Content-Type", "application/json;chartset=utf-8").
SetBody(string(pbs)).
Post(config.Conf.Wechat.GetURL("/api/quitChatRoom"))
if err != nil {
log.Printf("退群失败: %s", err.Error())
// 休眠五秒后重新发送
time.Sleep(5 * time.Second)
QuitChatroom(chatRoomId, retryCount+1)
}
log.Printf("退群结果: %s", resp.String())
}