diff --git a/go.mod b/go.mod index b1ded81..c8ec2d9 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module git.ekzyis.com/ekzyis/unpaywall go 1.21.0 require ( - github.com/ekzyis/snappy v0.5.2 + github.com/ekzyis/snappy v0.5.3 github.com/mattn/go-sqlite3 v1.14.17 ) diff --git a/go.sum b/go.sum index 0e7e9fe..018734e 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -github.com/ekzyis/snappy v0.5.2 h1:3dZyj3Kz7fV3OStllq/koL6d5qNfBRK+4UB2L3RNmiQ= -github.com/ekzyis/snappy v0.5.2/go.mod h1:BxJwdGlCwUw0Q5pQzBr59weAIS6pkVdivBBaZkkWTSo= +github.com/ekzyis/snappy v0.5.3 h1:Pq8b2s4WPz5gnHgCoZR2LVqArEVqWeVCyHSVZCawat4= +github.com/ekzyis/snappy v0.5.3/go.mod h1:BxJwdGlCwUw0Q5pQzBr59weAIS6pkVdivBBaZkkWTSo= github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= diff --git a/main.go b/main.go index c0def91..25c4759 100644 --- a/main.go +++ b/main.go @@ -44,7 +44,7 @@ func main() { for { log.Println("fetching items ...") - r, err := c.Items(&sn.ItemsQuery{Sort: "recent", Limit: 100}) + r, err := c.Items(&sn.ItemsQuery{Sort: "recent", Type: "all", Limit: 100}) if err != nil { log.Println(err) SendToNostr(fmt.Sprint(err)) @@ -53,26 +53,30 @@ func main() { } for _, item := range r.Items { - if m := TwitterUrlRegexp.FindStringSubmatch(item.Url); m != nil { + var m []string + var comment string + + if m = TwitterUrlRegexp.FindStringSubmatch(item.Url); m != nil { + comment = strings.Replace(item.Url, m[1], "xcancel.com", 1) + } else if m = TwitterUrlRegexp.FindStringSubmatch(item.Text); m != nil { + comment = strings.Replace(item.Text, m[1], "xcancel.com", 1) + } + + if comment != "" { log.Printf("item %d is twitter link\n", item.Id) + if ItemHasComment(item.Id) { log.Printf("item %d already has nitter links comment\n", item.Id) continue } - comment := "**Twitter2Nitter**\n\nClearnet: " - for _, nUrl := range NitterClearnetUrls { - nitterLink := strings.Replace(item.Url, m[1], nUrl, 1) - comment += fmt.Sprintf("[%s](%s) | ", nUrl, nitterLink) - } - comment = strings.TrimRight(comment, "| ") - comment += "\n\n_Nitter is a free and open source alternative Twitter front-end focused on privacy and performance. " - comment += "Click [here](https://github.com/zedeus/nitter) for more information._" + cId, err := c.CreateComment(item.Id, comment) if err != nil { - log.Println(err) + log.Println("create comment failed:", err) SendToNostr(fmt.Sprint(err)) continue } + log.Printf("created comment %d\n", cId) SaveComment(&sn.Comment{Id: cId, Text: comment, ParentId: item.Id}) } else {