shithub: hell

Download patch

ref: 8ab8b816209c6475946ca79cdf8085dc887b789f
parent: 7dee6e81cb521229d588749d3d2d2732512a87a5
author: fops <billgates@cock.li>
date: Thu Oct 2 14:19:31 EDT 2025

Address go-staticcheck warnings, go mod tidy, match module name in import

--- a/config.go
+++ b/config.go
@@ -109,7 +109,7 @@
 			return nil, "", fmt.Errorf("error marshalling config: %w", err)
 		}
 
-		err = ioutil.WriteFile(configpath, b.Bytes(), 0644)
+		err = os.WriteFile(configpath, b.Bytes(), 0644)
 		if err != nil {
 			return nil, "", fmt.Errorf("error writing config file: %w", err)
 		}
@@ -117,7 +117,7 @@
 	}
 
 	// File exists, load it
-	data, err := ioutil.ReadFile(configpath)
+	data, err := os.ReadFile(configpath)
 	if err != nil {
 		return nil, "", fmt.Errorf("error reading config file: %w", err)
 	}
@@ -127,7 +127,7 @@
 		return nil, "", fmt.Errorf("error unmarshalling config: %w", err)
 	}
 	if len(config.AccountConfigs) < 1 {
-		return nil, "", fmt.Errorf("empty config?\n")
+		return nil, "", fmt.Errorf("empty config")
 	}
 
 	prefval := config.AccountConfigs[0].Preferences
--- a/dispatch.go
+++ b/dispatch.go
@@ -6,7 +6,7 @@
 	"sync"
 	"time"
 
-	"codeberg.org/penny64/hellclient-go-mastodon"
+	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 )
 
 const ()
--- a/filehandler.go
+++ b/filehandler.go
@@ -10,7 +10,7 @@
 	"path"
 	"path/filepath"
 
-	"codeberg.org/penny64/hellclient-go-mastodon"
+	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 	"github.com/google/shlex"
 )
 
@@ -25,8 +25,8 @@
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stdout
 	cmd.Run()
-	return
 }
+
 func (hc *Hellclient) previewPostImages(target *mastodon.Status, commandstring string) (err error) {
 	//Let go of the lock while we wait for return
 	hc.unlock()
@@ -89,7 +89,7 @@
 	var pathnames []string
 
 	for _, media := range target.MediaAttachments {
-		err, mediafile := downloadImage(media.URL)
+		mediafile, err := downloadImage(media.URL)
 		if err != nil {
 			fmt.Printf("Media download error: %v\n", err)
 			continue
@@ -105,20 +105,20 @@
 	return files, pathnames, nil
 }
 
-func downloadImage(target string) (error, *os.File) {
+func downloadImage(target string) (*os.File, error) {
 	response, err := http.Get(target)
 	if err != nil {
-		return err, nil
+		return nil, err
 	}
 	defer response.Body.Close()
 
 	if response.StatusCode != http.StatusOK {
-		return fmt.Errorf("bad status: %s", response.Status), nil
+		return nil, fmt.Errorf("bad status: %s", response.Status)
 	}
 
 	parsedurl, err := url.Parse(target)
 	if err != nil {
-		return err, nil
+		return nil, err
 	}
 
 	filename := path.Base(parsedurl.Path)
@@ -125,7 +125,7 @@
 
 	file, err := os.CreateTemp("", "*"+filename)
 	if err != nil {
-		return err, nil
+		return nil, err
 	}
 
 	_, err = io.Copy(file, response.Body)
@@ -132,8 +132,8 @@
 	if err != nil {
 		file.Close()
 		os.Remove(file.Name())
-		return err, nil
+		return nil, err
 	}
 
-	return nil, file
+	return file, nil
 }
--- a/filtering.go
+++ b/filtering.go
@@ -5,7 +5,7 @@
 	"errors"
 	"strconv"
 
-	"codeberg.org/penny64/hellclient-go-mastodon"
+	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 )
 
 func (hc *Hellclient) getFilterID(title string) (ID int, result *mastodon.FilterV2) {
@@ -22,7 +22,7 @@
 func (hc *Hellclient) getFilter(title string) (result *mastodon.FilterV2, err error) {
 	ID, result := hc.getFilterID(title)
 	if ID == 0 {
-		return nil, errors.New("Filter not found")
+		return nil, errors.New("filter not found")
 	}
 
 	return
@@ -49,13 +49,10 @@
 	if ID == 0 {
 		result, err = hc.createNewFilter(title, filtercontext, action)
 		if err == nil {
+			// XXX: unused ID?
 			ID, _ = strconv.Atoi(string(result.ID))
 		}
 	}
-	if err != nil {
-		return
-	}
-
 	return
 }
 
@@ -84,5 +81,5 @@
 			return
 		}
 	}
-	return nil, errors.New("Post not filtered")
+	return nil, errors.New("post not filtered")
 }
--- a/go.sum
+++ b/go.sum
@@ -20,10 +20,7 @@
 github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
 github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 h1:nrZ3ySNYwJbSpD6ce9duiP+QkD3JuLCcWkdaehUS/3Y=
 github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80/go.mod h1:iFyPdL66DjUD96XmzVL3ZntbzcflLnznH0fr99w5VqE=
-github.com/tomnomnom/linkheader v0.0.0-20250811210735-e5fe3b51442e h1:tD38/4xg4nuQCASJ/JxcvCHNb46w0cdAaJfkzQOO1bA=
-github.com/tomnomnom/linkheader v0.0.0-20250811210735-e5fe3b51442e/go.mod h1:krvJ5AY/MjdPkTeRgMYbIDhbbbVvnPQPzsIsDJO8xrY=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
 golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
@@ -30,15 +27,9 @@
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
 golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
-golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
-golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
 golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg=
 golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0=
-golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4=
-golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
-golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
 golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
 golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
--- a/hellclient.go
+++ b/hellclient.go
@@ -9,7 +9,7 @@
 	"sync"
 	"time"
 
-	"codeberg.org/penny64/hellclient-go-mastodon"
+	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 	"github.com/ergochat/readline"
 )
 
--- a/help.go
+++ b/help.go
@@ -48,5 +48,5 @@
   /likes                       Display favorited status page.
   /reload                      Reload configuration file.
 `
-return fmt.Sprintf(helpstring, configpath)
+	return fmt.Sprintf(helpstring, configpath)
 }
--- a/main.go
+++ b/main.go
@@ -9,7 +9,7 @@
 	"strings"
 	"time"
 
-	"codeberg.org/penny64/hellclient-go-mastodon"
+	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 	"github.com/k3a/html2text"
 )
 
@@ -20,7 +20,7 @@
 		return
 	}
 
-	rl := *hc.rl
+	rl := hc.rl
 	client := *hc.client
 
 	//Horrible io pipe hack
@@ -37,10 +37,6 @@
 	lastindex := ""
 	recentpost := &hc.recentpost
 
-	if err != nil {
-		return
-	}
-
 	go StreamHomeTimeline(&client, homeMap, hc)
 
 	for {
@@ -66,7 +62,7 @@
 
 			//if we didn't get a slash command then the user is just posting
 			if command == "" && arguments != "" {
-				hc.dispatchStatus(fmt.Sprintf(line), "public")
+				hc.dispatchStatus(line, "public")
 				return
 			}
 
@@ -81,7 +77,7 @@
 			index, content, _ := strings.Cut(arguments, " ")
 
 			postItem, postOK := homeMap[index]
-			debugItem, _ := debugMap[index]
+			debugItem := debugMap[index]
 
 			//Wether we got a post index or not
 			var foundindex bool
@@ -108,10 +104,10 @@
 			case "reload":
 				account, _, err := loadConfig()
 				if err != nil {
-					fmt.Printf("Error reloading config: %s\n")
+					fmt.Printf("Error reloading config: %s\n", err)
 					return
 				}
-				fmt.Println("Successfully reloaded preferences\n")
+				fmt.Println("Successfully reloaded preferences")
 				hc.preferences = &account.Preferences
 				return
 			case "stats":
@@ -161,6 +157,9 @@
 				if len(notifications) > 0 {
 					hc.PrintNotifications(notifications)
 					err = hc.SetNotificationsRead(notifications[len(notifications)-1].ID)
+					if err != nil {
+						fmt.Print(err)
+					}
 					return
 				}
 				hc.page = &Page{}
@@ -387,7 +386,7 @@
 				unfollowjob := hc.dispatchFunc(unfollowfunc)
 				unfollowjob.Wait()
 				if err != nil {
-					fmt.Printf("Error unfollowing account\n", err)
+					fmt.Printf("Error unfollowing account: %s\n", err)
 					return
 				}
 				if !relationship.Following {
--- a/mastodon.go
+++ b/mastodon.go
@@ -9,7 +9,7 @@
 	"strings"
 	"time"
 
-	"codeberg.org/penny64/hellclient-go-mastodon"
+	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 	"github.com/k3a/html2text"
 	"golang.org/x/net/html"
 )
@@ -293,7 +293,7 @@
 }
 
 func printMastodonErr(err error) {
-	fmt.Printf("\r%w\n", err)
+	fmt.Printf("\r%v\n", err)
 }
 
 func (hc *Hellclient) printPostS(ref postref, post *mastodon.Status) *mastodon.Status {
@@ -357,94 +357,77 @@
 	readchan := hc.readMarkerUpdater()
 
 	// Enter a loop to continuously listen for events from the event channel.
-	for {
-		select {
-		case event, ok := <-eventCh: // Read from the event channel, checking 'ok' for closure
-
-			if !ok {
-				// The channel was closed, which indicates the stream has ended.
-				fmt.Println("Stream closed.\n")
-				return // Exit the function
-			}
-			func() {
-				hc.lock()
-				defer hc.unlock()
-				switch post := event.(type) {
-				case *mastodon.UpdateEvent:
-					//Count the statuses
-					hc.stats.slock.Lock()
-					hc.stats.IncomingStatuses++
-					hc.stats.slock.Unlock()
-					//Tell the timeline marker updater the most recent post
-					readchan <- &post.Status.ID
-					if hc.isPaused {
-						currentPostRef := hc.homeref.ref
-						capturedPost := post
-						hc.actionBuffer = append(hc.actionBuffer, func() {
-							capturedPost.Status = hc.printPost(currentPostRef, capturedPost.Status)
-						})
-						justIncrementPostref(hc.homeref, post.Status)
-						idmap[post.Status.ID] = post.Status
-						return
-					}
-					hc.printAndIncrement(hc.homeref, post.Status)
+	for event := range eventCh {
+		func() {
+			hc.lock()
+			defer hc.unlock()
+			switch post := event.(type) {
+			case *mastodon.UpdateEvent:
+				//Count the statuses
+				hc.stats.slock.Lock()
+				hc.stats.IncomingStatuses++
+				hc.stats.slock.Unlock()
+				//Tell the timeline marker updater the most recent post
+				readchan <- &post.Status.ID
+				if hc.isPaused {
+					currentPostRef := hc.homeref.ref
+					capturedPost := post
+					hc.actionBuffer = append(hc.actionBuffer, func() {
+						capturedPost.Status = hc.printPost(currentPostRef, capturedPost.Status)
+					})
+					justIncrementPostref(hc.homeref, post.Status)
 					idmap[post.Status.ID] = post.Status
 					return
+				}
+				hc.printAndIncrement(hc.homeref, post.Status)
+				idmap[post.Status.ID] = post.Status
+				return
 
-				case *mastodon.UpdateEditEvent:
-					//Count the statuses
-					hc.stats.slock.Lock()
-					hc.stats.IncomingStatuses++
-					hc.stats.slock.Unlock()
-					if hc.isPaused {
-						currentPostRef := hc.homeref.ref
-						capturedPost := post
-						hc.actionBuffer = append(hc.actionBuffer, func() {
-							fmt.Println(hc.formatEdit(capturedPost.Status, currentPostRef))
-						})
-						justIncrementPostref(hc.homeref, post.Status)
-						idmap[post.Status.ID] = post.Status
-						return
-					}
-					printAndIncrementDetailed(hc.homeref, post.Status, hc.formatEdit)
+			case *mastodon.UpdateEditEvent:
+				//Count the statuses
+				hc.stats.slock.Lock()
+				hc.stats.IncomingStatuses++
+				hc.stats.slock.Unlock()
+				if hc.isPaused {
+					currentPostRef := hc.homeref.ref
+					capturedPost := post
+					hc.actionBuffer = append(hc.actionBuffer, func() {
+						fmt.Println(hc.formatEdit(capturedPost.Status, currentPostRef))
+					})
+					justIncrementPostref(hc.homeref, post.Status)
 					idmap[post.Status.ID] = post.Status
 					return
+				}
+				printAndIncrementDetailed(hc.homeref, post.Status, hc.formatEdit)
+				idmap[post.Status.ID] = post.Status
+				return
 
-				case *mastodon.DeleteEvent:
-					deleted, ok := idmap[post.ID]
-					//didn't have this in the cache
-					if !ok {
-						capturedID := post.ID
-						if hc.isPaused {
-							hc.actionBuffer = append(hc.actionBuffer, func() {
-								fmt.Printf("Deleted: ID %v\n", capturedID)
-							})
-						} else {
-							fmt.Printf("Deleted: ID %v\n", capturedID)
-						}
-						return
-					}
+			case *mastodon.DeleteEvent:
+				deleted, ok := idmap[post.ID]
+				//didn't have this in the cache
+				if !ok {
+					capturedID := post.ID
 					if hc.isPaused {
 						hc.actionBuffer = append(hc.actionBuffer, func() {
-							hc.printPostDetailed("", deleted, "Deleted:")
+							fmt.Printf("Deleted: ID %v\n", capturedID)
 						})
 					} else {
-						hc.printPostDetailed("", deleted, "Deleted:")
+						fmt.Printf("Deleted: ID %v\n", capturedID)
 					}
 					return
+				}
+				if hc.isPaused {
+					hc.actionBuffer = append(hc.actionBuffer, func() {
+						hc.printPostDetailed("", deleted, "Deleted:")
+					})
+				} else {
+					hc.printPostDetailed("", deleted, "Deleted:")
+				}
+				return
 
-				case *mastodon.NotificationEvent:
-					hc.updatePrompt()
-					if post.Notification.Status == nil {
-						if hc.isPaused {
-							hc.actionBuffer = append(hc.actionBuffer, func() {
-								hc.PrintReceivedNotification(post.Notification)
-							})
-						} else {
-							hc.PrintReceivedNotification(post.Notification)
-						}
-						return
-					}
+			case *mastodon.NotificationEvent:
+				hc.updatePrompt()
+				if post.Notification.Status == nil {
 					if hc.isPaused {
 						hc.actionBuffer = append(hc.actionBuffer, func() {
 							hc.PrintReceivedNotification(post.Notification)
@@ -452,20 +435,28 @@
 					} else {
 						hc.PrintReceivedNotification(post.Notification)
 					}
-					justIncrementPostref(hc.homeref, post.Notification.Status)
-				default:
-					// Catch any other unexpected event types.
-					unhandledEvent := event
-					if hc.isPaused {
-						hc.actionBuffer = append(hc.actionBuffer, func() {
-							fmt.Printf("Unhandled event: %T\n", unhandledEvent)
-						})
-					} else {
+					return
+				}
+				if hc.isPaused {
+					hc.actionBuffer = append(hc.actionBuffer, func() {
+						hc.PrintReceivedNotification(post.Notification)
+					})
+				} else {
+					hc.PrintReceivedNotification(post.Notification)
+				}
+				justIncrementPostref(hc.homeref, post.Notification.Status)
+			default:
+				// Catch any other unexpected event types.
+				unhandledEvent := event
+				if hc.isPaused {
+					hc.actionBuffer = append(hc.actionBuffer, func() {
 						fmt.Printf("Unhandled event: %T\n", unhandledEvent)
-					}
+					})
+				} else {
+					fmt.Printf("Unhandled event: %T\n", unhandledEvent)
 				}
-			}()
-		}
+			}
+		}()
 	}
 }
 
--- a/notifications.go
+++ b/notifications.go
@@ -5,7 +5,7 @@
 	"fmt"
 	"strings"
 
-	"codeberg.org/penny64/hellclient-go-mastodon"
+	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 )
 
 func (hc *Hellclient) GetUnreadNotifications() (notifications []*mastodon.Notification, err error) {
--- a/pages.go
+++ b/pages.go
@@ -6,7 +6,7 @@
 	"strings"
 	"sync"
 
-	"codeberg.org/penny64/hellclient-go-mastodon"
+	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 	"golang.org/x/term"
 )
 
@@ -43,13 +43,9 @@
 		getter.loaded = true
 	}
 	var statuses []*mastodon.Status
-	for _, post := range context.Ancestors {
-		statuses = append(statuses, post)
-	}
+	statuses = append(statuses, context.Ancestors...)
 	statuses = append(statuses, getter.target)
-	for _, post := range context.Descendants {
-		statuses = append(statuses, post)
-	}
+	statuses = append(statuses, context.Descendants...)
 
 	return statuses, err
 }
@@ -134,7 +130,7 @@
 	if err != nil {
 		fmt.Printf("Couldn't load status page: %s\n", err)
 	}
-	for i, _ := range statuses {
+	for i := range statuses {
 		item := makePageItem(statusData.hc.renderAndIncrement(statusData.hc.ctxref, statuses[i]) + "\n")
 		itemArray = append(itemArray, item)
 	}
@@ -158,7 +154,7 @@
 	}
 	noticeArray := noticeData.hc.RenderNotificationsArray(notices)
 	var itemArray []PageItem
-	for i, _ := range noticeArray {
+	for i := range noticeArray {
 		item := makePageItem(noticeArray[i] + "\n")
 		itemArray = append(itemArray, item)
 	}
@@ -168,7 +164,7 @@
 
 func findIndex(height int, items []PageItem) (index int, bumped bool) {
 	linecount := 5
-	for i, _ := range items {
+	for i := range items {
 		linecount = linecount + items[i].lines
 		if i != 0 && linecount > height {
 			return index, true
@@ -198,7 +194,6 @@
 	newindex, _ := findIndex(windowheight, items)
 	page.indexend = page.index
 	page.index = page.index - newindex
-	return
 }
 
 func (page *Page) findIndexEnd() {
@@ -209,7 +204,7 @@
 	}
 	page.indexend = page.index
 	var items []PageItem
-	newend := page.indexend
+	var newend int
 	var bumped bool
 	if page.itembuffer == nil {
 		page.Buffer()
@@ -233,7 +228,6 @@
 			}
 		}
 	}
-	return
 }
 
 func (page *Page) Buffer() {
@@ -253,7 +247,7 @@
 	if !page.disablereverse {
 		items = reverseArray(items)
 	}
-	for i, _ := range items {
+	for i := range items {
 		sb.WriteString(items[i].itemtext)
 	}
 	sb.WriteString(page.pageTitle())
--- a/references.go
+++ b/references.go
@@ -4,7 +4,7 @@
 	"fmt"
 	"strings"
 
-	"codeberg.org/penny64/hellclient-go-mastodon"
+	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 )
 
 var charSequence = []rune{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
--- a/status.go
+++ b/status.go
@@ -4,7 +4,7 @@
 	"context"
 	"fmt"
 
-	"codeberg.org/penny64/hellclient-go-mastodon"
+	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 )
 
 func (hc *Hellclient) GetStatusesSince(ID mastodon.ID, GetTimeline func(ctx context.Context, pg *mastodon.Pagination) ([]*mastodon.Status, error)) ([]*mastodon.Status, error) {
--