Skip to content

Commit f67f1d4

Browse files
committed
fix nil
1 parent 652890c commit f67f1d4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

service/bot/api_handler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ func HandleSendPrivateMsg(cli *client.QQClient, req *onebot.SendPrivateMsgReq) *
136136
}
137137

138138
func HandleSendGroupMsg(cli *client.QQClient, req *onebot.SendGroupMsgReq) *onebot.SendGroupMsgResp {
139+
if cli.FindGroup(req.GroupId) == nil {
140+
log.Warnf("发送消息失败,群聊 %d 不存在", req.GroupId)
141+
return nil
142+
}
139143
miraiMsg := ProtoMsgToMiraiMsg(cli, req.Message, req.AutoEscape)
140144
sendingMessage := &message.SendingMessage{Elements: miraiMsg}
141145
log.Infof("Bot(%d) Group(%d) <- %s", cli.Uin, req.GroupId, MiraiMsgToRawMsg(miraiMsg))
@@ -174,6 +178,10 @@ func HandleSendMsg(cli *client.QQClient, req *onebot.SendMsgReq) *onebot.SendMsg
174178
}
175179

176180
if req.GroupId != 0 { // 群
181+
if cli.FindGroup(req.GroupId) == nil {
182+
log.Warnf("发送消息失败,群聊 %d 不存在", req.GroupId)
183+
return nil
184+
}
177185
preProcessGroupSendingMessage(cli, req.GroupId, sendingMessage)
178186
ret := cli.SendGroupMessage(req.GroupId, sendingMessage, config.Fragment)
179187
if ret == nil || ret.Id == -1 {

0 commit comments

Comments
 (0)