runtime irwin thresholds settings - for lichess-org/talk#34

pull/6046/head
Thibault Duplessis 2020-02-16 09:26:16 -06:00
parent 24a9e3c756
commit c49c7b60bd
4 changed files with 43 additions and 14 deletions

View File

@ -10,7 +10,7 @@ final class Dev(env: Env) extends LilaController(env) {
private lazy val settingsList = List[lila.memo.SettingStore[_]](
env.security.ugcArmedSetting,
env.security.spamKeywordsSetting,
env.irwin.irwinModeSetting,
env.irwin.irwinThresholdsSetting,
env.explorer.indexFlowSetting,
env.report.scoreThresholdSetting,
env.report.slackScoreThresholdSetting,

View File

@ -22,11 +22,7 @@ final class Env(
private lazy val reportColl = db(CollName("irwin_report"))
lazy val irwinModeSetting = settingStore[String](
"irwinMode",
default = "none",
text = "Allow Irwin to: [mark|report|none]".some
)
lazy val irwinThresholdsSetting = IrwinThresholds makeSetting settingStore
lazy val stream = wire[IrwinStream]

View File

@ -21,12 +21,9 @@ final class IrwinApi(
modApi: lila.mod.ModApi,
reportApi: lila.report.ReportApi,
notifyApi: lila.notify.NotifyApi,
mode: lila.memo.SettingStore[String]
thresholds: lila.memo.SettingStore[IrwinThresholds]
)(implicit ec: scala.concurrent.ExecutionContext) {
val reportThreshold = 88
val markThreshold = 95
import BSONHandlers._
def dashboard: Fu[IrwinDashboard] =
@ -34,12 +31,11 @@ final class IrwinApi(
object reports {
def insert(report: IrwinReport) = (mode.get() != "none") ?? {
def insert(report: IrwinReport) =
reportColl.update.one($id(report._id), report, upsert = true) >>
markOrReport(report) >>
notification(report) >>-
lila.mon.mod.irwin.ownerReport(report.owner).increment()
}
def get(user: User): Fu[Option[IrwinReport]] =
reportColl.ext.find($id(user.id)).one[IrwinReport]
@ -59,10 +55,10 @@ final class IrwinApi(
userRepo byId suspectId orFail s"suspect $suspectId not found" dmap Suspect.apply
private def markOrReport(report: IrwinReport): Funit =
if (report.activation >= markThreshold && mode.get() == "mark")
if (report.activation >= thresholds.get().mark)
modApi.autoMark(report.suspectId, ModId.irwin) >>-
lila.mon.mod.irwin.mark.increment()
else if (report.activation >= reportThreshold && mode.get() != "none") for {
else if (report.activation >= thresholds.get().report) for {
suspect <- getSuspect(report.suspectId.value)
irwin <- userRepo byId "irwin" orFail s"Irwin user not found" dmap Mod.apply
_ <- reportApi.create(

View File

@ -0,0 +1,37 @@
package lila.irwin
import lila.memo.SettingStore.{ Formable, StringReader }
import play.api.data.Form
import play.api.data.Forms.{ single, text }
case class IrwinThresholds(report: Int, mark: Int)
private object IrwinThresholds {
val defaultThresholds = IrwinThresholds(88, 95)
val thresholdsIso = lila.common.Iso[String, IrwinThresholds](
str => {
str.split(',').map(_.trim) match {
case Array(rs, ms) =>
for {
report <- rs.toIntOption
mark <- ms.toIntOption
} yield IrwinThresholds(report, mark)
case _ => none
}
} | defaultThresholds,
t => s"${t.report}, ${t.mark}"
)
implicit val thresholdsBsonHandler = lila.db.dsl.isoHandler(thresholdsIso)
implicit val thresholdsStringReader = StringReader.fromIso(thresholdsIso)
implicit val thresholdsFormable =
new Formable[IrwinThresholds](t => Form(single("v" -> text)) fill thresholdsIso.to(t))
def makeSetting(store: lila.memo.SettingStore.Builder) =
store[IrwinThresholds](
"irwinThresholds",
default = defaultThresholds,
text = "Irwin report and mark thresholds, separated with a comma. Set to 101 to disable.".some
)
}