mirror of https://github.com/velour/catbase.git
newsbid: sort scores by score
This commit is contained in:
parent
81cc0dc55b
commit
e2352a214b
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue