auto-report alt prints - closes lichess-org/tavern#50

3wc-trophy
Thibault Duplessis 2021-03-11 19:36:37 +01:00
parent ce82784776
commit 15070c9607
5 changed files with 24 additions and 15 deletions

View File

@ -297,8 +297,8 @@ final class Auth(
_ ?? { hash =>
!me.lame ?? (for {
otherIds <- api.recentUserIdsByFingerHash(hash).map(_.filter(me.id.!=))
_ <- (otherIds.sizeIs >= 2) ?? env.user.repo.countEngines(otherIds).flatMap {
case nb if nb >= 2 && nb >= otherIds.size / 2 => env.report.api.autoCheatPrintReport(me.id)
_ <- (otherIds.sizeIs >= 2) ?? env.user.repo.countLameOrTroll(otherIds).flatMap {
case nb if nb >= 2 && nb >= otherIds.size / 2 => env.report.api.autoAltPrintReport(me.id)
case _ => funit
}
} yield ())

View File

@ -12,7 +12,10 @@ sealed trait Reason {
object Reason {
case object Cheat extends Reason
case object CheatPrint extends Reason {
case object CheatPrint extends Reason { // BC, replaced with AltPrint
override def name = "Print"
}
case object AltPrint extends Reason {
override def name = "Print"
}
case object Comm extends Reason {
@ -22,9 +25,7 @@ object Reason {
case object Other extends Reason
case object Playbans extends Reason
// val communication: Set[Reason] = Set(Insult, Troll, CommFlag, Other)
val all = List(Cheat, CheatPrint, Comm, Boost, Other)
val all = List(Cheat, AltPrint, Comm, Boost, Other, CheatPrint)
val keys = all map (_.key)
val byKey = all map { v =>
(v.key, v)
@ -39,7 +40,7 @@ object Reason {
def isCheat = reason == Cheat
def isOther = reason == Other
def isPrint = reason == CheatPrint
def isPrint = reason == AltPrint || reason == CheatPrint
def isComm = reason == Comm
def isBoost = reason == Boost
def isPlaybans = reason == Playbans
@ -49,7 +50,7 @@ object Reason {
import lila.security.Granter
reason match {
case Cheat => Granter.is(_.MarkEngine)(mod)
case CheatPrint => Granter.is(_.Admin)(mod)
case AltPrint | CheatPrint => Granter.is(_.Admin)(mod)
case Comm => Granter.is(_.Shadowban)(mod)
case Boost | Playbans | Other => Granter.is(_.MarkBooster)(mod)
}

View File

@ -121,11 +121,11 @@ final class ReportApi(
def getSuspect(username: String): Fu[Option[Suspect]] =
userRepo named username dmap2 Suspect.apply
def autoCheatPrintReport(userId: String): Funit =
def autoAltPrintReport(userId: String): Funit =
coll.exists(
$doc(
"user" -> userId,
"reason" -> Reason.CheatPrint.key
"reason" -> Reason.AltPrint.key
)
) flatMap {
case true => funit // only report once
@ -136,8 +136,8 @@ final class ReportApi(
Candidate(
reporter = reporter,
suspect = suspect,
reason = Reason.CheatPrint,
text = "Shares print with known cheaters"
reason = Reason.AltPrint,
text = "Shares print with suspicious accounts"
)
)
case _ => funit

View File

@ -33,7 +33,7 @@ object Room {
def apply(reason: Reason): Room =
reason match {
case Reason.Cheat => Cheat
case Reason.CheatPrint => Print
case Reason.AltPrint | Reason.CheatPrint => Print
case Reason.Comm => Comm
case Reason.Boost | Reason.Playbans | Reason.Other => Other
}
@ -41,7 +41,7 @@ object Room {
def toReasons(room: Room): Set[Reason] =
room match {
case Cheat => Set(Reason.Cheat)
case Print => Set(Reason.CheatPrint)
case Print => Set(Reason.AltPrint)
case Comm => Set(Reason.Comm)
case Other => Set(Reason.Boost, Reason.Other)
case Xfiles => Set.empty

View File

@ -255,9 +255,14 @@ final class UserRepo(val coll: Coll)(implicit ec: scala.concurrent.ExecutionCont
val disabledSelect = $doc(F.enabled -> false)
def markSelect(mark: UserMark)(v: Boolean): Bdoc =
if (v) $doc(F.marks -> mark.key)
else F.marks $ne (mark.key)
else F.marks $ne mark.key
def engineSelect = markSelect(UserMark.Engine) _
def trollSelect = markSelect(UserMark.Troll) _
val lameOrTroll = $or(
$doc(F.marks -> UserMark.Engine.key),
$doc(F.marks -> UserMark.Boost.key),
$doc(F.marks -> UserMark.Troll.key)
)
def stablePerfSelect(perf: String) =
$doc(s"perfs.$perf.gl.d" -> $lt(lila.rating.Glicko.provisionalDeviation))
val patronSelect = $doc(s"${F.plan}.active" -> true)
@ -597,6 +602,9 @@ final class UserRepo(val coll: Coll)(implicit ec: scala.concurrent.ExecutionCont
def countEngines(userIds: List[User.ID]): Fu[Int] =
coll.secondaryPreferred.countSel($inIds(userIds) ++ engineSelect(true))
def countLameOrTroll(userIds: List[User.ID]): Fu[Int] =
coll.secondaryPreferred.countSel($inIds(userIds) ++ lameOrTroll)
def containsEngine(userIds: List[User.ID]): Fu[Boolean] =
coll.exists($inIds(userIds) ++ engineSelect(true))