actually handle errors
This commit is contained in:
parent
a652e7b029
commit
d87efe6757
1 changed files with 13 additions and 4 deletions
|
|
@ -59,8 +59,19 @@ public class Pgn2Gif extends ApplicationCommand {
|
||||||
}
|
}
|
||||||
// Load PGN from file
|
// Load PGN from file
|
||||||
PgnHolder pgn = new PgnHolder("./temp/pgn/" + attachment.getFileName());
|
PgnHolder pgn = new PgnHolder("./temp/pgn/" + attachment.getFileName());
|
||||||
|
Game game = null;
|
||||||
try {
|
try {
|
||||||
outputFile = pgnToGif(pgn);
|
game = pgnToGame(pgn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pgn.getGames().getFirst().getHalfMoves().isEmpty()) {
|
||||||
|
log.debug("Invalid PGN!");
|
||||||
|
event.getHook().sendMessage("Invalid PGN!").queue();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
outputFile = gameToGif(game);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
@ -80,11 +91,9 @@ public class Pgn2Gif extends ApplicationCommand {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File pgnToGif(PgnHolder pgn) throws Exception {
|
private static File gameToGif(Game game) throws Exception {
|
||||||
ChessRenderer renderer = new ChessRenderer(ChessThemeLibrary.GREEN_THEME, 60);
|
ChessRenderer renderer = new ChessRenderer(ChessThemeLibrary.GREEN_THEME, 60);
|
||||||
Game game = pgnToGame(pgn);
|
|
||||||
String boardID = String.valueOf(Instant.now().toEpochMilli());
|
String boardID = String.valueOf(Instant.now().toEpochMilli());
|
||||||
game.loadMoveText();
|
|
||||||
|
|
||||||
MoveList moves = game.getHalfMoves();
|
MoveList moves = game.getHalfMoves();
|
||||||
Board board = new Board();
|
Board board = new Board();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue