shithub: hell

Download patch

ref: 79dc9d4959e4d5b93a72a10e282237e00385b59c
parent: 581c0764699f92cbdde239602e69fb40662628e4
author: penny <penny@limitedideas.org>
date: Mon Aug 11 08:16:13 EDT 2025

objectify mastodon

--- a/main.go
+++ b/main.go
@@ -156,7 +156,7 @@
 				if err != nil {
 					printMastodonErr(err)
 				} else {
-					fmt.Printf(formatFavorite(postItem, arguments) + "\n")
+					fmt.Printf(hc.formatFavorite(postItem, arguments) + "\n")
 				}
 			case "mark":
 				_, err := client.Bookmark(context.Background(), postItem.ID)
@@ -163,7 +163,7 @@
 				if err != nil {
 					printMastodonErr(err)
 				} else {
-					fmt.Printf(formatBookmark(postItem, arguments) + "\n")
+					fmt.Printf(hc.formatBookmark(postItem, arguments) + "\n")
 				}
 			case "unmark":
 				_, err := client.Unbookmark(context.Background(), postItem.ID)
@@ -170,7 +170,7 @@
 				if err != nil {
 					printMastodonErr(err)
 				} else {
-					fmt.Printf(formatUnbookmark(postItem, arguments) + "\n")
+					fmt.Printf(hc.formatUnbookmark(postItem, arguments) + "\n")
 				}
 			case "open":
 				url := fmt.Sprintf("%v/statuses/%v", client.Config.Server, postItem.ID)
@@ -209,7 +209,7 @@
 				}
 				recentpost = rtStatus
 				saveWorkRef(homeMap, rtStatus, postref)
-				printPost("?"+postref, rtStatus)
+				hc.printPost("?"+postref, rtStatus)
 				postref = IncrementString(postref)
 			case "parent":
 				if postItem.InReplyToID == nil {
@@ -218,7 +218,7 @@
 				}
 				parentStatus, _ := client.GetStatus(context.Background(), mastodon.ID(postItem.InReplyToID.(string)))
 				saveWorkRef(homeMap, parentStatus, postref)
-				printPost("?"+postref, parentStatus)
+				hc.printPost("?"+postref, parentStatus)
 				postref = IncrementString(postref)
 			case "children":
 				context, err := client.GetStatusContext(context.Background(), postItem.ID)
@@ -231,7 +231,7 @@
 				}
 				for post := range context.Descendants {
 					saveWorkRef(homeMap, context.Descendants[post], postref)
-					printPost("?"+postref, context.Descendants[post])
+					hc.printPost("?"+postref, context.Descendants[post])
 					postref = IncrementString(postref)
 				}
 			case "thread":
@@ -243,15 +243,15 @@
 				hc.pause(true) // pause so user can read the thread
 				for post := range context.Ancestors {
 					saveWorkRef(homeMap, context.Ancestors[post], postref)
-					printPost("?"+postref, context.Ancestors[post])
+					hc.printPost("?"+postref, context.Ancestors[post])
 					postref = IncrementString(postref)
 				}
 
-				printPost(index, postItem)
+				hc.printPost(index, postItem)
 
 				for post := range context.Descendants {
 					saveWorkRef(homeMap, context.Descendants[post], postref)
-					printPost("?"+postref, context.Descendants[post])
+					hc.printPost("?"+postref, context.Descendants[post])
 					postref = IncrementString(postref)
 				}
 			case "account":
--- a/mastodon.go
+++ b/mastodon.go
@@ -73,7 +73,7 @@
 	return c
 }
 
-func renderStatus(content string) string {
+func (hc *Hellclient) renderStatus(content string) string {
 	doc, err := html.Parse(strings.NewReader(content))
 	if err != nil {
 		log.Fatal(err)
@@ -154,38 +154,38 @@
 }
 
 // Spaces before prefixes (no space if you're not passing a prefix)
-func formatReblog(post *mastodon.Status, index string) string {
+func (hc *Hellclient) formatReblog(post *mastodon.Status, index string) string {
 	reblogString := fmt.Sprintf(" <%v> Reblogged", post.Account.Username)
-	return hyphenate(formatStatusDetailed(post.Reblog, index, reblogString))
+	return hyphenate(hc.formatStatusDetailed(post.Reblog, index, reblogString))
 }
 
-func formatFavorite(post *mastodon.Status, index string) string {
+func (hc *Hellclient) formatFavorite(post *mastodon.Status, index string) string {
 	favString := fmt.Sprintf("Favorited: %v", index)
-	return hyphenate(formatStatusDetailed(post, "", favString))
+	return hyphenate(hc.formatStatusDetailed(post, "", favString))
 }
 
-func formatBookmark(post *mastodon.Status, index string) string {
+func (hc *Hellclient) formatBookmark(post *mastodon.Status, index string) string {
 	favString := fmt.Sprintf("Bookmarked: %v", index)
-	return hyphenate(formatStatusDetailed(post, "", favString))
+	return hyphenate(hc.formatStatusDetailed(post, "", favString))
 }
 
-func formatUnbookmark(post *mastodon.Status, index string) string {
+func (hc *Hellclient) formatUnbookmark(post *mastodon.Status, index string) string {
 	favString := fmt.Sprintf("Unbookmarked: %v", index)
-	return hyphenate(formatStatusDetailed(post, "", favString))
+	return hyphenate(hc.formatStatusDetailed(post, "", favString))
 }
 
-func formatStatus(post *mastodon.Status, index string) string {
-	return formatStatusDetailed(post, index, " ")
+func (hc *Hellclient) formatStatus(post *mastodon.Status, index string) string {
+	return hc.formatStatusDetailed(post, index, " ")
 }
 
-func formatStatusDetailed(post *mastodon.Status, index string, prefix string) string {
-	renderedPost := renderStatus(post.Content)
+func (hc *Hellclient) formatStatusDetailed(post *mastodon.Status, index string, prefix string) string {
+	renderedPost := hc.renderStatus(post.Content)
 	return fmt.Sprintf("%v%v <%v> %v", index, prefix, post.Account.Username, html2text.HTML2Text(renderedPost))
 }
 
-func formatEdit(post *mastodon.Status, index string) string {
+func (hc *Hellclient) formatEdit(post *mastodon.Status, index string) string {
 	editString := fmt.Sprintf(" <%v> EDITED:", post.Account.Username)
-	return hyphenate(formatStatusDetailed(post, index, editString))
+	return hyphenate(hc.formatStatusDetailed(post, index, editString))
 }
 
 func printMastodonErr(err error) {
@@ -192,26 +192,26 @@
 	fmt.Printf("\r%w\n", err)
 }
 
-func printPost(postref string, post *mastodon.Status) *mastodon.Status {
-	return printPostDetailed(postref, post, "")
+func (hc *Hellclient) printPost(postref string, post *mastodon.Status) *mastodon.Status {
+	return hc.printPostDetailed(postref, post, "")
 }
 
-func printPostDetailed(postref string, post *mastodon.Status, prefix string) *mastodon.Status {
-	post, plaintext := RenderPostPlaintext(post, postref, prefix)
+func (hc *Hellclient) printPostDetailed(postref string, post *mastodon.Status, prefix string) *mastodon.Status {
+	post, plaintext := hc.RenderPostPlaintext(post, postref, prefix)
 	fmt.Println(plaintext)
 	return post
 }
 
-func RenderPostPlaintext(post *mastodon.Status, postref string, prefix string) (selectedPost *mastodon.Status, plaintext string) {
+func (hc *Hellclient) RenderPostPlaintext(post *mastodon.Status, postref string, prefix string) (selectedPost *mastodon.Status, plaintext string) {
 	poststring := ""
 	postfix := ""
 	var media []mastodon.Attachment
 	if post.Reblog != nil {
-		poststring = formatReblog(post, postref)
+		poststring = hc.formatReblog(post, postref)
 		selectedPost = post.Reblog
 		media = post.Reblog.MediaAttachments
 	} else {
-		poststring = formatStatusDetailed(post, postref, prefix)
+		poststring = hc.formatStatusDetailed(post, postref, prefix)
 		selectedPost = post
 		media = post.MediaAttachments
 	}
@@ -263,10 +263,10 @@
 						currentPostRef := postref
 						capturedPost := post
 						hc.actionBuffer = append(hc.actionBuffer, func() {
-							capturedPost.Status = printPost(currentPostRef, capturedPost.Status)
+							capturedPost.Status = hc.printPost(currentPostRef, capturedPost.Status)
 						})
 					} else {
-						post.Status = printPost(postref, post.Status)
+						post.Status = hc.printPost(postref, post.Status)
 					}
 					saveRef(postMap, post.Status, postref)
 					idmap[post.Status.ID] = post.Status
@@ -277,10 +277,10 @@
 						currentPostRef := postref
 						capturedPost := post
 						hc.actionBuffer = append(hc.actionBuffer, func() {
-							fmt.Println(formatEdit(capturedPost.Status, currentPostRef))
+							fmt.Println(hc.formatEdit(capturedPost.Status, currentPostRef))
 						})
 					} else {
-						fmt.Println(formatEdit(post.Status, postref))
+						fmt.Println(hc.formatEdit(post.Status, postref))
 					}
 					saveRef(postMap, post.Status, postref)
 					postref = IncrementString(postref)
@@ -302,10 +302,10 @@
 					}
 					if hc.isPaused {
 						hc.actionBuffer = append(hc.actionBuffer, func() {
-							printPostDetailed("", deleted, "Deleted:")
+							hc.printPostDetailed("", deleted, "Deleted:")
 						})
 					} else {
-						printPostDetailed("", deleted, "Deleted:")
+						hc.printPostDetailed("", deleted, "Deleted:")
 					}
 					return
 
@@ -321,7 +321,7 @@
 						}
 						return
 					}
-					_, plaintext = RenderPostPlaintext(post.Notification.Status, postref, "")
+					_, plaintext = hc.RenderPostPlaintext(post.Notification.Status, postref, "")
 					notification := fmt.Sprintf("Notification [%v] from <%v>: %v\n", post.Notification.Type, post.Notification.Account.Acct, plaintext)
 					if hc.isPaused {
 						hc.actionBuffer = append(hc.actionBuffer, func() {
--