Update go-lemmy library

This commit is contained in:
Elara 2023-01-05 14:01:33 -08:00
parent 5cec172846
commit 5f08507a0d
3 changed files with 9 additions and 11 deletions

2
go.mod
View File

@ -8,7 +8,7 @@ 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.0.0-20221213090943-92b96981e2e1 go.arsenm.dev/go-lemmy v0.0.0-20230105214607-754cfa602c10
go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334 go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334
go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e
) )

4
go.sum
View File

@ -41,8 +41,8 @@ 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.0.0-20221213090943-92b96981e2e1 h1:SY7BxO21feXrg5zWYbvIfZ3vuz8qvODjR39kOlKwTbc= go.arsenm.dev/go-lemmy v0.0.0-20230105214607-754cfa602c10 h1:aQYXs2KVWztLLZ3i9tIH/rS3X4TllS0jXI8twJhJMtk=
go.arsenm.dev/go-lemmy v0.0.0-20221213090943-92b96981e2e1/go.mod h1:q7CIDksHIqltFNugJAixGTqk1Gp+a9emZMlILhU7Uh0= go.arsenm.dev/go-lemmy v0.0.0-20230105214607-754cfa602c10/go.mod h1:Br91zaVgauLWmj4sgk600XiD8297NpBTESULvGwMTdU=
go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334 h1:S98LJOBmj1pAKSw94spJk6+n8ERlBNTxi4lt5B67nQo= go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334 h1:S98LJOBmj1pAKSw94spJk6+n8ERlBNTxi4lt5B67nQo=
go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw= go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334/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=

14
main.go
View File

@ -34,7 +34,7 @@ func main() {
log.Fatal("Error creating new Lemmy API client").Err(err).Send() log.Fatal("Error creating new Lemmy API client").Err(err).Send()
} }
err = c.Login(ctx, types.Login{ err = c.ClientLogin(ctx, types.Login{
UsernameOrEmail: cfg.Lemmy.Account.UserOrEmail, UsernameOrEmail: cfg.Lemmy.Account.UserOrEmail,
Password: cfg.Lemmy.Account.Password, Password: cfg.Lemmy.Account.Password,
}) })
@ -44,12 +44,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.UserOpUserJoin, nil) err = c.Request(types.UserOperationUserJoin, nil)
if err != nil { if err != nil {
log.Fatal("Error joining WebSocket user context").Err(err).Send() log.Fatal("Error joining WebSocket user context").Err(err).Send()
} }
err = c.Request(types.UserOpCommunityJoin, types.CommunityJoin{ err = c.Request(types.UserOperationCommunityJoin, types.CommunityJoin{
CommunityID: 0, CommunityID: 0,
}) })
if err != nil { if err != nil {
@ -80,9 +80,7 @@ func commentWorker(ctx context.Context, c *lemmy.WSClient, replyCh chan<- replyJ
for { for {
select { select {
case res := <-c.Responses(): case res := <-c.Responses():
// Check which operation has been sent from the server if res.IsOneOf(types.UserOperationCrudCreateComment, types.UserOperationCrudEditComment) {
switch res.Op {
case types.UserOpCreateComment, types.UserOpEditComment:
var cr types.CommentResponse var cr types.CommentResponse
err = lemmy.DecodeResponse(res.Data, &cr) err = lemmy.DecodeResponse(res.Data, &cr)
if err != nil { if err != nil {
@ -160,7 +158,7 @@ func commentReplyWorker(ctx context.Context, c *lemmy.WSClient, ch <-chan replyJ
for { for {
select { select {
case reply := <-ch: case reply := <-ch:
err := c.Request(types.UserOpCreateComment, types.CreateComment{ err := c.Request(types.UserOperationCrudCreateComment, types.CreateComment{
PostID: reply.PostID, PostID: reply.PostID,
ParentID: types.NewOptional(reply.CommentID), ParentID: types.NewOptional(reply.CommentID),
Content: reply.Content, Content: reply.Content,
@ -180,7 +178,7 @@ func commentReplyWorker(ctx context.Context, c *lemmy.WSClient, ch <-chan replyJ
} }
func expandStr(s string, mapping func(string) string) string { func expandStr(s string, mapping func(string) string) string {
strings.ReplaceAll(s, "$$", "${_escaped_dollar_symbol}") s = strings.ReplaceAll(s, "$$", "${_escaped_dollar_symbol}")
return os.Expand(s, func(s string) string { return os.Expand(s, func(s string) string {
if s == "_escaped_dollar_symbol" { if s == "_escaped_dollar_symbol" {
return "$" return "$"