commit 95c74047a741347b822c316b6e086ac5eea7c8e4
parent 6c0e926b47dcf64d3a750923e422ee71a496e3b4
Author: Natasha Kerensikova <natacha@instinctive.eu>
Date: Sun, 18 Jan 2026 11:46:57 +0100
feat: secondary bot watches xposted hashes
Diffstat:
| M | main.go | | | 28 | +++++++++++++++++++++++++--- |
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/main.go b/main.go
@@ -27,6 +27,7 @@ type News struct {
var newsList []News
var pendingList []News
+var xpostHashList []string
// Send an IRC ircMessage, unless in dry-run mode
func ircMessage(client *girc.Client, target, message string) {
@@ -62,6 +63,23 @@ func saveNews(news News) {
}
}
+func xpostSeen(hash string) bool {
+ for _, h := range xpostHashList {
+ if h == hash {
+ return true
+ }
+ }
+ return false
+}
+
+func saveXpost(hash string) {
+ if len(xpostHashList) < viper.GetInt("feeds.ringsize") {
+ xpostHashList = append(xpostHashList, hash)
+ } else {
+ xpostHashList = append(xpostHashList[1:], hash)
+ }
+}
+
// Retrieve a news by its hash
func getNewsByHash(hash string) News {
hash = strings.ReplaceAll(hash, "#", "")
@@ -326,9 +344,13 @@ func main() {
for _, suffix, found := strings.Cut(e.Last(), "#"); found && len(suffix) >= 8; _, suffix, found = strings.Cut(suffix, "#") {
if strings.Trim(suffix[:8], "0123456789abcdef") == "" {
log.Printf("Received hash %s from %s", suffix[:8], e.Source.Name)
- news := News{Hash: suffix[:8]}
- if !newsExists(news) {
- saveNews(news)
+ if e.Params[0] == channel {
+ news := News{Hash: suffix[:8]}
+ if !newsExists(news) {
+ saveNews(news)
+ }
+ } else {
+ saveXpost(suffix[:8])
}
}
}