From df88e2a7aade839bef116d41cfc207331e660184 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Sun, 24 Sep 2023 19:48:38 -0700 Subject: [PATCH] Update for new go-lemmy generator --- go.mod | 2 +- go.sum | 4 ++-- main.go | 38 +++++++++++++++++++------------------- main_test.go | 8 ++++---- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index 29e195d..ad87d92 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/jarcoal/httpmock v1.3.1 github.com/pelletier/go-toml/v2 v2.0.6 github.com/spf13/pflag v1.0.5 - go.elara.ws/go-lemmy v0.18.1-0.20230902225105-9f4bae88f2fe + go.elara.ws/go-lemmy v0.18.1-0.20230925023946-7e4c13d03170 go.elara.ws/logger v0.0.0-20230421022458-e80700db2090 go.elara.ws/pcre v0.0.0-20230805032557-4ce849193f64 modernc.org/sqlite v1.25.0 diff --git a/go.sum b/go.sum index 84d6ff0..98e5942 100644 --- a/go.sum +++ b/go.sum @@ -57,8 +57,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o 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.elara.ws/go-lemmy v0.18.1-0.20230902225105-9f4bae88f2fe h1:X7mPzVAc7zZipyzxzi4kdFuRptEsM6GJYLLJQtKiJrQ= -go.elara.ws/go-lemmy v0.18.1-0.20230902225105-9f4bae88f2fe/go.mod h1:rurQND/HT3yWfX/T4w+hb6vEwRAeAlV+9bSGFkkx5rA= +go.elara.ws/go-lemmy v0.18.1-0.20230925023946-7e4c13d03170 h1:TKscLCs4Rr0uUxNyAXWMdUUVQsh+0KYggkPcLiHN9tY= +go.elara.ws/go-lemmy v0.18.1-0.20230925023946-7e4c13d03170/go.mod h1:aZbF/4c1VA7qPXsP4Pth0ERu3HGZFPPl8bTY1ltBrcQ= go.elara.ws/logger v0.0.0-20230421022458-e80700db2090 h1:RVC8XvWo6Yw4HUshqx4TSzuBDScDghafU6QFRJ4xPZg= go.elara.ws/logger v0.0.0-20230421022458-e80700db2090/go.mod h1:qng49owViqsW5Aey93lwBXONw20oGbJIoLVscB16mPM= go.elara.ws/pcre v0.0.0-20230805032557-4ce849193f64 h1:QixGnJE1jP08Hs1G3rS7tZGd8DeBRtz9RBpk08WlGh4= diff --git a/main.go b/main.go index e5d1ac1..97f18f5 100644 --- a/main.go +++ b/main.go @@ -90,7 +90,7 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q comments, err := c.Comments(ctx, types.GetComments{ Type: types.NewOptional(types.ListingTypeLocal), Sort: types.NewOptional(types.CommentSortTypeNew), - Limit: types.NewOptional[int64](50), + Limit: types.NewOptional[float64](50), }) if err != nil { log.Warn("Error getting comments").Err(err).Send() @@ -116,11 +116,11 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q } else if err != nil { log.Warn("Error checking if item exists").Err(err).Send() continue - } else if item.UpdatedTime == c.Comment.Updated.Unix() { + } else if item.UpdatedTime == c.Comment.Updated.ValueOrEmpty().Unix() { // If the item we're checking for exists and hasn't been edited, // we've already replied, so skip it continue - } else if item.UpdatedTime != c.Comment.Updated.Unix() { + } else if item.UpdatedTime != c.Comment.Updated.ValueOrEmpty().Unix() { // If the item exists but has been edited since we replied, // set edit to true so we know to edit it instead of making // a new comment @@ -135,7 +135,7 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q log.Info("Matched comment body"). Int("reply-index", i). - Int("comment-id", c.Comment.ID). + Float64("comment-id", c.Comment.ID). Send() job := replyJob{ @@ -147,7 +147,7 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q // so set the job's EditID so the reply worker knows which // comment to edit if edit { - job.EditID = int(item.ReplyID) + job.EditID = float64(item.ReplyID) } matches := re.FindAllStringSubmatch(c.Comment.Content, -1) @@ -167,7 +167,7 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q err = rs.AddItem(ctx, store.AddItemParams{ ID: int64(c.Comment.ID), ItemType: store.Comment, - UpdatedTime: c.Comment.Updated.Unix(), + UpdatedTime: c.Comment.Updated.ValueOrEmpty().Unix(), }) if err != nil { log.Warn("Error adding comment to the reply store").Err(err).Send() @@ -180,7 +180,7 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q posts, err := c.Posts(ctx, types.GetPosts{ Type: types.NewOptional(types.ListingTypeLocal), Sort: types.NewOptional(types.SortTypeNew), - Limit: types.NewOptional[int64](20), + Limit: types.NewOptional[float64](20), }) if err != nil { log.Warn("Error getting comments").Err(err).Send() @@ -206,11 +206,11 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q } else if err != nil { log.Warn("Error checking if item exists").Err(err).Send() continue - } else if item.UpdatedTime == p.Post.Updated.Unix() { + } else if item.UpdatedTime == p.Post.Updated.ValueOrEmpty().Unix() { // If the item we're checking for exists and hasn't been edited, // we've already replied, so skip it continue - } else if item.UpdatedTime != p.Post.Updated.Unix() { + } else if item.UpdatedTime != p.Post.Updated.ValueOrEmpty().Unix() { // If the item exists but has been edited since we replied, // set edit to true so we know to edit it instead of making // a new comment @@ -226,7 +226,7 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q log.Info("Matched post body"). Int("reply-index", i). - Int("post-id", p.Post.ID). + Float64("post-id", p.Post.ID). Send() job := replyJob{PostID: p.Post.ID} @@ -235,7 +235,7 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q // so set the job's EditID so the reply worker knows which // comment to edit if edit { - job.EditID = int(item.ReplyID) + job.EditID = float64(item.ReplyID) } matches := re.FindAllStringSubmatch(body, -1) @@ -255,7 +255,7 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q err = rs.AddItem(ctx, store.AddItemParams{ ID: int64(p.Post.ID), ItemType: store.Post, - UpdatedTime: p.Post.Updated.Unix(), + UpdatedTime: p.Post.Updated.ValueOrEmpty().Unix(), }) if err != nil { log.Warn("Error adding post to the reply store").Err(err).Send() @@ -271,9 +271,9 @@ func commentWorker(ctx context.Context, c *lemmy.Client, cfg Config, rs *store.Q type replyJob struct { Content string - CommentID types.Optional[int] - EditID int - PostID int + CommentID types.Optional[float64] + EditID float64 + PostID float64 } func commentReplyWorker(ctx context.Context, c *lemmy.Client, rs *store.Queries, ch <-chan replyJob) { @@ -302,7 +302,7 @@ func commentReplyWorker(ctx context.Context, c *lemmy.Client, rs *store.Queries, } log.Info("Edited comment"). - Int("comment-id", cr.CommentView.Comment.ID). + Float64("comment-id", cr.CommentView.Comment.ID). Send() } else { // Create a new comment replying to a post/comment @@ -326,9 +326,9 @@ func commentReplyWorker(ctx context.Context, c *lemmy.Client, rs *store.Queries, } log.Info("Created new comment"). - Int("post-id", reply.PostID). - Int("parent-id", reply.CommentID.ValueOr(-1)). - Int("comment-id", cr.CommentView.Comment.ID). + Float64("post-id", reply.PostID). + Float64("parent-id", reply.CommentID.ValueOr(-1)). + Float64("comment-id", cr.CommentView.Comment.ID). Send() } case <-ctx.Done(): diff --git a/main_test.go b/main_test.go index 82b18b5..25fe196 100644 --- a/main_test.go +++ b/main_test.go @@ -89,7 +89,7 @@ func TestEdit(t *testing.T) { return httpmock.NewJsonResponse(200, types.CommentResponse{}) }) - edited := map[int]string{} + edited := map[float64]string{} // Whenever the edit comment endpoint is called, add the edited comment to // the edited map, so that it can be checked later @@ -148,7 +148,7 @@ func TestEdit(t *testing.T) { // Wait for the workers to stop due to context cancellation wg.Wait() - expected := map[int]string{ + expected := map[float64]string{ 100: "Lemmy Comment!", 101: "Lemmy Post!", } @@ -265,7 +265,7 @@ func registerListComments(t *testing.T) { Comment: types.Comment{ // Should match reply index 1 ID: 12, Published: types.LemmyTime{Time: time.Unix(1550164620, 0)}, - Updated: types.LemmyTime{Time: time.Unix(1581700620, 0)}, + Updated: types.NewOptional(types.LemmyTime{Time: time.Unix(1581700620, 0)}), Content: "Hello, Lemmy Comment", }, Community: types.Community{ @@ -317,7 +317,7 @@ func registerListPosts(t *testing.T) { Post: types.Post{ // Should match reply index 1 ID: 3, Published: types.LemmyTime{Time: time.Unix(1550164620, 0)}, - Updated: types.LemmyTime{Time: time.Unix(1581700620, 0)}, + Updated: types.NewOptional(types.LemmyTime{Time: time.Unix(1581700620, 0)}), Body: types.NewOptional("Hello, Lemmy Post"), }, Community: types.Community{