Skip to content

Commit

Permalink
fix: Ignore lottery messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
hguandl committed Apr 7, 2021
1 parent 4e0d184 commit 5cd6417
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dr-feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 12 additions & 3 deletions watcher/weibo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)

Expand All @@ -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)
}
Expand Down

0 comments on commit 5cd6417

Please sign in to comment.