-
-
Save tors42/49b74ee441a767f9e7e7bfc528fe8085 to your computer and use it in GitHub Desktop.
A user account which has Study/Broadcast Admin permissions can set "period" via API with scopes study:read, study:write, web:mod
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
String lichessApi = "http://localhost:8080"; | |
if (! Files.exists(Path.of("chariot.jar"))) { | |
Files.write(Path.of("chariot.jar"), URI.create( | |
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.1.1/chariot-0.1.1.jar" | |
).toURL().openStream().readAllBytes()); | |
} | |
/env --class-path chariot.jar | |
import chariot.*; | |
import chariot.Client.*; | |
import chariot.model.*; | |
void runWithClient(ClientAuth client) throws Exception { | |
String name = "Test Broadcast"; | |
String descr = "Testing Period"; | |
String roundName = "Test Round"; | |
String syncUrl = "http://127.0.1.1/games.pgn"; | |
int period = 42; | |
int updatePeriod = 20; | |
if (client.broadcasts().create(b -> b.name(name).shortDescription(descr)) | |
instanceof Entry(Broadcast broadcast) | |
&& client.broadcasts().createRound(broadcast.id(), r -> r.name(roundName).syncUrl(syncUrl).period(period)) | |
instanceof Entry(MyRound round)) { | |
System.out.println("Visit " + lichessApi + "/broadcast/round/" + round.id() + "/edit to see value of period."); | |
Thread.sleep(5000); | |
if (client.broadcasts().updateRound(round.id(), r -> r.name(roundName).syncUrl(syncUrl).period(updatePeriod)) | |
instanceof Entry(Broadcast.Round updated)) { | |
System.out.println("Updated period"); | |
} else { | |
System.out.println("Failed to update round"); | |
} | |
} else { | |
System.out.println("Failed to create broadcast and round"); | |
} | |
} | |
switch (Client.auth( | |
conf -> conf.api(lichessApi), | |
url -> System.out.println("Visit the following URL to grant permission:\n\n" + url), | |
pkce -> pkce.scope(Scope.study_read, Scope.study_write, Scope.web_mod))) { | |
case AuthOk(var client) -> runWithClient(client); | |
case AuthFail(var fail) -> System.out.println("Authorization failed: " + fail); | |
} | |
/exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update-period.webm