Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fancy bots #17007

Draft
wants to merge 450 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
450 commits
Select commit Hold shift + click to select a range
4fc0b4f
try pre-push again
schlawg Jul 16, 2024
106a830
pre-merge
schlawg Jul 17, 2024
069c14c
apply allan joseph ci build fix
schlawg Jul 17, 2024
b964fa5
wip
schlawg Jul 21, 2024
81051be
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jul 21, 2024
830cb6c
bot editor fixup
schlawg Jul 22, 2024
29bd788
add export study to libot
schlawg Jul 22, 2024
0ab17e2
gah
schlawg Jul 26, 2024
dc8dfa9
wip
schlawg Jul 26, 2024
4bc72d1
mobile
schlawg Jul 28, 2024
2844a5b
bot & asset crud for bot dev
schlawg Jul 29, 2024
f42bb9c
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jul 29, 2024
c0caed9
wip
schlawg Aug 1, 2024
4a8de4f
gah
schlawg Aug 2, 2024
d274168
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 2, 2024
b5da6bb
ui fuckery
schlawg Aug 2, 2024
e2925c1
gah
schlawg Aug 5, 2024
d66d35c
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 5, 2024
6a25e87
gah
schlawg Aug 7, 2024
e58fe6e
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 7, 2024
a115ba5
wip
schlawg Aug 13, 2024
3af006e
merge
schlawg Aug 13, 2024
244676c
move isolatedDeclarations to tsconfig.base.json, and clean up all the…
schlawg Aug 13, 2024
73e9e52
remove accidental files
schlawg Aug 13, 2024
4d46b16
wip
schlawg Aug 16, 2024
029fd25
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 16, 2024
14cc315
just need history dialog and we ready
schlawg Aug 17, 2024
69a2151
gah
schlawg Aug 19, 2024
7758ebe
gah
schlawg Aug 19, 2024
5e6e972
private play branch for testy
schlawg Aug 19, 2024
db8e8ca
remove cruft
schlawg Aug 19, 2024
d6c1e51
gah
schlawg Aug 19, 2024
953c92c
fix bin/deploy
schlawg Aug 19, 2024
0ab238e
gah
schlawg Aug 19, 2024
fcb8b41
moar bin/deploy
schlawg Aug 19, 2024
c6dd3fc
moar bin/deploy
schlawg Aug 19, 2024
ba76393
remove http request to self
schlawg Aug 19, 2024
f03409f
sanity check
schlawg Aug 19, 2024
b8b85c8
fix bin/deploy again
schlawg Aug 19, 2024
139cc1f
round/ctrl.ts better handles clock changes
schlawg Aug 20, 2024
63840c1
isolatedDeclarations related tweaks. also preload opening books and s…
schlawg Aug 21, 2024
39a4ada
murge
schlawg Aug 21, 2024
b6fe651
refacterz and add stuff i realized we need while making video
schlawg Aug 24, 2024
9894b3c
get rid of outdated build cruft
schlawg Aug 24, 2024
fcfbcf5
for video
schlawg Aug 24, 2024
85d6614
fix zerofish link
schlawg Aug 24, 2024
b08b93b
murge new purtier
schlawg Aug 24, 2024
d44a727
comment out button in gui
schlawg Aug 24, 2024
e236388
fix bugs found making video
schlawg Aug 25, 2024
1c8bdd0
fix style issue
schlawg Aug 25, 2024
b73cf67
push labels out to right on lhs card spreads
schlawg Aug 28, 2024
6d10c6d
handOfCards ugly right now, will fix after video
schlawg Aug 28, 2024
2edfe01
murge
schlawg Aug 28, 2024
f17de0d
minor fixes to cards & new bot dialog
schlawg Aug 29, 2024
2f17bda
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 29, 2024
0a00071
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Aug 30, 2024
7190b3c
take eslint update from ui-assorted-improvements
schlawg Aug 30, 2024
d0fbc61
murge
schlawg Sep 2, 2024
38bb375
murge
schlawg Sep 5, 2024
bc8c1da
fix lint
schlawg Sep 5, 2024
2a82881
gah
schlawg Sep 5, 2024
11c4d99
murge
schlawg Sep 12, 2024
2ccbb62
add boteditor permission
schlawg Sep 12, 2024
cbb1929
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Sep 12, 2024
029ebf5
eslint
schlawg Sep 12, 2024
5d6d430
fix iterator error due to CI typings mismatch
schlawg Sep 12, 2024
cce0d12
murge
schlawg Sep 13, 2024
e3f4f6c
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Sep 13, 2024
cc300eb
merge from master
schlawg Sep 16, 2024
bdbba68
murge
schlawg Sep 18, 2024
a4de350
merge socket-test updates
schlawg Sep 18, 2024
9bd632e
Merge branch 'scala-esm-interop-cleanup' into local-play
schlawg Sep 18, 2024
67df2c7
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Sep 18, 2024
c22bd17
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Sep 19, 2024
39505c7
separate ask out from unrelated stuff in canary
schlawg Sep 25, 2024
42d9247
murge and also let everyone play with bot dev, only require BotEditor…
schlawg Sep 28, 2024
4c161c4
updates from master
schlawg Oct 5, 2024
498c84d
prettier
schlawg Oct 5, 2024
23d44c3
fix time controls on prototype setup dialog
schlawg Oct 7, 2024
c062914
no move confirm on private play
schlawg Oct 7, 2024
ac4979c
preload images on slow connections
schlawg Oct 8, 2024
6ea18eb
properly wait on preloaded images
schlawg Oct 8, 2024
170197f
rename selector -> switch
schlawg Oct 8, 2024
da3429d
fix animation glitch on first draw
schlawg Oct 8, 2024
da567c5
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Oct 9, 2024
3ce47b2
murge from master
schlawg Oct 16, 2024
7af16a3
murge
schlawg Oct 22, 2024
8e3e82c
murge
schlawg Oct 23, 2024
0529bce
prepare for multideck
schlawg Oct 24, 2024
113d9b3
buh
schlawg Oct 26, 2024
44ad966
gah
schlawg Oct 26, 2024
f049732
murge
schlawg Oct 26, 2024
c3f4143
murge
schlawg Oct 27, 2024
96f36fd
Merge remote-tracking branch 'upstream/master' into ask
schlawg Oct 27, 2024
2a09193
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Oct 27, 2024
f72060e
murge
schlawg Nov 6, 2024
e2dc93c
Merge remote-tracking branch 'upstream/master' into ask
schlawg Nov 6, 2024
f2a2d8c
Merge branch 'local-play' into testy-bot-studio
schlawg Nov 6, 2024
7983b26
prettier
schlawg Nov 6, 2024
9f13de3
make tsc promise rejection fatal
schlawg Nov 6, 2024
e647454
add french language to voice rec
schlawg Dec 7, 2024
da0f9ac
fix package.json
schlawg Dec 7, 2024
0dea52c
swap static image for paused video player
schlawg Dec 14, 2024
16f0d54
close button style tweaks
schlawg Dec 14, 2024
369a67e
remove Seq
schlawg Dec 15, 2024
72eaae1
merge pinned streamer change for preview on testy
schlawg Dec 16, 2024
8872b50
comment out "ongoing" requirement to facilitate testing
schlawg Dec 16, 2024
916b6e9
resolve branch conflict
schlawg Dec 16, 2024
767d723
aaarmstark ideas
schlawg Dec 18, 2024
53ac34e
neutral look
schlawg Dec 18, 2024
a05b380
slightly less hilite on hover
schlawg Dec 18, 2024
af6e51d
remove youtube play button
schlawg Dec 19, 2024
ecbc689
aaarmstarks play button masterpiece continues to evolve
schlawg Dec 20, 2024
ae0b359
aaarmstark's masterpiece continues to evolve
schlawg Dec 20, 2024
2d63d7b
murge
schlawg Dec 20, 2024
fca5ce9
murge
schlawg Dec 26, 2024
c88fa47
murge
schlawg Dec 30, 2024
cddeed1
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Dec 30, 2024
6cc9ff4
dasher polls
schlawg Dec 31, 2024
714f336
.
schlawg Dec 31, 2024
83e57ae
troubleshoot x-forwarded-for problem
schlawg Dec 31, 2024
74c4d03
murge
schlawg Dec 31, 2024
10762f7
murge
schlawg Dec 31, 2024
89f1555
revert forwarded-for debugging
schlawg Dec 31, 2024
50ddb48
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Jan 1, 2025
7e59297
analysis button fixes
schlawg Jan 1, 2025
5eb1f9c
murge
schlawg Jan 1, 2025
80c01a4
fix analyse board
schlawg Jan 1, 2025
ae32257
remove logging
schlawg Jan 2, 2025
c1e8a30
use container query for cosmetics
schlawg Jan 2, 2025
8f2b92b
Merge remote-tracking branch 'upstream/master' into local-play
schlawg Jan 2, 2025
a3ae587
zerofish 0.0.30
schlawg Jan 2, 2025
87472bd
zerofish 0.0.30
schlawg Jan 2, 2025
249404d
fix threefold, add json, add move tracing & reports
schlawg Jan 5, 2025
e4a8679
fix linked chessground
schlawg Jan 5, 2025
f4d5c8b
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Jan 5, 2025
ac74ec0
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Jan 5, 2025
a9dd575
combined filters WIP
schlawg Jan 5, 2025
293ad87
eradicate threefolds
schlawg Jan 6, 2025
c9387e3
bin/deploy wtf?
schlawg Jan 6, 2025
a50b48c
faceted filters (no db upgrade yet)
schlawg Jan 10, 2025
5619a95
split opening books by color
schlawg Jan 10, 2025
8ff0fd9
fix pgn crlf, add db migration
schlawg Jan 11, 2025
6c049fa
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Jan 11, 2025
242a9fa
fix migration issue
schlawg Jan 11, 2025
a2474f4
fix server build error, optimize folderSize, experimental _html
schlawg Jan 11, 2025
c8afba5
fix windows
schlawg Jan 12, 2025
8d03be4
save game progress & murge
schlawg Jan 15, 2025
9d99dd0
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Jan 15, 2025
94d37e9
troubleshoot iOS < 10 oauth button
schlawg Jan 15, 2025
d26c9d1
scalafmt
schlawg Jan 15, 2025
20379e4
fix init bug
schlawg Jan 15, 2025
2ab6a22
inline the oauth button script
schlawg Jan 15, 2025
84f95a3
test inline oauth script
schlawg Jan 15, 2025
c5620b6
to be honest i have not idea what is in this commit
schlawg Jan 16, 2025
302beda
cosmedits
schlawg Jan 16, 2025
17db4e0
move localGame.ts to game and board hashing to chess
schlawg Jan 17, 2025
909ff8f
bugfixes and prepare for local.db
schlawg Jan 17, 2025
ee533a7
deps
schlawg Jan 17, 2025
9266eab
murge
schlawg Jan 18, 2025
6212b5d
murge
schlawg Jan 31, 2025
e6506c1
Merge branch 'ui-build-refactor' into testy-bot-studio
schlawg Jan 31, 2025
cd37550
remove fs-ext package, fallback to pid file
schlawg Feb 1, 2025
f83325b
move instanceLock to env
schlawg Feb 1, 2025
81863fd
fix clock, resume game on bot turn, and sass
schlawg Feb 2, 2025
7d5d325
refactor
schlawg Feb 2, 2025
885910a
fix fun mobject clear bug
schlawg Feb 2, 2025
c5c3140
gah
schlawg Feb 3, 2025
0796655
fun with corepack
schlawg Feb 3, 2025
87c7564
add p
schlawg Feb 3, 2025
c020b0f
add latest
schlawg Feb 3, 2025
f8890b3
keep throwing shit at the wall
schlawg Feb 3, 2025
f553546
gah
schlawg Feb 3, 2025
3d40e2a
gah
schlawg Feb 3, 2025
445ce11
prepare to support full asset urls in bot jsons
schlawg Feb 5, 2025
d91f2d8
lastIndexOf rather than indexOf for hash extensions (same as esbuild …
schlawg Feb 6, 2025
4b77280
relative css urls no longer inherit the cache buster
schlawg Feb 6, 2025
7368675
always be hashing
schlawg Feb 8, 2025
d7dedad
murge
schlawg Feb 8, 2025
8d231b8
murge
schlawg Feb 8, 2025
fec1bb8
localDb crap
schlawg Feb 8, 2025
4b52eda
ids -> status and export status as * from game
schlawg Feb 9, 2025
092908c
move bits.user stuff out of bits
schlawg Feb 9, 2025
9d738f0
fix build monitor
schlawg Feb 9, 2025
28117a6
fixxezzz
schlawg Feb 11, 2025
88be022
murge
schlawg Feb 11, 2025
fced504
honestly i cannot remember, it was at least 4 hours ago
schlawg Feb 12, 2025
a50e977
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Feb 12, 2025
d63a0e9
hand of cards wip, broke on touch
schlawg Feb 13, 2025
437d493
gah
schlawg Feb 13, 2025
f2d889e
murge
schlawg Feb 13, 2025
0395a4e
Merge remote-tracking branch 'upstream/master' into testy-bot-studio
schlawg Feb 14, 2025
23204b0
well have to delete this testCheckCfg stuff from tsc.ts
schlawg Feb 15, 2025
63c34dc
h
schlawg Feb 19, 2025
547104d
YOLO merge from testy-bot-studio
schlawg Feb 19, 2025
e094464
Merge branch 'master' into fancy-bots
ornicar Feb 19, 2025
7ba393a
IOResult.status is always set to Success(Done)
ornicar Feb 19, 2025
d60a31a
remove unnecessary `.as[JsObject]`
ornicar Feb 19, 2025
ecd0f34
don't read the cookie session when serving asset keys
ornicar Feb 19, 2025
6be1d7f
fix next-group gesture (touch drag down)
schlawg Feb 19, 2025
e263fe9
basic board editor for setup dialog
schlawg Feb 20, 2025
adbadeb
nav buttons in setup for those without touch scroll
schlawg Feb 20, 2025
d271a55
fix dup import
schlawg Feb 20, 2025
8f47bd3
Merge branch 'fancy-bots' of https://github.com/lichess-org/lila into…
ornicar Feb 20, 2025
6590a65
Merge branch 'master' into fancy-bots
ornicar Feb 20, 2025
be61544
fix pnpm lockfile maybe
ornicar Feb 20, 2025
bf6f216
local use config.assetPath
ornicar Feb 20, 2025
5dc23cd
scala tweak
ornicar Feb 20, 2025
e14b4e0
local filter file extensions earlier
ornicar Feb 20, 2025
547a27d
move code from controller to local module, use Map instead of JsObjec…
ornicar Feb 20, 2025
f27d375
better type LocalAssets
ornicar Feb 20, 2025
0b86185
LocalApi.AlmostFileName
ornicar Feb 20, 2025
8326d48
remove a bunch of unused imports
ornicar Feb 20, 2025
7086e41
use the user infos present on the page, remove unused imports
ornicar Feb 20, 2025
edec5bb
improve setup dialog in tiny portrait views
schlawg Feb 20, 2025
adfe8d2
show fake rating on card label
schlawg Feb 20, 2025
67450ab
tweak Local ctrl
ornicar Feb 20, 2025
d4b4f44
ui/local this.bots & this.scratch should be Map<>
ornicar Feb 20, 2025
6a0171b
more consistent function names
schlawg Feb 20, 2025
0aa353f
remove dead code
schlawg Feb 21, 2025
ab5a0cc
hopefully fix lockfile issue with vitest & jsdom
schlawg Feb 21, 2025
2361340
merge from master
schlawg Feb 21, 2025
778d7ed
setup modal for mobile landscape
schlawg Feb 21, 2025
a31c95a
Merge branch 'master' into fancy-bots
ornicar Feb 21, 2025
165b8d8
nicer, although unused, assetTypeOpt implementation
ornicar Feb 21, 2025
4704394
local scala typing, golf, and new bugs
ornicar Feb 21, 2025
d49b7f6
move OpaqueJson to common
ornicar Feb 21, 2025
89fd0d4
rename local mongodb collections to use singular instead of plural
ornicar Feb 21, 2025
9376012
rename local collections in scripts
ornicar Feb 21, 2025
1ceafea
more local typing and golf
ornicar Feb 21, 2025
a1c167d
use AssetType.read
ornicar Feb 21, 2025
bcae9f2
tweak LocalUi
ornicar Feb 21, 2025
3440e83
remove debug and improve comments
schlawg Feb 21, 2025
ff2a1f9
Merge branch 'master' into fancy-bots
ornicar Feb 25, 2025
52de0aa
Merge branch 'master' into fancy-bots
ornicar Feb 25, 2025
61a8f51
Merge branch 'master' into fancy-bots
ornicar Feb 26, 2025
d373717
bugfixes, better movetime, and a murge
schlawg Mar 1, 2025
82ac997
Merge remote-tracking branch 'upstream/master' into fancy-bots
schlawg Mar 1, 2025
b3f2eae
murge
schlawg Mar 1, 2025
4e0149e
fix local package link
schlawg Mar 1, 2025
63d9cab
Merge branch 'master' into fancy-bots
ornicar Mar 1, 2025
d076ee6
fix branch merge
ornicar Mar 1, 2025
a0e6c1f
remove transitive dependencies
ornicar Mar 1, 2025
6b47b18
relocate to /bots
ornicar Mar 1, 2025
5a10da4
secure bots controllers
ornicar Mar 1, 2025
577c7c9
remove superfluous dependency
ornicar Mar 1, 2025
5ef4052
bots fix warnings and stuff
ornicar Mar 2, 2025
a3ccb17
fix search and replace
schlawg Mar 2, 2025
bc21732
reduce zerofish memory footprint, fix bugs
schlawg Mar 3, 2025
86179a4
make url with a string, not a url
schlawg Mar 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class Env(
given scheduler: Scheduler = system.scheduler
given RateLimit = net.rateLimit
given NetDomain = net.domain
given getFile: (String => java.io.File) = environment.getFile

// wire all the lila modules in the right order
val i18n: lila.i18n.Env.type = lila.i18n.Env
Expand Down Expand Up @@ -98,6 +99,7 @@ final class Env(
val bot: lila.bot.Env = wire[lila.bot.Env]
val storm: lila.storm.Env = wire[lila.storm.Env]
val racer: lila.racer.Env = wire[lila.racer.Env]
val local: lila.local.Env = wire[lila.local.Env]
val opening: lila.opening.Env = wire[lila.opening.Env]
val tutor: lila.tutor.Env = wire[lila.tutor.Env]
val recap: lila.recap.Env = wire[lila.recap.Env]
Expand Down
1 change: 1 addition & 0 deletions app/LilaComponents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ final class LilaComponents(
lazy val irwin: Irwin = wire[Irwin]
lazy val learn: Learn = wire[Learn]
lazy val lobby: Lobby = wire[Lobby]
lazy val localPlay: Local = wire[Local]
lazy val main: Main = wire[Main]
lazy val msg: Msg = wire[Msg]
lazy val mod: Mod = wire[Mod]
Expand Down
99 changes: 99 additions & 0 deletions app/controllers/Local.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package controllers

import play.api.libs.json.*
import play.api.mvc.*

import lila.app.{ given, * }
import lila.common.Json.given
import lila.local.{ AssetType, BotJson }

final class Local(env: Env) extends LilaController(env):

extension (r: Result)
def withServiceWorker(using RequestHeader) =
r.enforceCrossSiteIsolation.withHeaders("Service-Worker-Allowed" -> "/")

def index = Secure(_.Beta) { _ ?=> _ ?=>
for
bots <- env.local.repo.getLatestBots()
res <- negotiate(
html =
for page <- renderPage(indexPage(bots))
yield Ok(page).withServiceWorker,
json = JsonOk(Json.obj("bots" -> bots))
)
yield res
}

def assetKeys = Anon: // for service worker
JsonOk(env.local.api.getJson)

def devIndex = Secure(_.BotEditor): _ ?=>
for
bots <- env.local.repo.getLatestBots()
assets <- env.local.api.devGetAssets
page <- renderPage(indexPage(bots, assets.some))
yield Ok(page).withServiceWorker

def devAssets = Secure(_.BotEditor): ctx ?=>
env.local.api.devGetAssets.map(JsonOk)

def devBotHistory(botId: Option[UserStr]) = Secure(_.BotEditor): _ ?=>
env.local.repo
.getVersions(botId.map(_.id))
.map: history =>
JsonOk(Json.obj("bots" -> history))

def devPostBot = SecureBody(parse.json)(_.BotEditor) { ctx ?=> me ?=>
ctx.body.body
.validate[JsObject]
.fold(
err => BadRequest(jsonError(err.toString)),
bot => env.local.repo.putBot(BotJson(bot), me.userId).map(JsonOk)
)
}

def devNameAsset(key: String, name: String) = Secure(_.BotEditor): _ ?=>
env.local.repo
.nameAsset(none, key, name, none)
.flatMap(_ => env.local.api.devGetAssets.map(JsonOk))

def devDeleteAsset(key: String) = Secure(_.BotEditor): _ ?=>
env.local.repo
.deleteAsset(key)
.flatMap(_ => env.local.api.devGetAssets.map(JsonOk))

def devPostAsset(tpe: String, key: String) = SecureBody(parse.multipartFormData)(_.BotEditor) { ctx ?=>
AssetType
.read(tpe)
.so: (tpe: AssetType) =>
def formValue(field: String) = ctx.body.body.dataParts.get(field).flatMap(_.headOption)
val author: Option[UserId] = formValue("author").flatMap(UserStr.read).map(_.id)
val name = formValue("name").getOrElse(key)
ctx.body.body
.file("file")
.map: file =>
env.local.api
.storeAsset(tpe, key, file)
.flatMap:
case Left(error) => InternalServerError(jsonError(error)).as(JSON)
case Right(assets) =>
for _ <- env.local.repo.nameAsset(tpe.some, key, name, author)
yield JsonOk(Json.obj("key" -> key, "name" -> name))
.getOrElse(BadRequest(jsonError("missing file")).as(JSON))
}

private def indexPage(bots: List[BotJson], devAssets: Option[JsObject] = none)(using Context) =
views.local.index(
Json
.obj("pref" -> pref, "bots" -> bots)
.add("assets", devAssets)
.add("canPost", isGrantedOpt(_.BotEditor)),
if devAssets.isDefined then "local.dev" else "local"
)

private def pref(using ctx: Context) =
lila.pref.JsonView
.write(ctx.pref, false)
.add("animationDuration", ctx.pref.animationMillis.some)
.add("enablePremove", ctx.pref.premove.some)
2 changes: 1 addition & 1 deletion app/controllers/Round.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class Round(
jsChat <- chat.flatMap(_.game).map(_.chat).soFu(lila.chat.JsonView.asyncLines)
yield Ok(data.add("chat", jsChat)).noCache
)
yield res
yield res.enforceCrossSiteIsolation

def player(fullId: GameFullId) = Open:
env.round.proxyRepo
Expand Down
1 change: 1 addition & 0 deletions app/views/game/widgets.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ object widgets:

private val separator = " • "

// mirrored html generation in file://../../../ui/user/src/user.ts
def apply(
games: Seq[Game],
notes: Map[GameId, String] = Map(),
Expand Down
2 changes: 2 additions & 0 deletions app/views/ui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ val challenge = lila.challenge.ui.ChallengeUi(helpers)

val dev = lila.web.ui.DevUi(helpers)(mod.ui.menu)

val local = lila.local.ui.LocalUi(helpers)

def mobile(p: lila.cms.CmsPage.Render)(using Context) =
lila.web.ui.mobile(helpers)(cms.render(p))

Expand Down
2 changes: 1 addition & 1 deletion bin/schlawg-dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
journalctl --user -fu lila -o cat | grep -E -v fishnet &
JOURNALCTL_PID=$!

# l=/ui-build
# l=https://schlawg.org/console
"$(dirname "${BASH_SOURCE[0]:-$0}")/../ui/build" -${1:-'wd'} &
UI_BUILD_PID=$!

Expand Down
7 changes: 6 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ lazy val modules = Seq(
// and then the smaller ones
pool, lobby, relation, tv, coordinate, feed, history, recap,
shutup, appeal, irc, explorer, learn, event, coach,
practice, evalCache, irwin, bot, racer, cms, i18n,
practice, evalCache, irwin, bot, racer, cms, i18n, local,
socket, bookmark, studySearch, gameSearch, forumSearch, teamSearch,
)

Expand Down Expand Up @@ -148,6 +148,11 @@ lazy val racer = module("racer",
Seq()
)

lazy val local = module("local",
Seq(db, ui),
Seq()
)

lazy val video = module("video",
Seq(memo, ui),
macwire.bundle
Expand Down
1 change: 1 addition & 0 deletions conf/base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ insight {
learn {
collection.progress = learn_progress
}
local.asset_path = "public/lifat/bots"
kaladin.enabled = false
zulip {
domain = ""
Expand Down
11 changes: 11 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,17 @@ GET /streamer/:username controllers.Streamer.show(username: UserS
GET /streamer/:username/redirect controllers.Streamer.redirect(username: UserStr)
POST /streamer/:username/check controllers.Streamer.checkOnline(username: UserStr)

# Private Play

GET /bots controllers.Local.index
GET /bots/assets controllers.Local.assetKeys
GET /bots/dev controllers.Local.devIndex
GET /bots/dev/history controllers.Local.devBotHistory(id: Option[UserStr])
POST /bots/dev/bot controllers.Local.devPostBot
GET /bots/dev/assets controllers.Local.devAssets
POST /bots/dev/asset/$tpe<sound|image|book>/$key<\w{12}(\.\w{2,4})?> controllers.Local.devPostAsset(tpe: String, key: String)
POST /bots/dev/asset/mv/$key<\w{12}(\.\w{2,4})?>/:name controllers.Local.devNameAsset(key: String, name: String)

# Round
GET /$gameId<\w{8}> controllers.Round.watcher(gameId: GameId, color: Color = Color.white)
GET /$gameId<\w{8}>/$color<white|black> controllers.Round.watcher(gameId: GameId, color: Color)
Expand Down
2 changes: 2 additions & 0 deletions modules/common/src/main/Json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ object Json:
.add("title", u.title)
.add("flair", u.flair)
.add("patron", u.isPatron)

trait OpaqueJson[A](using A =:= JsObject) extends TotalWrapper[A, JsObject]
4 changes: 3 additions & 1 deletion modules/core/src/main/perm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ enum Permission(val key: String, val alsoGrants: List[Permission], val name: Str
case ApiHog extends Permission("API_HOG", "API hog")
case ApiChallengeAdmin extends Permission("API_CHALLENGE_ADMIN", "API Challenge admin")
case LichessTeam extends Permission("LICHESS_TEAM", List(Beta), "Lichess team")
case BotEditor extends Permission("BOT_EDITOR", "Bot editor")
case TimeoutMod
extends Permission(
"TIMEOUT_MOD",
Expand Down Expand Up @@ -188,6 +189,7 @@ enum Permission(val key: String, val alsoGrants: List[Permission], val name: Str
extends Permission(
"ADMIN",
List(
BotEditor,
LichessTeam,
UserSearch,
PrizeBan,
Expand Down Expand Up @@ -243,7 +245,7 @@ object Permission:
val all: Set[Permission] = values.toSet

val nonModPermissions: Set[Permission] =
Set(Beta, Coach, Teacher, Developer, Verified, ContentTeam, BroadcastTeam, ApiHog)
Set(Beta, Coach, Teacher, Developer, Verified, ContentTeam, BroadcastTeam, ApiHog, BotEditor)

val modPermissions: Set[Permission] = all.diff(nonModPermissions)

Expand Down
5 changes: 2 additions & 3 deletions modules/db/src/main/JSON.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ object JSON:
case JsArray(arr) => BSONArray(arr.map(bval))
case _ => BSONNull

def jval(bson: BSONDocument): JsValue = Json.obj(
bson.elements.map(el => el.name -> jval(el.value))*
)
def jval(bson: BSONDocument): JsObject = JsObject:
bson.elements.map(el => el.name -> jval(el.value))

def jval(bson: BSONValue): JsValue = bson match
case BSONString(value) => JsString(value)
Expand Down
5 changes: 2 additions & 3 deletions modules/forum/src/main/ForumForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ final private[forum] class ForumForm(
single("categ" -> nonEmptyText.into[ForumCategId])

private def userTextMapping(inOwnTeam: Boolean, previousText: Option[String] = None)(using me: Me) =
cleanText(minLength = 3, 20_000)
cleanText(minLength = 3, 10_000_000) // bot move dumps
.verifying(
"You have reached the daily maximum for links in forum posts.",
t => inOwnTeam || promotion.test(me, t, previousText)
)

val diagnostic = Form(single("text" -> nonEmptyText(maxLength = 100_000)))
val diagnostic = Form(single("text" -> nonEmptyText(maxLength = 10_000_000))) // bot move dumps

object ForumForm:

Expand Down
25 changes: 25 additions & 0 deletions modules/local/src/main/Env.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package lila.local

import com.softwaremill.macwire.*
import play.api.Configuration

import lila.common.autoconfig.{ *, given }
import lila.core.config.*

@Module
final private class LocalConfig(
@ConfigName("asset_path") val assetPath: String
)

@Module
final class Env(
appConfig: Configuration,
db: lila.db.Db,
getFile: String => java.io.File
)(using Executor, akka.stream.Materializer):

private val config: LocalConfig = appConfig.get[LocalConfig]("local")(AutoConfig.loader)

val repo = LocalRepo(db(CollName("local_bot")), db(CollName("local_asset")))

val api: LocalApi = wire[LocalApi]
67 changes: 67 additions & 0 deletions modules/local/src/main/LocalApi.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package lila.local

import java.nio.file.{ Files as NioFiles, Paths }
import play.api.libs.json.*
import play.api.libs.Files
import play.api.mvc.*
import akka.stream.scaladsl.{ FileIO, Source }
import akka.util.ByteString

// this stuff is for bot devs

final private class LocalApi(config: LocalConfig, repo: LocalRepo, getFile: String => java.io.File)(using
Executor,
akka.stream.Materializer
):

type AlmostFileName = String
type LocalAssets = Map[AssetType, List[AlmostFileName]]

@volatile private var cachedAssets: Option[(LocalAssets, JsonStr)] = None

def storeAsset(
tpe: AssetType,
fileName: String,
file: MultipartFormData.FilePart[Files.TemporaryFile]
): Fu[Either[String, (LocalAssets, JsonStr)]] =
FileIO
.fromPath(file.ref.path)
.runWith(FileIO.toPath(getFile(s"${config.assetPath}/${tpe}/$fileName").toPath))
.map(_ => Right(updateAssets))
.recover:
case e: Exception => Left(s"Exception: ${e.getMessage}")

def getBoth: (LocalAssets, JsonStr) = cachedAssets.getOrElse(updateAssets)
def getAssets: LocalAssets = getBoth._1
def getJson: JsonStr = getBoth._2

def devGetAssets: Fu[JsObject] =
repo.getAssets.map: m =>
Json.toJsObject:
getAssets.map: (categ, keys) =>
categ -> (for
key <- keys
name <- m.get(key)
yield Json.obj("key" -> key, "name" -> name))

private def listFiles(tpe: AssetType, ext: String): List[AlmostFileName] =
val path = getFile(s"${config.assetPath}/${tpe}")
if !path.exists() then
NioFiles.createDirectories(path.toPath)
Nil
else
path
.listFiles(_.getName.endsWith(s".${ext}"))
.toList
.map(_.getName)

def updateAssets: (LocalAssets, JsonStr) =
val data: LocalAssets = Map(
"image" -> listFiles("image", "webp"),
"net" -> listFiles("net", "pb"),
"sound" -> listFiles("sound", "mp3"),
"book" -> listFiles("book", "png").map(_.dropRight(4))
)
val newAssets = (data, JsonStr(Json.stringify(Json.toJson(data))))
cachedAssets = newAssets.some
newAssets
Loading
Loading