This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand-admin-info.go
92 lines (75 loc) · 2.56 KB
/
command-admin-info.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"fmt"
)
const (
USERS_TOTAL_AND_STRAVA = "Users: %d (unique strava users: %d)"
USERS_TOTAL = "Users: %d"
USERS_UNLOCKED = "Unlocked users: %d"
TEAMS_TOTAL_AND_MONITORED = "Teams: %d (monitored: %d)"
TEAMS_TOTAL = "Teams: %d"
CLUBS_TOTAL = "Clubs: %d"
RATE_LIMITS_UNKNOWN = "Rate usage/limits are unknown - Strava API hasn't be called yet"
RATE_LIMITS = "Rate usage/limits at %s: 15-minute usage - %d/%d requests, day usage - %d/%d requests"
)
type AdminInfoCommand struct {
}
func (cmd *AdminInfoCommand) Name() string {
return "admin_info"
}
func (cmd *AdminInfoCommand) Execute(params []string, message *IncomingSlackMessage, executor *CommandExecutor) (string, error) {
checkResult, err := executor.checkFromAdmin(message)
if err != nil {
return "", err
}
if checkResult != "" {
return checkResult, nil
}
totalUsersCount, err := executor.repo.AccessDetails.Count()
if err != nil {
return "", err
}
stravaUsersCount, err := executor.repo.AccessDetails.CountStravaUsers()
if err != nil {
return "", err
}
unlockedUsersCount, err := executor.repo.UserDetails.CountUnlocked()
if err != nil {
return "", err
}
totalTeamsCount, err := executor.repo.AccessDetails.CountTeams()
if err != nil {
return "", err
}
monitoredTeamsCount, err := executor.repo.JobDetails.CountTeams()
if err != nil {
return "", err
}
clubsCount, err := executor.repo.JobDetails.CountClubs()
if err != nil {
return "", err
}
var usersCountStr string
if stravaUsersCount != totalUsersCount {
usersCountStr = fmt.Sprintf(USERS_TOTAL_AND_STRAVA, totalUsersCount, stravaUsersCount)
} else {
usersCountStr = fmt.Sprintf(USERS_TOTAL, totalUsersCount)
}
unlockedUsersCountStr := fmt.Sprintf(USERS_UNLOCKED, unlockedUsersCount)
var teamsCountStr string
if monitoredTeamsCount != totalTeamsCount {
teamsCountStr = fmt.Sprintf(TEAMS_TOTAL_AND_MONITORED, totalTeamsCount, monitoredTeamsCount)
} else {
teamsCountStr = fmt.Sprintf(TEAMS_TOTAL, totalTeamsCount)
}
clubsCountStr := fmt.Sprintf(CLUBS_TOTAL, clubsCount)
var rateLimitisStr string
requestTime, limitShort, limitLong, usageShort, usageLong := executor.strava.GetRateLimits()
if requestTime.IsZero() {
rateLimitisStr = RATE_LIMITS_UNKNOWN
} else {
rateLimitisStr = fmt.Sprintf(RATE_LIMITS,
requestTime.Format("02-Jan-06 15:04:05"), usageShort, limitShort, usageLong, limitLong)
}
return usersCountStr + "\n" + unlockedUsersCountStr + "\n" + teamsCountStr + "\n" + clubsCountStr + "\n\n" + rateLimitisStr, nil
}