newsbid: make the !bids command look nicer

This commit is contained in:
Chris Sexton 2019-12-22 09:00:31 -05:00 committed by Chris Sexton
parent 2625671ed6
commit 47c3def722
1 changed files with 8 additions and 2 deletions

View File

@ -48,10 +48,16 @@ func (p *NewsBid) message(conn bot.Connector, k bot.Kind, message msg.Message, a
p.bot.Send(conn, bot.Message, ch, "No bids to report.") p.bot.Send(conn, bot.Message, ch, "No bids to report.")
return true return true
} }
sort.Slice(bids, func(i, j int) bool { return bids[i].User < bids[j].User }) sort.Slice(bids, func(i, j int) bool {
if bids[i].User == bids[j].User {
return bids[i].Bid > bids[j].Bid
}
return bids[i].User < bids[j].User
})
out := "Bids:\n" out := "Bids:\n"
for _, b := range bids { for _, b := range bids {
out += fmt.Sprintf("%s bid %s on <%s|%s> \n", b.User, b.BidStr, b.URL, b.Title) hnURL := fmt.Sprintf("https://news.ycombinator.com/item?id=%d", b.HNID)
out += fmt.Sprintf("• %s bid %s <%s|%s> (<%s|Comments>)\n", b.User, b.BidStr, b.URL, b.Title, hnURL)
} }
p.bot.Send(conn, bot.Message, ch, out) p.bot.Send(conn, bot.Message, ch, out)
return true return true