From 5f08507a0dc7dfea0df9e203c637273f04581f72 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Thu, 5 Jan 2023 14:01:33 -0800 Subject: [PATCH] Update go-lemmy library --- go.mod | 2 +- go.sum | 4 ++-- main.go | 14 ++++++-------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index eb8a824..ccc4db3 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/pelletier/go-toml/v2 v2.0.6 github.com/spf13/pflag v1.0.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/pcre v0.0.0-20220530205550-74594f6c8b0e ) diff --git a/go.sum b/go.sum index 2a0dca8..09f64b0 100644 --- a/go.sum +++ b/go.sum @@ -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/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= 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-20221213090943-92b96981e2e1/go.mod h1:q7CIDksHIqltFNugJAixGTqk1Gp+a9emZMlILhU7Uh0= +go.arsenm.dev/go-lemmy v0.0.0-20230105214607-754cfa602c10 h1:aQYXs2KVWztLLZ3i9tIH/rS3X4TllS0jXI8twJhJMtk= +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/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw= go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e h1:4XwLmFDvAKt7ZvS3E3hD2R++0wr75fBUEvXkK9dLXzk= diff --git a/main.go b/main.go index 8652364..790da44 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ func main() { 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, Password: cfg.Lemmy.Account.Password, }) @@ -44,12 +44,12 @@ func main() { log.Info("Successfully logged in to Lemmy instance").Send() - err = c.Request(types.UserOpUserJoin, nil) + err = c.Request(types.UserOperationUserJoin, nil) if err != nil { 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, }) if err != nil { @@ -80,9 +80,7 @@ func commentWorker(ctx context.Context, c *lemmy.WSClient, replyCh chan<- replyJ for { select { case res := <-c.Responses(): - // Check which operation has been sent from the server - switch res.Op { - case types.UserOpCreateComment, types.UserOpEditComment: + if res.IsOneOf(types.UserOperationCrudCreateComment, types.UserOperationCrudEditComment) { var cr types.CommentResponse err = lemmy.DecodeResponse(res.Data, &cr) if err != nil { @@ -160,7 +158,7 @@ func commentReplyWorker(ctx context.Context, c *lemmy.WSClient, ch <-chan replyJ for { select { case reply := <-ch: - err := c.Request(types.UserOpCreateComment, types.CreateComment{ + err := c.Request(types.UserOperationCrudCreateComment, types.CreateComment{ PostID: reply.PostID, ParentID: types.NewOptional(reply.CommentID), 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 { - strings.ReplaceAll(s, "$$", "${_escaped_dollar_symbol}") + s = strings.ReplaceAll(s, "$$", "${_escaped_dollar_symbol}") return os.Expand(s, func(s string) string { if s == "_escaped_dollar_symbol" { return "$"