From ee354e32501e10d8078fc07f8eced67073a7e36f Mon Sep 17 00:00:00 2001 From: boypt <1033514+boypt@users.noreply.github.com> Date: Tue, 17 Dec 2019 01:05:39 +0800 Subject: [PATCH] fix misuse of sub.EnableTelegraph --- bot/service.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/bot/service.go b/bot/service.go index f86553cb..ecd1807d 100644 --- a/bot/service.go +++ b/bot/service.go @@ -92,26 +92,28 @@ func SendError(c *tb.Chat) { func BroadNews(source *model.Source, subs []model.Subscribe, contents []model.Content) { log.Printf("Source Title: <%s> Subscriber: %d New Contents: %d", source.Title, len(subs), len(contents)) + var buf []byte + wb := bytes.NewBuffer(buf) for _, content := range contents { previewText := trimDescription(content.Description, config.PreviewText) - tpldata := &config.TplData{ - SourceTitle: source.Title, - ContentTitle: content.Title, - RawLink: content.RawLink, - PreviewText: previewText, - TelegraphURL: content.TelegraphUrl, - EnableTelegraph: config.EnableTelegraph, - } - - var buf []byte - wb := bytes.NewBuffer(buf) - if err := config.MessageTpl.Execute(wb, tpldata); err != nil { - log.Println(err) - return - } for _, sub := range subs { + tpldata := &config.TplData{ + SourceTitle: source.Title, + ContentTitle: content.Title, + RawLink: content.RawLink, + PreviewText: previewText, + TelegraphURL: content.TelegraphUrl, + EnableTelegraph: sub.EnableTelegraph == 1 && content.TelegraphUrl != "", + } + + wb.Reset() + if err := config.MessageTpl.Execute(wb, tpldata); err != nil { + log.Println(err) + return + } + u := &tb.User{ ID: int(sub.UserID), }