forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
193 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package lila.explorer | ||
|
||
import org.joda.time.DateTime | ||
|
||
import lila.game.{ Game, GameRepo } | ||
import lila.importer.{ Importer, ImportData } | ||
|
||
final class ExplorerImport( | ||
endpoint: String, | ||
importer: Importer | ||
) { | ||
|
||
private val masterGameEncodingFixedAt = new DateTime(2016, 3, 9, 0, 0) | ||
|
||
def apply(id: Game.ID): Fu[Option[Game]] = | ||
GameRepo game id flatMap { | ||
case Some(game) if game.createdAt.isAfter(masterGameEncodingFixedAt) => fuccess(game.some) | ||
case _ => (GameRepo remove id) >> fetchPgn(id) flatMap { | ||
case None => fuccess(none) | ||
case Some(pgn) => importer( | ||
ImportData(pgn, none), | ||
user = "lichess".some, | ||
forceId = id.some | ||
) map some | ||
} | ||
} | ||
|
||
private def fetchPgn(id: String): Fu[Option[String]] = { | ||
import play.api.libs.ws.WS | ||
import play.api.Play.current | ||
WS.url(s"$endpoint/master/pgn/$id").get() map { | ||
case res if res.status == 200 => res.body.some | ||
case _ => None | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package lila.study | ||
|
||
import lila.game.{ Game, Namer, PgnImport } | ||
import lila.user.User | ||
import chess.format.pgn.{ Parser, Reader, ParsedPgn, Tag, TagType } | ||
|
||
private final class ExplorerGame( | ||
importer: lila.explorer.ExplorerImport | ||
) { | ||
|
||
def quote(userId: User.ID, study: Study, chapter: Chapter, path: Path, gameId: Game.ID): Fu[Comment] = | ||
importer(gameId) flatMap { | ||
_.fold(false) { game => | ||
|
||
val comment = Comment( | ||
id = Comment.Id.make, | ||
text = game.pgnImport.fold(lichessTitle)(importTitle(game)), | ||
by = Comment.Author.User(author.id, author.titleName) | ||
) | ||
} | ||
} | ||
|
||
private def importTitle(g: Game)(pgnImport: PgnImport): String = | ||
Parser.full(pgnImport.pgn) flatMap { | ||
case ParsedPgn(_, tags, _) => | ||
def tag(which: Tag.type => TagType): Option[String] = | ||
tags find (_.name == which(Tag)) map (_.value) | ||
|
||
ImportData(pgnImport.pgn, none).preprocess(none).fold( | ||
_ => lichessTitle(g), | ||
processed => | ||
val players = Namer.vsText(game, withRatings = true) | ||
val result = chess.Color.showResult(game.winnerColor) | ||
val text = s"$players, $result | ||
} | ||
|
||
def insert(userId: User.ID, study: Study, chapter: Chapter, gameId: Game.ID) = ??? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package lila.study | ||
|
||
private final class StudyCommenter() { | ||
|
||
def apply(chapter: Chapteer, position: Position, comment: Comment) = | ||
chapter.setComment(comment, position.path) match { | ||
case Some(newChapter) => | ||
studyRepo.updateNow(study) | ||
newChapter.root.nodeAt(position.path) ?? { node => | ||
node.comments.findBy(comment.by) ?? { c => | ||
chapterRepo.setComments(newChapter, position.path, node.comments.filterEmpty) >>- { | ||
sendTo(study, Socket.SetComment(position, c, uid)) | ||
indexStudy(study) | ||
sendStudyEnters(study, userId) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters