Skip to content

Commit

Permalink
feat: new api endpoint and enable regular match creations
Browse files Browse the repository at this point in the history
  • Loading branch information
yHSJ committed Dec 10, 2024
1 parent 3a57bff commit bf9d9c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/fi/sundae/bot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Bot(String token, String ownerId, String channelId, String adminRoleId) {
jdaBuilder.addEventListeners(commandBuilder.build(), new Listener(MATCHMAKER));

JDA jda = jdaBuilder.build();
// scheduleMatchmaking(jda);
scheduleMatchmaking(jda);
}

private void scheduleMatchmaking(JDA jda) {
Expand All @@ -46,7 +46,7 @@ private void scheduleMatchmaking(JDA jda) {
MATCHMAKER.announceMatchesStart(matches, jda);
},
0,
10,
5,
TimeUnit.MINUTES);
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/fi/sundae/bot/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public API(Matchmaker matchmaker, JDA jda) {
Javalin.create()
.post("/match", new MatchHandler(matchmaker, jda))
.get("/readyPlayers", new ReadyPlayersHandler(matchmaker))
.get("/activeMatches", new ActiveMatchesHandler(matchmaker))
.start();
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/fi/sundae/bot/api/ActiveMatchesHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fi.sundae.bot.api;

import fi.sundae.bot.tournament.Matchmaker;
import io.javalin.http.Context;
import io.javalin.http.Handler;
import org.jetbrains.annotations.NotNull;

public class ActiveMatchesHandler implements Handler {

private final Matchmaker MATCHMAKER;

public ActiveMatchesHandler(Matchmaker matchmaker) {
this.MATCHMAKER = matchmaker;
}

@Override
public void handle(@NotNull Context ctx) throws Exception {
ctx.json(MATCHMAKER.getActiveMatches());
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/fi/sundae/bot/tournament/Matchmaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,8 @@ public HashMap<Region, List<String>> getUsernames() {

return userNamesInRegions;
}

public List<Match> getActiveMatches() {
return ACTIVE_MATCHES;
}
}

0 comments on commit bf9d9c0

Please sign in to comment.