shithub: hell

Download patch

ref: 78e3bc4908c7b6c2d7b5e39ba485fb0f8e0113f7
parent: e3419ac8376d16abdd502810bc18b696ec2340ed
author: penny <penny@limitedideas.org>
date: Tue Jul 29 23:31:51 EDT 2025

Improve replies, add deletes and reblogs

--- a/commands.go
+++ b/commands.go
@@ -4,7 +4,7 @@
 	"strings"
 )
 
-var commands = []string{"examine", "reply", "like", "thread", "open", "preview", "dm", "rt", "parent", "children", "thread"}
+var commands = []string{"examine", "reply", "like", "thread", "open", "preview", "dm", "rt", "parent", "children", "thread", "rm"}
 
 func processInput(input string) (command string, arguments string) {
 
@@ -22,7 +22,7 @@
 
 	input = input[1:]
 
-	command = ""
+	command = "Command not found"
 	arguments = ""
 	commandInput := ""
 
--- a/main.go
+++ b/main.go
@@ -34,6 +34,14 @@
 	homeMap := make(map[string]*mastodon.Status)
 	debugMap := make(map[string]interface{})
 	postref := "a"
+	var recentpost *mastodon.Status
+	
+	currentUser, err := client.GetAccountCurrentUser(context.Background())
+	
+	if err != nil {
+		fmt.Println("Couldn't get our own profile", err)
+		return
+	}
 
 	go StreamHomeTimeline(client, rl, homeMap)
 
@@ -48,27 +56,56 @@
 
 		//if we didn't get a slash command then the user is just posting
 		if command == "" && arguments != "" {
-			postStatus(fmt.Sprintf(line), account, *client, "public")
+			recentpost, err = postStatus(fmt.Sprintf(line), account, *client, "public")
+			if(err != nil) {
+				fmt.Println(err)
+			}
 			continue
 		}
+		
+		index, content, _ := strings.Cut(arguments, " ")
+		postItem, postOK := homeMap[index]
+		debugItem, debugOK := debugMap[index]
+		
+		//Contextual commands that need to handle their own requirements
+		switch command {
+		case "rm":
+			if(!postOK && recentpost != nil) {
+				err = client.DeleteStatus(context.Background(), recentpost.ID)
+				if(err != nil) {
+					fmt.Println(err)
+				}
+				recentpost = nil
+				continue
+			}
+			if(!postOK) {
+				fmt.Println("No recent status to delete or post index not valid")
+				continue
+			}
+			err = client.DeleteStatus(context.Background(), postItem.ID)
+			if(err != nil) {
+					fmt.Println(err)
+			}
+			continue
+		}
+		
 		if arguments == "" {
 			fmt.Printf("%v requires an argument\n", command)
 			continue
 		}
-		index, content, _ := strings.Cut(arguments, " ")
-		postItem, postOK := homeMap[index]
-		debugItem, debugOK := debugMap[index]
 
 		//Commands that don't take an index
 		switch command {
 		case "dm":
-			postStatus(arguments, account, *client, "direct")
+			recentpost, err = postStatus(arguments, account, *client, "direct")
+			if(err != nil) {
+					fmt.Println(err)
+			}
 			continue
-		}
-
 		if !postOK && !debugOK {
 			fmt.Printf("\"%v\" not a valid index\n", index)
 			continue
+			}
 		}
 
 		//Commands that accept debug indexes
@@ -87,7 +124,7 @@
 			fmt.Printf("\"%v\" not a valid post index\n", index)
 			continue
 		}
-		//Commands that only accept status indexes
+		//Commands require status indexes
 		switch command {
 		case "like":
 			_, err := client.Favourite(context.Background(), postItem.ID)
@@ -105,8 +142,28 @@
 			cmd := exec.Command("open", url)
 			cmd.Run()
 		case "reply":
-			
-			postReply("@"+getUserString(postItem)+" "+content, account, *client, postItem.Visibility, postItem.ID)
+			if currentUser.ID == postItem.Account.ID {
+				recentpost, err = postReply(content, account, *client, postItem.Visibility, postItem.ID)
+				if (err != nil) {
+					fmt.Println(err)
+				}
+				continue
+			}
+			recentpost, err = postReply("@"+getUserString(postItem)+" "+content, account, *client, postItem.Visibility, postItem.ID)
+			if (err != nil) {
+				fmt.Println(err)
+			}
+			continue
+		case "rt":
+			rtStatus, err := client.Reblog(context.Background(), postItem.ID)
+			if (err != nil) {
+				fmt.Println(err)
+				continue
+			}
+			recentpost = rtStatus
+			saveWorkRef(homeMap, rtStatus, postref)
+			printPost("?"+postref, rtStatus)
+			postref = IncrementString(postref)	
 		case "parent":
 			if postItem.InReplyToID == nil {
 				fmt.Printf("%v doesn't have a parent\n", index)
--- a/mastodon.go
+++ b/mastodon.go
@@ -106,31 +106,34 @@
 	return rendered.String()
 }
 
-func postReply(posttext string, account *account, client mastodon.Client, visibility string, replyto mastodon.ID) {
+func postReply(posttext string, account *account, client mastodon.Client, visibility string, replyto mastodon.ID) (status *mastodon.Status, err error){
 	toot := mastodon.Toot{
 		Status:      posttext,
 		Visibility:  visibility,
 		InReplyToID: replyto,
 	}
-	postStatusDetailed(posttext, account, client, visibility, toot)
+	status, err = postStatusDetailed(posttext, account, client, visibility, toot)
+	return
 }
 
-func postStatus(posttext string, account *account, client mastodon.Client, visibility string) {
+func postStatus(posttext string, account *account, client mastodon.Client, visibility string) (status *mastodon.Status, err error) {
 	// Post a toot
 	toot := mastodon.Toot{
 		Status:     posttext,
 		Visibility: visibility,
 	}
-	postStatusDetailed(posttext, account, client, visibility, toot)
+	status, err = postStatusDetailed(posttext, account, client, visibility, toot)
+	return
 }
 
-func postStatusDetailed(posttext string, account *account, client mastodon.Client, visibility string, toot mastodon.Toot) {
-	_, err := client.PostStatus(context.Background(), &toot)
+func postStatusDetailed(posttext string, account *account, client mastodon.Client, visibility string, toot mastodon.Toot) (status *mastodon.Status, err error){
+	status, err = client.PostStatus(context.Background(), &toot)
 
 	if err != nil {
 		printMastodonErr(err)
 		return
 	}
+	return
 }
 
 func getUserString(post *mastodon.Status) string {
--