gruik

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

commit 39c87f159c0ba63661a3775239505f0d563cd8d3
parent c5964d0d5f2fbb9e3709930a6e6198c77829c77d
Author: Emile 'iMil' Heitor <imil@NetBSD.org>
Date:   Fri, 14 Jul 2023 17:02:08 +0200

fix: ctx makes girc crash, wrong index for !latest

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

diff --git a/main.go b/main.go @@ -1,7 +1,6 @@ package main import ( - "context" "crypto/sha256" "encoding/hex" "encoding/json" @@ -114,10 +113,8 @@ func newsFetch(client *girc.Client, channel string) { for _, feedURL := range viper.GetStringSlice("feeds.urls") { log.Printf("fetching %s...\n", feedURL) // don't wait more than 20 seconds for feed to reply - feedctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) - defer cancel() fp := gofeed.NewParser() - feed, err := fp.ParseURLWithContext(feedURL, feedctx) + feed, err := fp.ParseURL(feedURL) if err != nil { log.Printf("Failed to fetch feed '%s': %s", feedURL, err) continue @@ -343,21 +340,26 @@ func main() { c.Cmd.Message(dest, "usage: !latest <number> [origin]") return } + // n == number of news to show n, err := strconv.Atoi(p[1]) if err != nil { c.Cmd.Message(dest, "conversion error") return } showNews := newsList + // there was a second parameter, specific origin if len(p) > 2 { showNews = getNewsByOrigin(p[2]) numNews = len(showNews) } + // user gave a greater number that we have news if n > numNews { n = numNews } + numNews-- for i := 0; i < n; i++ { - c.Cmd.Message(dest, girc.Fmt(fmtNews(showNews[i]))) + fmt.Println(i) + c.Cmd.Message(dest, girc.Fmt(fmtNews(showNews[numNews-i]))) time.Sleep(viper.GetDuration("irc.delay")) } }