Add GET /music/{guildId}/volume endpoint
Introduced a new endpoint to retrieve the current volume level for a guild's music player. Updated `MusicRoutes` and `MusicManager` with the necessary logic and added OpenAPI documentation for the route. This enhances API completeness by providing both read and write access to the volume setting.
This commit is contained in:
1 parent
9812e6da41
commit
44b284fde8
2 files changed
+29
No files matched your search
@@ -72,6 +72,7 @@ public final class MusicRoutes {
|
||||
routes.post("/music/{guildId}/stop", ctx -> stop(jdaSupplier, musicService, ctx));
|
||||
routes.post("/music/{guildId}/pause", ctx -> pause(jdaSupplier, musicService, ctx));
|
||||
routes.post("/music/{guildId}/resume", ctx -> resumePlayback(jdaSupplier, musicService, ctx));
|
||||
routes.get("/music/{guildId}/volume", ctx -> getVolume(jdaSupplier, musicService, ctx));
|
||||
routes.put("/music/{guildId}/volume", ctx -> volume(jdaSupplier, musicService, ctx));
|
||||
routes.put("/music/{guildId}/seek", ctx -> seek(jdaSupplier, musicService, ctx));
|
||||
routes.post("/music/{guildId}/vote-skip/{userId}", ctx -> voteSkip(jdaSupplier, musicService, ctx));
|
||||
@@ -218,6 +219,22 @@ public final class MusicRoutes {
|
||||
ctx.json(Map.of("status", "ok", "message", "Resuming current track"));
|
||||
}
|
||||
|
||||
@OpenApi(
|
||||
path = "/music/{guildId}/volume",
|
||||
methods = HttpMethod.GET,
|
||||
summary = "Get the current player volume of a guild",
|
||||
tags = {"Music"},
|
||||
pathParams = @OpenApiParam(name = "guildId", description = "The Discord guild id"),
|
||||
responses = {
|
||||
@OpenApiResponse(status = "200", content = @OpenApiContent(from = VolumeResponse.class)),
|
||||
@OpenApiResponse(status = "404", content = @OpenApiContent(from = ErrorResponse.class))
|
||||
}
|
||||
)
|
||||
private static void getVolume(Supplier<JDA> jdaSupplier, MusicService musicService, Context ctx) {
|
||||
MusicManager manager = manager(jdaSupplier, musicService, ctx);
|
||||
ctx.json(Map.of("status", "ok", "volume", manager.getVolume()));
|
||||
}
|
||||
|
||||
@OpenApi(
|
||||
path = "/music/{guildId}/volume",
|
||||
methods = HttpMethod.PUT,
|
||||
|
||||
@@ -367,6 +367,18 @@ public class MusicManager implements MusicManagerCallback {
|
||||
updatePlayer("set volume", builder -> builder.setVolume(volume));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player's current volume on the Lavalink node.
|
||||
*
|
||||
* @return the volume, from {@code 0} to {@code 1000}, or {@link #DEFAULT_VOLUME} when no
|
||||
* player is cached
|
||||
*/
|
||||
public int getVolume() {
|
||||
Link link = getLink();
|
||||
LavalinkPlayer player = link == null ? null : link.getCachedPlayer();
|
||||
return player == null ? DEFAULT_VOLUME : player.getVolume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeks the currently playing track to the given position.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user