-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Env.scala
155 lines (134 loc) · 4.92 KB
/
Env.scala
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package lila.mod
import akka.actor._
import com.typesafe.config.Config
import lila.security.{ Firewall, UserSpy }
final class Env(
config: Config,
db: lila.db.Env,
hub: lila.hub.Env,
system: ActorSystem,
scheduler: lila.common.Scheduler,
firewall: Firewall,
reportApi: lila.report.ReportApi,
lightUserApi: lila.user.LightUserApi,
userSpy: String => Fu[UserSpy],
securityApi: lila.security.SecurityApi,
tournamentApi: lila.tournament.TournamentApi,
simulEnv: lila.simul.Env,
chatApi: lila.chat.ChatApi,
notifyApi: lila.notify.NotifyApi,
historyApi: lila.history.HistoryApi,
rankingApi: lila.user.RankingApi,
relationApi: lila.relation.RelationApi,
noteApi: lila.user.NoteApi,
userJson: lila.user.JsonView,
asyncCache: lila.memo.AsyncCache.Builder,
emailValidator: lila.security.EmailAddressValidator
) {
private object settings {
val CollectionPlayerAssessment = config getString "collection.player_assessment"
val CollectionBoosting = config getString "collection.boosting"
val CollectionModlog = config getString "collection.modlog"
val CollectionGamingHistory = config getString "collection.gaming_history"
val ActorName = config getString "actor.name"
val NbGamesToMark = config getInt "boosting.nb_games_to_mark"
val RatioGamesToMark = config getDouble "boosting.ratio_games_to_mark"
}
import settings._
val ApiKey = config getString "api.key"
private[mod] lazy val logColl = db(CollectionModlog)
lazy val logApi = new ModlogApi(logColl)
private lazy val notifier = new ModNotifier(notifyApi, reportApi)
private lazy val ratingRefund = new RatingRefund(
scheduler = scheduler,
notifier = notifier,
historyApi = historyApi,
rankingApi = rankingApi,
wasUnengined = logApi.wasUnengined
)
lazy val api = new ModApi(
logApi = logApi,
userSpy = userSpy,
firewall = firewall,
reporter = hub.actor.report,
reportApi = reportApi,
lightUserApi = lightUserApi,
notifier = notifier,
refunder = ratingRefund,
lilaBus = system.lilaBus
)
private lazy val boosting = new BoostingApi(
modApi = api,
collBoosting = db(CollectionBoosting),
nbGamesToMark = NbGamesToMark,
ratioGamesToMark = RatioGamesToMark
)
lazy val assessApi = new AssessApi(
collAssessments = db(CollectionPlayerAssessment),
logApi = logApi,
modApi = api,
reporter = hub.actor.report,
fishnet = hub.actor.fishnet,
userIdsSharingIp = securityApi.userIdsSharingIp
)
lazy val gamify = new Gamify(
logColl = logColl,
reportApi = reportApi,
asyncCache = asyncCache,
historyColl = db(CollectionGamingHistory)
)
lazy val publicChat = new PublicChat(chatApi, tournamentApi, simulEnv)
lazy val search = new UserSearch(
securityApi = securityApi,
emailValidator = emailValidator
)
lazy val jsonView = new JsonView(
assessApi = assessApi,
relationApi = relationApi,
userJson = userJson
)
lazy val userHistory = new UserHistory(
logApi = logApi,
reportApi = reportApi
)
lazy val inquiryApi = new InquiryApi(reportApi, noteApi, logApi)
// api actor
system.lilaBus.subscribe(system.actorOf(Props(new Actor {
def receive = {
case lila.analyse.actorApi.AnalysisReady(game, analysis) =>
assessApi.onAnalysisReady(game, analysis)
case lila.game.actorApi.FinishGame(game, whiteUserOption, blackUserOption) if !game.aborted =>
(whiteUserOption |@| blackUserOption) apply {
case (whiteUser, blackUser) => boosting.check(game, whiteUser, blackUser) >>
assessApi.onGameReady(game, whiteUser, blackUser)
}
case lila.hub.actorApi.mod.ChatTimeout(mod, user, reason) => logApi.chatTimeout(mod, user, reason)
case lila.hub.actorApi.mod.CheatDetected(userId, gameId) => logApi.cheatDetected(userId, gameId)
}
}), name = ActorName), 'finishGame, 'analysisReady)
}
object Env {
lazy val current = "mod" boot new Env(
config = lila.common.PlayApp loadConfig "mod",
db = lila.db.Env.current,
hub = lila.hub.Env.current,
system = lila.common.PlayApp.system,
scheduler = lila.common.PlayApp.scheduler,
firewall = lila.security.Env.current.firewall,
reportApi = lila.report.Env.current.api,
userSpy = lila.security.Env.current.userSpy,
lightUserApi = lila.user.Env.current.lightUserApi,
securityApi = lila.security.Env.current.api,
tournamentApi = lila.tournament.Env.current.api,
simulEnv = lila.simul.Env.current,
chatApi = lila.chat.Env.current.api,
notifyApi = lila.notify.Env.current.api,
historyApi = lila.history.Env.current.api,
rankingApi = lila.user.Env.current.rankingApi,
relationApi = lila.relation.Env.current.api,
noteApi = lila.user.Env.current.noteApi,
userJson = lila.user.Env.current.jsonView,
asyncCache = lila.memo.Env.current.asyncCache,
emailValidator = lila.security.Env.current.emailAddressValidator
)
}