diff --git a/coolq/bot.go b/coolq/bot.go index 6980c2efc..2dfb916be 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -294,19 +294,20 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupId int64, m *message.Sen if msg != nil { id = bot.InsertPrivateMessage(msg) } - } else if code, ok := bot.tempMsgCache.Load(target); ok || groupId != 0 { // 临时会话 - if bot.Client.FindGroup(groupId) == nil { - log.Errorf("错误: 找不到群(%v)", groupId) + } else if code, ok := bot.tempMsgCache.Load(target); ok || groupID != 0 { // 临时会话 + switch { + case groupID != 0 && bot.Client.FindGroup(groupID) == nil: + log.Errorf("错误: 找不到群(%v)", groupID) id = -1 - } else if groupId != 0 && !bot.Client.FindGroup(groupId).AdministratorOrOwner() { - log.Errorf("错误: 机器人在群(%v) 为非管理员或群主, 无法主动发起临时会话", groupId) + case groupID != 0 && !bot.Client.FindGroup(groupID).AdministratorOrOwner(): + log.Errorf("错误: 机器人在群(%v) 为非管理员或群主, 无法主动发起临时会话", groupID) id = -1 - } else if groupId != 0 && bot.Client.FindGroup(groupId).FindMember(target) == nil { - log.Errorf("错误: 群员(%v) 不在 群(%v), 无法发起临时会话", target, groupId) + case groupID != 0 && bot.Client.FindGroup(groupID).FindMember(target) == nil: + log.Errorf("错误: 群员(%v) 不在 群(%v), 无法发起临时会话", target, groupID) id = -1 - } else { - if code != nil { - groupId = code.(int64) + default: + if code != nil && groupID == 0 { + groupID = code.(int64) } msg := bot.Client.SendTempMessage(groupId, target, m) if msg != nil {