gruik

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

commit 55cbe11683a5893d8f49947b6df1a598d90570bf
parent d7b8f6f0aab55828704fd49c39310d0948627f55
Author: Sébastien Marie <semarie@online.fr>
Date:   Tue, 18 Jul 2023 09:36:06 +0000

!latest: initialize showNews/numNews a bit later

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

diff --git a/main.go b/main.go @@ -292,14 +292,13 @@ func main() { } } if strings.HasPrefix(e.Last(), "!latest") && e.Params[0] != channel { - numNews := len(newsList) - args := strings.SplitN(e.Last(), " ", 3) if len(args) < 2 { c.Cmd.Message(dest, "usage: !latest <number> [origin]") time.Sleep(viper.GetDuration("irc.delay")) return } + // n == number of news to show n, err := strconv.Atoi(args[1]) if err != nil || n <= 0 { @@ -307,18 +306,24 @@ func main() { time.Sleep(viper.GetDuration("irc.delay")) return } + + // default to all news showNews := newsList + numNews := len(showNews) + // there was a second parameter, specific origin if len(args) > 2 { showNews = getNewsByOrigin(args[2]) numNews = len(showNews) } + // check if some news are available if numNews < 1 { c.Cmd.Message(dest, "no news available") time.Sleep(viper.GetDuration("irc.delay")) return } + // user gave a greater number that we have news if n > numNews { n = numNews