From 563d5ff9a618fcf40928d53d69cfdc438f019acb Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Wed, 7 Jul 2021 15:36:03 +0200 Subject: [PATCH] feat: anti-flapping Send notifications only if the state duration is not instant. There are a lot of replies with 0 seconds duration spamming channels. Signed-off-by: Julien Riou --- main.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index cc71c31..0709b2d 100644 --- a/main.go +++ b/main.go @@ -340,16 +340,18 @@ func handleProducts(parser Parser, notifiers []Notifier, filters []Filter, db *g } // send notifications - if createThread { - for _, notifier := range notifiers { - if err := notifier.NotifyWhenAvailable(shop.Name, dbProduct.Name, dbProduct.Price, dbProduct.PriceCurrency, dbProduct.URL); err != nil { - log.Errorf("%s", err) + if duration > 0 { + if createThread { + for _, notifier := range notifiers { + if err := notifier.NotifyWhenAvailable(shop.Name, dbProduct.Name, dbProduct.Price, dbProduct.PriceCurrency, dbProduct.URL); err != nil { + log.Errorf("%s", err) + } } - } - } else if closeThread { - for _, notifier := range notifiers { - if err := notifier.NotifyWhenNotAvailable(dbProduct.URL, duration); err != nil { - log.Errorf("%s", err) + } else if closeThread { + for _, notifier := range notifiers { + if err := notifier.NotifyWhenNotAvailable(dbProduct.URL, duration); err != nil { + log.Errorf("%s", err) + } } } }