newsbid: sort scores by score

This commit is contained in:
Chris Sexton 2020-03-11 12:25:34 -04:00 committed by Chris Sexton
parent 81cc0dc55b
commit e2352a214b
2 changed files with 9 additions and 2 deletions

View File

@ -73,6 +73,7 @@ func (p *NewsBid) message(conn bot.Connector, k bot.Kind, message msg.Message, a
return true
}
out := "NGate balances:\n"
sort.Sort(bals)
for _, b := range bals {
out += fmt.Sprintf("%s has a total score of %d with %d left to bid this session\n", b.User, b.Score, b.Balance)
}

View File

@ -57,6 +57,12 @@ type Balance struct {
Score int
}
type Balances []Balance
func (b Balances) Len() int { return len(b) }
func (b Balances) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b Balances) Less(i, j int) bool { return b[i].Score < b[j].Score }
type WeeklyResult struct {
User string
Won int
@ -274,8 +280,8 @@ func (w *Webshit) GetAllBids() ([]Bid, error) {
return bids, nil
}
func (w *Webshit) GetAllBalances() ([]Balance, error) {
var balances []Balance
func (w *Webshit) GetAllBalances() (Balances, error) {
var balances Balances
err := w.db.Select(&balances, `select * from webshit_balances`)
if err != nil {
return nil, err