-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
83 lines (66 loc) · 1.97 KB
/
utils.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
package manager
import (
"context"
"github.com/galexrt/fivenet/gen/go/proto/resources/centrum"
"github.com/galexrt/fivenet/pkg/grpc/auth/userinfo"
)
func (s *Manager) CheckIfUserIsDisponent(ctx context.Context, job string, userId int32) bool {
disponents, err := s.GetDisponents(ctx, job)
if err != nil {
return false
}
if len(disponents) == 0 {
return false
}
for i := 0; i < len(disponents); i++ {
if userId == disponents[i].UserId {
return true
}
}
return false
}
func (s *Manager) CheckIfUserIsPartOfDispatch(ctx context.Context, userInfo *userinfo.UserInfo, dsp *centrum.Dispatch, disponentOkay bool) bool {
// Check if user is a disponent
if disponentOkay && s.CheckIfUserIsDisponent(ctx, userInfo.Job, userInfo.UserId) {
return true
}
// Iterate over units of dispatch and check if the user is in one of the units
for i := 0; i < len(dsp.Units); i++ {
unit, err := s.GetUnit(ctx, dsp.Units[i].Unit.Job, dsp.Units[i].UnitId)
if unit == nil || err != nil {
continue
}
if s.CheckIfUserPartOfUnit(ctx, userInfo.Job, userInfo.UserId, unit, disponentOkay) {
return true
}
}
return false
}
func (s *Manager) CheckIfUserPartOfUnit(ctx context.Context, job string, userId int32, unit *centrum.Unit, disponentOkay bool) bool {
// Check if user is a disponent
if disponentOkay && s.CheckIfUserIsDisponent(ctx, job, userId) {
return true
}
for i := 0; i < len(unit.Users); i++ {
if (unit.Users[i].User != nil && unit.Users[i].User.UserId == userId) || unit.Users[i].UserId == userId {
return true
}
}
return false
}
func (s *Manager) CheckIfBotNeeded(ctx context.Context, job string) bool {
settings := s.GetSettings(ctx, job)
if settings.Mode == centrum.CentrumMode_CENTRUM_MODE_AUTO_ROUND_ROBIN {
return true
}
disponents, err := s.GetDisponents(ctx, job)
if err != nil {
return false
}
if len(disponents) == 0 {
if settings.FallbackMode == centrum.CentrumMode_CENTRUM_MODE_AUTO_ROUND_ROBIN {
return true
}
}
return false
}