rewrite sandbag/boosting auto handlers WIP
parent
b46cde1850
commit
fc89094e6c
|
@ -148,8 +148,8 @@ final class MsgApi(
|
|||
}
|
||||
}
|
||||
|
||||
def postPreset(dest: User, preset: MsgPreset): Fu[PostResult] =
|
||||
systemPost(dest.id, preset.text)
|
||||
def postPreset(destId: User.ID, preset: MsgPreset): Fu[PostResult] =
|
||||
systemPost(destId, preset.text)
|
||||
|
||||
def systemPost(destId: User.ID, text: String) =
|
||||
post(User.lichessId, destId, text, multi = true)
|
||||
|
|
|
@ -42,7 +42,7 @@ final class PlaybanApi(
|
|||
}
|
||||
|
||||
private def IfBlameable[A: ornicar.scalalib.Zero](game: Game)(f: => Fu[A]): Fu[A] =
|
||||
Uptime.startedSinceMinutes(10) ?? {
|
||||
Uptime.startedSinceMinutes(0) ?? {
|
||||
blameable(game) flatMap { _ ?? f }
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,7 @@ final class PlaybanApi(
|
|||
loser = game.player(!w)
|
||||
loserId <- loser.userId
|
||||
} yield {
|
||||
println(status(Status))
|
||||
if (Status.NoStart is status)
|
||||
save(Outcome.NoPlay, loserId, RageSit.Reset) >>- feedback.noStart(Pov(game, !w))
|
||||
else
|
||||
|
@ -245,18 +246,13 @@ final class PlaybanApi(
|
|||
rageSitCache.put(record.userId, fuccess(record.rageSit))
|
||||
(delta < 0) ?? {
|
||||
if (record.rageSit.isTerrible) funit
|
||||
else if (record.rageSit.isVeryBad)
|
||||
userRepo byId record.userId flatMap {
|
||||
_ ?? { u =>
|
||||
lila.log("ragesit").info(s"https://lichess.org/@/${u.username} ${record.rageSit.counterView}")
|
||||
Bus.publish(
|
||||
lila.hub.actorApi.mod.AutoWarning(u.id, MsgPreset.sittingAuto.name),
|
||||
"autoWarning"
|
||||
)
|
||||
messenger.postPreset(u, MsgPreset.sittingAuto).void
|
||||
}
|
||||
}
|
||||
else funit
|
||||
else if (record.rageSit.isVeryBad) {
|
||||
Bus.publish(
|
||||
lila.hub.actorApi.mod.AutoWarning(record.userId, MsgPreset.sittingAuto.name),
|
||||
"autoWarning"
|
||||
)
|
||||
messenger.postPreset(record.userId, MsgPreset.sittingAuto).void
|
||||
} else funit
|
||||
}
|
||||
case _ => funit
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ final private class PlaybanFeedback(
|
|||
def sandbag(pov: Pov): Unit = tell(pov, s"Warning, {user}. Losing games on purpose will result in a ban.")
|
||||
|
||||
private def tell(pov: Pov, template: String): Unit =
|
||||
pov.player.userId foreach { userId =>
|
||||
lightUser(userId) foreach { light =>
|
||||
val message = template.replace("{user}", light.fold(userId)(_.name))
|
||||
pov.player.userId.pp foreach { userId =>
|
||||
lightUser(userId).thenPp foreach { light =>
|
||||
val message = template.replace("{user}", light.fold(userId)(_.name)).pp
|
||||
chatApi.userChat.volatile(Chat.Id(pov.gameId), message, _.Round)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,45 +16,46 @@ final private class SandbagWatch(
|
|||
|
||||
import SandbagWatch._
|
||||
|
||||
private val onceEvery = lila.memo.OnceEvery(1 hour)
|
||||
private val messageOnceEvery = lila.memo.OnceEvery(1 hour)
|
||||
|
||||
// returns true if one of the players has 2 or more sandbag outcomes
|
||||
def apply(game: Game, loser: Color): Fu[Boolean] =
|
||||
(game.rated && !game.fromApi) ?? {
|
||||
game.userIds
|
||||
.map { userId =>
|
||||
(records getIfPresent userId, outcomeOf(game, loser, userId)) match {
|
||||
case (None, Good) => funit
|
||||
case (Some(record), Good) => updateRecord(userId, record + Good, game)
|
||||
case (record, outcome) => updateRecord(userId, (record | emptyRecord) + outcome, game)
|
||||
(records getIfPresent userId, outcomeOf(game, loser, userId).pp(userId)) match {
|
||||
case (None, Good) => fuccess(0)
|
||||
case (Some(record), Good) => updateRecord(userId, record + Good, game) inject 0
|
||||
case (record, outcome) =>
|
||||
val newRecord = (record | emptyRecord) + outcome
|
||||
updateRecord(userId, newRecord, game) inject {
|
||||
(outcome == Sandbag) ?? newRecord.count(Sandbag)
|
||||
}
|
||||
}
|
||||
}
|
||||
.sequenceFu
|
||||
.void inject isSandbag(game)
|
||||
.thenPp
|
||||
.dmap { _.exists(_ > 0) }
|
||||
}
|
||||
|
||||
private def sendMessage(userId: User.ID, preset: MsgPreset): Funit =
|
||||
onceEvery(userId) ?? {
|
||||
userRepo byId userId flatMap {
|
||||
_ ?? { u =>
|
||||
lila.common.Bus
|
||||
.publish(lila.hub.actorApi.mod.AutoWarning(u.id, preset.name), "autoWarning")
|
||||
messenger.postPreset(u, preset).void
|
||||
}
|
||||
}
|
||||
messageOnceEvery(userId) ?? {
|
||||
lila.common.Bus.publish(lila.hub.actorApi.mod.AutoWarning(userId, preset.name), "autoWarning")
|
||||
messenger.postPreset(userId, preset).void
|
||||
}
|
||||
|
||||
private def updateRecord(userId: User.ID, record: Record, game: Game): Funit =
|
||||
if (record.immaculate) fuccess(records invalidate userId)
|
||||
if (record.pp(userId).immaculate) fuccess(records invalidate userId)
|
||||
else {
|
||||
records.put(userId, record)
|
||||
if (record.latest has Sandbag) {
|
||||
if (record.count(Sandbag) == 3) sendMessage(userId, MsgPreset.sandbagAuto)
|
||||
if (record.count(Sandbag).pp("sandbag") == 3) sendMessage(userId, MsgPreset.sandbagAuto)
|
||||
else if (record.count(Sandbag) == 4) withWinnerAndLoser(game) { (winner, loser) =>
|
||||
fuccess { reporter ! lila.hub.actorApi.report.Sandbagger(winner, loser) }
|
||||
}
|
||||
else funit
|
||||
} else if (record.latest has Boost) {
|
||||
if (record.count(Boost) == 3) sendMessage(userId, MsgPreset.boostAuto)
|
||||
if (record.count(Boost).pp("boost") == 3) sendMessage(userId, MsgPreset.boostAuto)
|
||||
else if (record.count(Boost) == 4) withWinnerAndLoser(game) { (winner, loser) =>
|
||||
fuccess { reporter ! lila.hub.actorApi.report.Booster(winner, loser) }
|
||||
}
|
||||
|
@ -84,7 +85,7 @@ final private class SandbagWatch(
|
|||
private def isSandbag(game: Game): Boolean =
|
||||
game.playedTurns <= {
|
||||
if (game.variant == chess.variant.Atomic) 3
|
||||
else 6
|
||||
else 8
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -246,13 +246,13 @@ final class ReportApi(
|
|||
suspect = Suspect(winner),
|
||||
reason = Reason.Boost,
|
||||
text = s"Boosting: farms rating points from @${loser.username} ($loginsText)"
|
||||
)
|
||||
).pp
|
||||
)
|
||||
case _ => funit
|
||||
}
|
||||
|
||||
def autoSandbagReport(winnerId: User.ID, loserId: User.ID): Funit =
|
||||
userRepo.pair(winnerId, loserId) zip getLichessReporter flatMap {
|
||||
userRepo.pair(winnerId, loserId).thenPp zip getLichessReporter flatMap {
|
||||
case Some((winner, loser)) ~ reporter if !winner.lame && !loser.lame =>
|
||||
create(
|
||||
Candidate(
|
||||
|
@ -260,7 +260,7 @@ final class ReportApi(
|
|||
suspect = Suspect(loser),
|
||||
reason = Reason.Boost,
|
||||
text = s"Sandbagging: throws games to @${loser.username}"
|
||||
)
|
||||
).pp
|
||||
)
|
||||
case _ => funit
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue