gruik

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

commit 8443b02718fbcc5feb963fc78f6e94ee7a487f84
parent 95c74047a741347b822c316b6e086ac5eea7c8e4
Author: Natasha Kerensikova <natacha@instinctive.eu>
Date:   Sun, 18 Jan 2026 11:50:51 +0100

feat: secondary bot delayed xposting

Diffstat:
Mmain.go | 25+++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go @@ -38,6 +38,21 @@ func ircMessage(client *girc.Client, target, message string) { } } +// Cross-post news to IRC channels +func xpostMessage(client *girc.Client, message string) { + for _, xchan := range viper.GetStringSlice("irc.xchannels") { + ircMessage(client, xchan, message) + time.Sleep(viper.GetDuration("irc.delay")) + } +} + +func xpostDelayedMessage(client *girc.Client, message, hash string) { + time.Sleep(viper.GetDuration("irc.xpostdelay")) + if !xpostSeen(hash) { + xpostMessage(client, message) + } +} + // Create a hash out of link func mkHash(s string) string { h := sha256.Sum256([]byte(s)) @@ -237,6 +252,7 @@ func confDefault() { "irc.secondary": false, "irc.port": 6667, "irc.delay": "2s", + "irc.xpostdelay": "4s", "irc.startfreq": "10m", "irc.colors.origin": "pink", "irc.colors.title": "bold", @@ -363,7 +379,7 @@ func main() { time.Sleep(viper.GetDuration("irc.delay")) } } - if strings.HasPrefix(e.Last(), "!xpost") && e.Params[0] == channel && !viper.GetBool("irc.secondary") { + if strings.HasPrefix(e.Last(), "!xpost") && e.Params[0] == channel { requestedHash := getParam(e.Last()) if requestedHash == "" { return @@ -371,9 +387,10 @@ func main() { if news := getNewsByHash(requestedHash); news.Hash != "" { post := fmt.Sprintf(" {r}(from %s on %s)", e.Source.Name, channel) message := fmtNews(news) + girc.Fmt(post) - for _, xchan := range viper.GetStringSlice("irc.xchannels") { - ircMessage(c, xchan, message) - time.Sleep(viper.GetDuration("irc.delay")) + if !viper.GetBool("irc.secondary") { + xpostMessage(c, message) + } else { + go xpostDelayedMessage(c, message, news.Hash) } } }