From a4331405d9302833cc4e1d2ea2d71dc582437c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 28 Jul 2023 15:44:23 +0800 Subject: [PATCH] fix: nil mark_as_read --- bot.go | 2 +- driver/wsclient.go | 11 ++++++----- driver/wsserver.go | 11 ++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/bot.go b/bot.go index 8d87215..8829651 100644 --- a/bot.go +++ b/bot.go @@ -228,7 +228,7 @@ func processEventAsync(response []byte, caller APICaller, maxwait time.Duration) // match 匹配规则,处理事件 func match(ctx *Ctx, matchers []*Matcher, maxwait time.Duration) { - if BotConfig.MarkMessage { + if BotConfig.MarkMessage && ctx.Event.MessageID != nil { ctx.MarkThisMessageAsRead() } gorule := func(rule Rule) <-chan bool { diff --git a/driver/wsclient.go b/driver/wsclient.go index eaa3f02..eb2e604 100644 --- a/driver/wsclient.go +++ b/driver/wsclient.go @@ -123,12 +123,13 @@ func (ws *WSClient) Listen(handler func([]byte, zero.APICaller)) { } close(c) // channel only use once } - } else { - if rsp.Get("meta_event_type").Str != "heartbeat" { // 忽略心跳事件 - log.Debug("[ws] 接收到事件: ", helper.BytesToString(payload)) - } - handler(payload, ws) + return + } + if rsp.Get("meta_event_type").Str != "heartbeat" { // 忽略心跳事件 + log.Debug("[ws] 接收到事件: ", helper.BytesToString(payload)) + return } + handler(payload, ws) } } diff --git a/driver/wsserver.go b/driver/wsserver.go index f581107..9be687e 100644 --- a/driver/wsserver.go +++ b/driver/wsserver.go @@ -194,12 +194,13 @@ func (wssc *WSSCaller) listen(handler func([]byte, zero.APICaller)) { } close(c) // channel only use once } - } else { - if rsp.Get("meta_event_type").Str != "heartbeat" { // 忽略心跳事件 - log.Debug("[wss] 接收到事件: ", helper.BytesToString(payload)) - } - handler(payload, wssc) + return + } + if rsp.Get("meta_event_type").Str != "heartbeat" { // 忽略心跳事件 + log.Debug("[wss] 接收到事件: ", helper.BytesToString(payload)) + return } + handler(payload, wssc) } }