gruik

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

commit a9366d7cc0e190ff9bfc97f34570ce0a16a1c7ec
parent fed197cd524705b4a84ea22bf9578540d2da4856
Author: Sébastien Marie <semarie@online.fr>
Date:   Tue, 18 Jul 2023 09:09:47 +0000

reorder client.Handlers to separate unpriv and priv commands

Diffstat:
Mmain.go | 82+++++++++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 45 insertions(+), 37 deletions(-)

diff --git a/main.go b/main.go @@ -268,9 +268,7 @@ func main() { if len(e.Params) > 0 && e.Params[0] != channel { dest = e.Source.Name } - if isOp(e.Source.Name) && strings.HasPrefix(e.Last(), "!die") { - c.Close() - } + if strings.HasPrefix(e.Last(), "!lsfeeds") { for i, f := range viper.GetStringSlice("feeds.urls") { n := strconv.Itoa(i + 1) @@ -278,40 +276,6 @@ func main() { time.Sleep(viper.GetDuration("irc.delay")) } } - if isOp(e.Source.Name) && strings.HasPrefix(e.Last(), "!addfeed") { - s := getParam(e.Last()) - if s == "" { - return - } - ss := append(viper.GetStringSlice("feeds.urls"), s) - viper.Set("feeds.urls", ss) - c.Cmd.ReplyTo(e, girc.Fmt("feed {b}{green}added{c}{b}")) - if err := viper.WriteConfig(); err != nil { - c.Cmd.ReplyTo(e, girc.Fmt("adding feed {b}{red}failed{c}{b}")) - } - } - if isOp(e.Source.Name) && strings.HasPrefix(e.Last(), "!rmfeed") { - s := getParam(e.Last()) - if s == "" { - return - } - ss := viper.GetStringSlice("feeds.urls") - i, err := strconv.Atoi(s) - if err != nil { - c.Cmd.ReplyTo(e, "index conversion failed") - return - } - if i < 1 || i > len(ss) { - c.Cmd.ReplyTo(e, "bad index number") - return - } - ss = append(ss[:i-1], ss[i:]...) - viper.Set("feeds.urls", ss) - c.Cmd.ReplyTo(e, girc.Fmt("feed {b}{green}removed{c}{b}")) - if err := viper.WriteConfig(); err != nil { - c.Cmd.ReplyTo(e, girc.Fmt("removing feed {b}{red}failed{c}{b}")) - } - } if strings.HasPrefix(e.Last(), "!xpost") && e.Params[0] == channel { s := getParam(e.Last()) if s == "" { @@ -358,6 +322,50 @@ func main() { time.Sleep(viper.GetDuration("irc.delay")) } } + + + // All commands below requires OP + if ! isOp(e.Source.Name) { + return + } + + if strings.HasPrefix(e.Last(), "!die") { + c.Close() + } + if strings.HasPrefix(e.Last(), "!addfeed") { + s := getParam(e.Last()) + if s == "" { + return + } + ss := append(viper.GetStringSlice("feeds.urls"), s) + viper.Set("feeds.urls", ss) + c.Cmd.ReplyTo(e, girc.Fmt("feed {b}{green}added{c}{b}")) + if err := viper.WriteConfig(); err != nil { + c.Cmd.ReplyTo(e, girc.Fmt("adding feed {b}{red}failed{c}{b}")) + } + } + if strings.HasPrefix(e.Last(), "!rmfeed") { + s := getParam(e.Last()) + if s == "" { + return + } + ss := viper.GetStringSlice("feeds.urls") + i, err := strconv.Atoi(s) + if err != nil { + c.Cmd.ReplyTo(e, "index conversion failed") + return + } + if i < 1 || i > len(ss) { + c.Cmd.ReplyTo(e, "bad index number") + return + } + ss = append(ss[:i-1], ss[i:]...) + viper.Set("feeds.urls", ss) + c.Cmd.ReplyTo(e, girc.Fmt("feed {b}{green}removed{c}{b}")) + if err := viper.WriteConfig(); err != nil { + c.Cmd.ReplyTo(e, girc.Fmt("removing feed {b}{red}failed{c}{b}")) + } + } }) go newsFetch(client, channel)