gruik

Fork of GCU-Squad's RSS-to-IRC bridge
git clone https://git.instinctive.eu/gruik.git
Log | Files | Refs | README | LICENSE

commit b00450896733ff825538921421ababfb544d77b1
parent a7d80c4be3d140958c597d0175970099ad0ece5b
Author: Emile 'iMil' Heitor <imil@NetBSD.org>
Date:   Fri, 14 Jul 2023 11:20:06 +0200

fix: replaced ugly timer with rotating list

Diffstat:
Mmain.go | 16+++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/main.go b/main.go @@ -24,6 +24,8 @@ type News struct { Hash string `json:"hash"` } +const maxNews = 100 + var newslist []News func mkHash(s1, s2 string) string { @@ -71,8 +73,6 @@ func newsFetch(client *girc.Client, channel string) { newslist = make([]News, 0) - start := time.Now() - for { if client.IsConnected() && len(client.ChannelList()) != 0 { break @@ -95,13 +95,7 @@ func newsFetch(client *girc.Client, channel string) { client.Cmd.Message(channel, "could not load news list, empty?") } - oneDay := 24 * time.Hour - for { - // reset news list after one day - if time.Since(start) > oneDay { - newslist = make([]News, 0) - } for _, feedURL := range viper.GetStringSlice("feeds.urls") { log.Printf("fetching %s...\n", feedURL) fp := gofeed.NewParser() @@ -140,7 +134,11 @@ func newsFetch(client *girc.Client, channel string) { time.Sleep(viper.GetDuration("irc.delay")) // Mark item as posted - newslist = append(newslist, news) + if len(newslist) < maxNews { + newslist = append(newslist, news) + } else { + newslist = append(newslist[1:], news) + } } } // save news list to disk to avoid repost when restarting