polls in embeds
This commit is contained in:
parent
8042c65ce3
commit
33db7b46cb
@ -1,10 +1,26 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import strutils, strformat, options, json, sequtils, times
|
||||
import strutils, strformat, options, json, sequtils, times, math
|
||||
import ".."/[types, formatters, utils]
|
||||
|
||||
proc formatTweetForMastoAPI*(tweet: Tweet, cfg: Config, prefs: Prefs): string =
|
||||
var content = replaceUrls(tweet.text, prefs)
|
||||
|
||||
if tweet.poll.isSome():
|
||||
let poll = get(tweet.poll)
|
||||
content &= "\n<blockquote>"
|
||||
for i in 0 ..< poll.options.len:
|
||||
let
|
||||
leader = if poll.leader == i: " leader" else: ""
|
||||
val = poll.values[i]
|
||||
perc = if val > 0: val / poll.votes * 100 else: 0
|
||||
percStr = (&"{perc:>3.0f}").strip(chars={'.'}) & '%'
|
||||
barLen = round((perc / 100) * 32).int
|
||||
bar = repeat("█", barLen)
|
||||
notBar = repeat(" ", 32 - barLen)
|
||||
content &= &"<b>{poll.options[i]}</b> ({val}, {percStr})\n<code>{bar}{notBar}</code>\n"
|
||||
|
||||
content &= &"\n{insertSep($poll.votes, ',')} votes • {poll.status}</blockquote>"
|
||||
|
||||
if tweet.quote.isSome():
|
||||
let
|
||||
quote = get(tweet.quote)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user