gruik

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

commit cb60e9a02b9fefb5c02d5d795e6d1cc139250bfd
parent 3e2e7cc2aaf59272f3889c594e4b3d2629d05943
Author: Emile 'iMil' Heitor <imil@NetBSD.org>
Date:   Fri, 14 Jul 2023 12:23:19 +0200

fix: load news without waiting

Diffstat:
Mmain.go | 22+++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/main.go b/main.go @@ -84,15 +84,6 @@ func newsFetch(client *girc.Client, channel string) { newsList = make([]News, 0) - for { - if client.IsConnected() && len(client.ChannelList()) != 0 { - break - } - log.Printf("%v, not connected, waiting...\n", client.ChannelList()) - - time.Sleep(viper.GetDuration("feeds.frequency")) - } - feedFile := channel + "-feed.json" // load saved news f, err := os.OpenFile(feedFile, os.O_CREATE|os.O_RDWR, 0o644) @@ -100,10 +91,18 @@ func newsFetch(client *girc.Client, channel string) { log.Fatalf("can't open %s: %v", feedFile, err) } defer f.Close() - // read news from disk decoder := json.NewDecoder(f) if err := decoder.Decode(&newsList); err != nil { - client.Cmd.Message(channel, "could not load news list, empty?") + log.Println("could not load news list, empty?") + } + + for { + if client.IsConnected() && len(client.ChannelList()) != 0 { + break + } + log.Printf("%v, not connected, waiting...\n", client.ChannelList()) + + time.Sleep(viper.GetDuration("feeds.frequency")) } for { @@ -350,6 +349,7 @@ func main() { } for i := 0; i < n; i++ { c.Cmd.Message(dest, girc.Fmt(fmtNews(showNews[i]))) + time.Sleep(viper.GetDuration("irc.delay")) } } })