From 3e6fc41298f55363fbbf8a410acebd7d57d7b409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E5=90=83=E7=82=B9=E8=8B=B9=E6=9E=9C?= <73388495+eatmoreapple@users.noreply.github.com> Date: Sun, 5 Feb 2023 11:23:05 +0800 Subject: [PATCH] =?UTF-8?q?[fix]:=20=E4=BF=AE=E6=94=B9=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=80=BB=E8=BE=91=20(#236)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.go | 8 ++++++-- sync_check.go | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bot.go b/bot.go index 3c974ec..f8e98fc 100644 --- a/bot.go +++ b/bot.go @@ -223,8 +223,8 @@ func (b *Bot) syncCheck() error { if !resp.Success() { return resp.Err() } - // 如果Selector不为0,则获取消息 - if !resp.NorMal() { + switch resp.Selector { + case SelectorNewMsg: messages, err := b.syncMessage() if err != nil { return err @@ -237,8 +237,12 @@ func (b *Bot) syncCheck() error { // 默认同步调用 // 如果异步调用则需自行处理 // 如配合 openwechat.MessageMatchDispatcher 使用 + // NOTE: 请确保 MessageHandler 不会阻塞,否则会导致收不到后续的消息 b.MessageHandler(message) } + case SelectorModContact: + case SelectorAddOrDelContact: + case SelectorModChatRoom: } } return err diff --git a/sync_check.go b/sync_check.go index 3dd069b..6f70da3 100644 --- a/sync_check.go +++ b/sync_check.go @@ -25,7 +25,11 @@ func (s SyncCheckResponse) Success() bool { } func (s SyncCheckResponse) NorMal() bool { - return s.Success() && s.Selector == "0" + return s.Success() && s.Selector == SelectorNormal +} + +func (s SyncCheckResponse) HasNewMessage() bool { + return s.Success() && s.Selector == SelectorNewMsg } func (s SyncCheckResponse) Err() error {