shithub: hell

Download patch

ref: 2df672ac8b4c4a6e9b4ac6ea8bd7e1b461790e06
parent: 9e028273a255c6e254a1627ece5a5fcac76b04f5
author: penny <penny@limitedideas.org>
date: Wed Nov 5 14:39:12 EST 2025

almost done

--- a/commands.go
+++ b/commands.go
@@ -1109,6 +1109,80 @@
 	return cmd
 }
 
+func (hc *Hellclient) followcmd() cmder {
+		cmd := &basiccmd{}
+		cmd.hc = hc
+		cmd.bname = "follow"
+		cmd.bflags = account | acc_resolve
+		cmd.doer = func(data *cmddata) string {
+			account := data.account
+			var err error
+			var relationship *mastodon.Relationship
+			followfunc := func(job *GenericJob) { relationship, err = hc.client.AccountFollow(context.Background(), account.ID) }
+			followjob := hc.dispatchFunc(followfunc)
+			followjob.Wait()
+			if err != nil {
+				return fmt.Sprintf("Error requesting follow: %s\n", err)
+			}
+			if relationship.Following {
+				return fmt.Sprintf("Successfully followed %s\n", account.Acct)
+			}
+			if relationship.Requested {
+				return fmt.Sprintf("Follow request sent to %s\n", account.Acct)
+			}
+			return "No error but no follow or request returned in response.\n"
+		}
+		return cmd
+}
+
+func (hc *Hellclient) unfollowcmd() cmder {
+		cmd := &basiccmd{}
+		cmd.hc = hc
+		cmd.bname = "unfollow"
+		cmd.bflags = account | acc_resolve
+		cmd.doer = func(data *cmddata) string {
+			var relationship *mastodon.Relationship
+			account := data.account
+			var err error
+			unfollowfunc := func(job *GenericJob) { relationship, err = hc.client.AccountUnfollow(context.Background(), account.ID) }
+			unfollowjob := hc.dispatchFunc(unfollowfunc)
+			unfollowjob.Wait()
+			if err != nil {
+				return fmt.Sprintf("Error unfollowing account: %s\n", err)
+			}
+			if !relationship.Following {
+				return fmt.Sprintf("Successfully unfollowed %s\n", data.index)
+			}
+			return "No error but account is still followed in response\n"
+		}
+		return cmd
+}
+
+func (hc *Hellclient) filtercmd(name string, filter bool) cmder {
+	cmd := &basiccmd{}
+	cmd.hc = hc
+	cmd.bname = name
+	cmd.bflags = status | templater
+	cmd.doer = func(data *cmddata) string {
+		var err error
+		if filter {
+			_, err = hc.filterStatus(data.status)
+			if err != nil {
+				return fmt.Sprintf("Error filtering post: %v\n", err)
+			}
+			url := fmt.Sprintf("%v/statuses/%v", hc.client.Config.Server, data.status.ID)
+			return fmt.Sprintf("Filtered %v\n", url)
+		}
+		_, err = hc.unfilterStatus(data.status)
+		if err != nil {
+			return fmt.Sprintf("Error unfiltering post: %v\n", err)
+		}
+		line, _ := data.templater.render("Unfiltered: $standard_or_subject\n")
+		return line
+	}
+	return cmd
+}
+
 // Commmands are lazy evaluated in this order
 // Single/two letter matches need to match the most common commands
 func (hc *Hellclient) newCmdArray() []cmder {
@@ -1149,11 +1223,15 @@
 		hc.localcmd(),
 		hc.statusurlcmd("open", &hc.preferences.Browser),
 		hc.urlcmd("url", &hc.preferences.Browser),
+		hc.filtercmd("ufpost", false),
+		hc.unfollowcmd(),
 		hc.urlcmd("play", &hc.preferences.MediaPlayer),
 		hc.mediacmd("view", &hc.preferences.ImageViewer),
 		hc.mediacmd("import", &hc.preferences.MediaImport),
 		hc.editcmd(),
 		hc.threadcmd(),
+		hc.followcmd(),
+		hc.filtercmd("fpost", true),
 
 	}
 	return cmdarray
--- a/main.go
+++ b/main.go
@@ -21,9 +21,7 @@
 
 	homeMap := hc.homeMap
 	lastindex := ""
-	var lastaccount *mastodon.Account
 
-
 	go StreamHomeTimeline(&client, homeMap, hc)
 
 	for {
@@ -64,10 +62,6 @@
 
 			index, content, _ := strings.Cut(arguments, " ")
 			
-			
-
-
-
 			postItem, postOK := homeMap[index]
 
 			//Wether we got a post index or not
@@ -76,7 +70,6 @@
 			if postOK {
 				foundindex = true
 				lastindex = index
-				lastaccount = nil
 			} else {
 				postItem, postOK = homeMap[lastindex]
 			}
@@ -117,67 +110,6 @@
 
 			//Commands require status indexes
 			switch command {
-			case "unfollow":
-				account := accByNameOrRef()
-				if account == nil {
-					fmt.Printf("Account lookup failed.")
-					return
-				}
-				var relationship *mastodon.Relationship
-				unfollowfunc := func(job *GenericJob) { relationship, err = hc.client.AccountUnfollow(context.Background(), account.ID) }
-				unfollowjob := hc.dispatchFunc(unfollowfunc)
-				unfollowjob.Wait()
-				if err != nil {
-					fmt.Printf("Error unfollowing account: %s\n", err)
-					return
-				}
-				if !relationship.Following {
-					fmt.Printf("Successfully unfollowed %s\n", index)
-					return
-				}
-				fmt.Printf("Unknown failure, account is still followed\n")
-				return
-
-			case "follow":				
-				account := accByNameOrRef()
-				if account == nil {
-					fmt.Printf("Account lookup failed.\n")
-					return
-				}
-				var relationship *mastodon.Relationship
-				followfunc := func(job *GenericJob) { relationship, err = hc.client.AccountFollow(context.Background(), account.ID) }
-				followjob := hc.dispatchFunc(followfunc)
-				followjob.Wait()
-				if err != nil {
-					fmt.Printf("Error requesting follow: %s\n", err)
-					return
-				}
-				if relationship.Following {
-					fmt.Printf("Successfully followed %s\n", account.Acct)
-					return
-				}
-				if relationship.Requested {
-					fmt.Printf("Follow request sent to %s\n", account.Acct)
-					return
-				}
-			case "fpost":
-				_, err := hc.filterStatus(postItem)
-				if err != nil {
-					fmt.Printf("Error filtering post: %v\n", err)
-					return
-				}
-				url := fmt.Sprintf("%v/statuses/%v", client.Config.Server, postItem.ID)
-				fmt.Printf("Filtered %v\n", url)
-				return
-			case "ufpost":
-				_, err := hc.unfilterStatus(postItem)
-				if err != nil {
-					fmt.Printf("Error unfiltering post: %v\n", err)
-					return
-				}
-				line, _ := templater.render("Unfiltered: %s> $standard_or_subject\n")
-				fmt.Print(line)
-				return
 			case "block":
 				var account *mastodon.Account
 				if foundindex || index == "" {
--