accept clarkey's bot JSON input - closes #2341
This commit is contained in:
parent
b29c741aaf
commit
c0a2fee3a4
|
@ -233,15 +233,21 @@ object User extends LilaController {
|
|||
}
|
||||
}
|
||||
|
||||
def writeClarkeyBotNote(username: String) = Open { implicit ctx =>
|
||||
private case class ClarkeyBot(result: Boolean, reason: String)
|
||||
private implicit val clarkeyBotReads = Json.reads[ClarkeyBot]
|
||||
|
||||
def writeClarkeyBotNote(username: String) = OpenBody(parse.json) { implicit ctx =>
|
||||
Mod.ModExternalBot {
|
||||
OptionFuResult(UserRepo named username) { user =>
|
||||
UserRepo.lichess.flatten("Missing lichess user") flatMap { lichess =>
|
||||
val decision = ~getInt("v") == 1
|
||||
val text =
|
||||
if (decision) "Clarkey's bot would mark as engine."
|
||||
else "Clarkey's bot doesn't know whether to mark as engine or not."
|
||||
env.noteApi.write(user, text, lichess, true) inject Ok
|
||||
ctx.body.body.validate[ClarkeyBot].fold(
|
||||
err => fuccess(BadRequest(err.toString)),
|
||||
data => {
|
||||
val text =
|
||||
if (data.result) s"Clarkey's bot would mark as engine: ${data.reason}"
|
||||
else s"Clarkey's bot is indecise: ${data.reason}"
|
||||
env.noteApi.write(user, text, lichess, true) inject Ok
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue