Update go-lemmy library

This commit is contained in:
Elara 2023-01-09 12:55:51 -08:00
parent cafc23598d
commit b6fb1a06e2
3 changed files with 27 additions and 13 deletions

5
go.mod
View File

@ -2,18 +2,19 @@ module go.arsenm.dev/lemmy-reply-bot
go 1.19 go 1.19
//replace go.arsenm.dev/go-lemmy => /home/arsen/Code/go-lemmy replace go.arsenm.dev/go-lemmy => /home/arsen/Code/go-lemmy
require ( require (
github.com/pelletier/go-toml/v2 v2.0.6 github.com/pelletier/go-toml/v2 v2.0.6
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
github.com/vmihailenco/msgpack/v5 v5.3.5 github.com/vmihailenco/msgpack/v5 v5.3.5
go.arsenm.dev/go-lemmy v0.16.7 go.arsenm.dev/go-lemmy v0.16.8-0.20230109205406-c0aced05f0cd
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df
go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e
) )
require ( require (
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/gookit/color v1.5.1 // indirect github.com/gookit/color v1.5.1 // indirect

4
go.sum
View File

@ -1,3 +1,5 @@
github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4=
github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -41,8 +43,6 @@ github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.arsenm.dev/go-lemmy v0.16.7 h1:aY343U5AMFryffRO9PsKPBMLKAl91WdwmlCYXW3TdGM=
go.arsenm.dev/go-lemmy v0.16.7/go.mod h1:Ytr6kiml1hmSvTHvOz+qV79HSNS4FtIynJfj8KWmT5Q=
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df h1:8mBHvEe7BJmpOeKSMA5YLqrGo9dCpePocTeR0C1+/2w= go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df h1:8mBHvEe7BJmpOeKSMA5YLqrGo9dCpePocTeR0C1+/2w=
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw= go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw=
go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e h1:4XwLmFDvAKt7ZvS3E3hD2R++0wr75fBUEvXkK9dLXzk= go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e h1:4XwLmFDvAKt7ZvS3E3hD2R++0wr75fBUEvXkK9dLXzk=

31
main.go
View File

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"fmt"
"os" "os"
"os/signal" "os/signal"
"strconv" "strconv"
@ -44,17 +45,12 @@ func main() {
log.Info("Successfully logged in to Lemmy instance").Send() log.Info("Successfully logged in to Lemmy instance").Send()
err = c.Request(types.UserOperationUserJoin, nil) joinAll(c)
if err != nil {
log.Fatal("Error joining WebSocket user context").Err(err).Send()
}
err = c.Request(types.UserOperationCommunityJoin, types.CommunityJoin{ c.OnReconnect(func(c *lemmy.WSClient) {
CommunityID: 0, joinAll(c)
log.Info("Successfully reconnected to WebSocket").Send()
}) })
if err != nil {
log.Fatal("Error joining WebSocket community context").Err(err).Send()
}
replyCh := make(chan replyJob, 200) replyCh := make(chan replyJob, 200)
@ -130,6 +126,9 @@ func commentWorker(ctx context.Context, c *lemmy.WSClient, replyCh chan<- replyJ
repliedIDs[cr.CommentView.Comment.ID] = struct{}{} repliedIDs[cr.CommentView.Comment.ID] = struct{}{}
} }
} }
case err := <-c.Errors():
fmt.Printf("%T\n", err)
log.Warn("Lemmy client error").Err(err).Send()
case <-ctx.Done(): case <-ctx.Done():
repliedStore, err := os.Create("replied.bin") repliedStore, err := os.Create("replied.bin")
if err != nil { if err != nil {
@ -186,3 +185,17 @@ func expandStr(s string, mapping func(string) string) string {
return mapping(s) return mapping(s)
}) })
} }
func joinAll(c *lemmy.WSClient) {
err := c.Request(types.UserOperationUserJoin, nil)
if err != nil {
log.Fatal("Error joining WebSocket user context").Err(err).Send()
}
err = c.Request(types.UserOperationCommunityJoin, types.CommunityJoin{
CommunityID: 0,
})
if err != nil {
log.Fatal("Error joining WebSocket community context").Err(err).Send()
}
}