From 5cd6417ec9ce906540d03afbaa5f5c5edca3b2c6 Mon Sep 17 00:00:00 2001 From: Hao Guan Date: Wed, 7 Apr 2021 15:07:32 +0800 Subject: [PATCH] fix: Ignore lottery messages. --- dr-feeder.go | 2 +- watcher/weibo.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dr-feeder.go b/dr-feeder.go index 9b55edd..cef0728 100644 --- a/dr-feeder.go +++ b/dr-feeder.go @@ -14,7 +14,7 @@ import ( ) // Version is current `git describe --tags` infomation. -var Version string = "v2.3.0" +var Version string = "v2.3.1" func consume(ch chan common.NotifyPayload, notifiers []notifier.Notifier) { for { diff --git a/watcher/weibo.go b/watcher/weibo.go index c134bcc..5be00aa 100644 --- a/watcher/weibo.go +++ b/watcher/weibo.go @@ -125,7 +125,7 @@ func (watcher *weiboWatcher) update() bool { return ret } -func (watcher weiboWatcher) parseContent() common.NotifyPayload { +func (watcher weiboWatcher) parseContent() (common.NotifyPayload, bool) { weibo := watcher.latestMblog doc, _ := htmlquery.Parse( @@ -143,6 +143,10 @@ func (watcher weiboWatcher) parseContent() common.NotifyPayload { texts += strings.Trim(node.Data, " \n") } + if strings.Contains(texts, "微博官方唯一抽奖工具") && strings.Contains(texts, "结果公正有效") { + return common.NotifyPayload{}, false + } + picURL := weibo.PicURL pageURL := fmt.Sprintf("%s/%s", "https://m.weibo.cn/status", weibo.ID) @@ -162,13 +166,18 @@ func (watcher weiboWatcher) parseContent() common.NotifyPayload { Body: texts, URL: pageURL, PicURL: picURL, - } + }, true } func (watcher *weiboWatcher) Produce(ch chan common.NotifyPayload) { if watcher.update() { log.Printf("New post from \"%s\"...\n", watcher.name) - ch <- watcher.parseContent() + payload, valid := watcher.parseContent() + if valid { + ch <- payload + } else { + log.Println("Lottery message, ignored.") + } } else { log.Printf("Waiting for post \"%s\"...\n", watcher.name) }