Also reply to comments with xcancel.com link

This commit is contained in:
ekzyis 2024-09-08 21:04:06 +02:00
parent ef9886efc5
commit 6a4892944b
3 changed files with 18 additions and 14 deletions

2
go.mod
View File

@ -3,6 +3,6 @@ module git.ekzyis.com/ekzyis/unpaywall
go 1.21.0 go 1.21.0
require ( require (
github.com/ekzyis/snappy v0.5.2 github.com/ekzyis/snappy v0.5.3
github.com/mattn/go-sqlite3 v1.14.17 github.com/mattn/go-sqlite3 v1.14.17
) )

4
go.sum
View File

@ -1,4 +1,4 @@
github.com/ekzyis/snappy v0.5.2 h1:3dZyj3Kz7fV3OStllq/koL6d5qNfBRK+4UB2L3RNmiQ= github.com/ekzyis/snappy v0.5.3 h1:Pq8b2s4WPz5gnHgCoZR2LVqArEVqWeVCyHSVZCawat4=
github.com/ekzyis/snappy v0.5.2/go.mod h1:BxJwdGlCwUw0Q5pQzBr59weAIS6pkVdivBBaZkkWTSo= 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 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=

26
main.go
View File

@ -44,7 +44,7 @@ func main() {
for { for {
log.Println("fetching items ...") 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 { if err != nil {
log.Println(err) log.Println(err)
SendToNostr(fmt.Sprint(err)) SendToNostr(fmt.Sprint(err))
@ -53,26 +53,30 @@ func main() {
} }
for _, item := range r.Items { 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) log.Printf("item %d is twitter link\n", item.Id)
if ItemHasComment(item.Id) { if ItemHasComment(item.Id) {
log.Printf("item %d already has nitter links comment\n", item.Id) log.Printf("item %d already has nitter links comment\n", item.Id)
continue 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) cId, err := c.CreateComment(item.Id, comment)
if err != nil { if err != nil {
log.Println(err) log.Println("create comment failed:", err)
SendToNostr(fmt.Sprint(err)) SendToNostr(fmt.Sprint(err))
continue continue
} }
log.Printf("created comment %d\n", cId) log.Printf("created comment %d\n", cId)
SaveComment(&sn.Comment{Id: cId, Text: comment, ParentId: item.Id}) SaveComment(&sn.Comment{Id: cId, Text: comment, ParentId: item.Id})
} else { } else {