Skip to content

Commit c7ce373

Browse files
committed
Coerce volume range
1 parent 33e6331 commit c7ce373

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ services:
22
ukulele:
33
container_name: ukulele
44
image: ghcr.io/freyacodes/ukulele:main
5-
restart: unless-stopped
65
environment:
76
CONFIG_DATABASE: ./db/database # Database location overwrite so mounting works
87
volumes:

src/main/kotlin/dev/arbjerg/ukulele/command/VolumeCommand.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import dev.arbjerg.ukulele.jda.Command
66
import dev.arbjerg.ukulele.jda.CommandContext
77
import org.springframework.stereotype.Component
88

9+
val PERMITTED_VOLUME_RANGE = 0..150
10+
911
@Component
1012
class VolumeCommand(val players: PlayerRegistry) : Command("volume", "v") {
1113
override suspend fun CommandContext.invoke() {
@@ -16,14 +18,14 @@ class VolumeCommand(val players: PlayerRegistry) : Command("volume", "v") {
1618
?: return replyHelp()
1719

1820
val formerVolume = player.volume
19-
player.volume = num
21+
player.volume = num.coerceIn(PERMITTED_VOLUME_RANGE)
2022
reply("Changed volume from ${formerVolume}% to ${player.volume}%.")
2123
}
2224

2325
override fun HelpContext.provideHelp() {
2426
addUsage("")
2527
addDescription("Displays the current volume.")
26-
addUsage("<0-150>%")
28+
addUsage("<${PERMITTED_VOLUME_RANGE.first}-${PERMITTED_VOLUME_RANGE.last}>%")
2729
addDescription("Sets the volume to the given percentage.")
2830
}
2931
}

0 commit comments

Comments
 (0)