ref: 5b66b4096e7b1cdb74580da41597d69fb93123a1
parent: 765cdf06a02ff221319e36ac6778c7adaec666f1
author: penny <penny@limitedideas.org>
date: Wed Nov 12 14:37:39 EST 2025
better poll rendering, /vote command
--- a/commands.go
+++ b/commands.go
@@ -1287,6 +1287,38 @@
return cmd
}
+func (hc *Hellclient) votecmd() cmder {+ cmd := &basiccmd{}+ cmd.hc = hc
+ cmd.bname = "vote"
+ cmd.bflags = status | templater
+ cmd.doer = func(data *cmddata) string {+ if data.status.Poll == nil {+ return "Status does not contain a poll.\n"
+ }
+ votes := strings.Fields(data.content)
+ var voteints []int
+ for _, vote := range votes {+ voter := int(rune(vote[0]))
+ voter = voter - 97
+ voteints = append(voteints, voter)
+ }
+ var poll *mastodon.Poll
+ var err error
+ votefunc := func() {+ poll, err = hc.client.PollVote(context.Background(), data.status.Poll.ID, voteints...)
+ }
+ hc.dispatchAnon(votefunc).Wait()
+ if err != nil {+ return fmt.Sprintf("Err: %s\n", err)+ }
+ data.status.Poll = poll
+ line, _ := data.templater.render("$standard_status")+ 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 {@@ -1340,6 +1372,7 @@
hc.followcmd(),
hc.filtercmd("fpost", true),hc.examinecmd(),
+ hc.votecmd(),
}
return cmdarray
--- a/help.go
+++ b/help.go
@@ -17,6 +17,7 @@
/help Show this help message.
/reply <index> content Reply to status by index.
/like <index> Favorite status by index.
+ /vote <index> opt [opt..] Vote for poll option(s).
/unlike <index> Unfavorite status by index.
/thread <index> View thread the indexed status is part of.
/cat <index> Output a status with details (liker, replies, etc).
--- a/renderer.go
+++ b/renderer.go
@@ -230,9 +230,12 @@
var sb strings.Builder
sb.WriteString("\n")total := poll.status.Poll.VotesCount
+ countstr := fmt.Sprintf("%v votes.\n", total)+ if total == 0 { total = 1 }+ index := "a"
for _, item := range poll.status.Poll.Options {- sb.WriteString(item.Title)
- sb.WriteString("\n")+ sb.WriteString(fmt.Sprintf("%s) %s\n", index, item.Title))+ index = IncrementString(index)
percent := math.Round(float64(item.VotesCount) / float64(total) * 100)
percentBar := "░░░░░░░░░░"
percentBy10 := int(math.Round(percent/10))
@@ -239,6 +242,7 @@
percentBar = strings.Replace(percentBar, "░", "▓", percentBy10)
sb.WriteString(fmt.Sprintf("%s %v%%\n", percentBar, percent))}
+ sb.WriteString(countstr)
return sb.String()
}
return ""
--
⑨