/
shownewbie.go
43 lines (39 loc) · 1 KB
/
shownewbie.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"context"
"fmt"
"sort"
"github.com/johansundell/cocapi"
)
func init() {
key := commandFunc{"!show newbie", "To see our newest members and their donations", "", categoryAdmin}
lockMap.Lock()
defer lockMap.Unlock()
botFuncs[key] = func(ctx context.Context, command string) (string, error) {
if key.command == command {
list, _ := cocClient.GetMembers(myClanTag)
players := []cocapi.Player{}
for _, v := range list.Items {
if v.Role == "member" {
if p, err := cocClient.GetPlayerInfo(v.Tag); err == nil {
players = append(players, p)
}
}
}
sort.Slice(players, func(i, j int) bool { return players[i].Donations > players[j].Donations })
msg := ""
for _, v := range players {
msg += fmt.Sprintf("%d %s th%d total hero lvl %d\n", v.Donations, v.Name, v.TownHallLevel, getHeroLvl(v))
}
return msg, nil
}
return "", nil
}
}
func getHeroLvl(p cocapi.Player) int {
tot := 0
for _, v := range p.Heroes {
tot += v.Level
}
return tot
}