diff --git a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/AddCommand.kt b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/AddCommand.kt index 0a61dd5..a398def 100644 --- a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/AddCommand.kt +++ b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/AddCommand.kt @@ -55,6 +55,13 @@ class AddSoundCommandArguments : Arguments() { description = "commands.add_sound.arguments.public.description" defaultValue = true } + + val volume by optionalInt { + name = "volume" + description = "commands.add_sound.arguments.volume.description" + minValue = 0 + maxValue = 1000 + } } fun SubCommandModule.addCommand() = ephemeralSubCommand(::AddSoundCommandArguments) { @@ -101,7 +108,8 @@ fun SubCommandModule.addCommand() = ephemeralSubCommand(::AddSoundCommandArgumen id, arguments.name, user.id, arguments.description, arguments.emoji?.toEmoji(), public = arguments.public, - tag = arguments.tag + tag = arguments.tag, + volume = arguments.volume ) val file = Config.SOUNDS_FOLDER / sound.fileName val soundsFolder = file.parent diff --git a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/UpdateCommand.kt b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/UpdateCommand.kt index c355bfe..d7fe419 100644 --- a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/UpdateCommand.kt +++ b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/UpdateCommand.kt @@ -2,6 +2,7 @@ package dev.schlaubi.tonbrett.bot.commands import com.kotlindiscord.kord.extensions.commands.Arguments import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalBoolean +import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalInt import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalString import com.kotlindiscord.kord.extensions.types.respond import dev.schlaubi.mikbot.plugin.api.module.SubCommandModule @@ -43,6 +44,13 @@ class UpdateSoundArguments : Arguments() { name = "public" description = "commands.update_sound.arguments.public.description" } + + val volume by optionalInt { + name = "public" + description = "commands.update_sound.arguments.volume.description" + minValue = 0 + maxValue = 1000 + } } fun SubCommandModule.updateCommand() = ephemeralSubCommand(::UpdateSoundArguments) { @@ -69,7 +77,8 @@ fun SubCommandModule.updateCommand() = ephemeralSubCommand(::UpdateSoundArgument description = arguments.description ?: sound.description, emoji = arguments.emoji?.toEmoji() ?: sound.emoji, public = arguments.public ?: sound.public, - tag = arguments.tag ?: sound.tag + tag = arguments.tag ?: sound.tag, + volume = arguments.volume ?: sound.volume ) SoundBoardDatabase.sounds.save(newSound) diff --git a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/core/SoundPlayer.kt b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/core/SoundPlayer.kt index f6cb2bd..d8955d2 100644 --- a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/core/SoundPlayer.kt +++ b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/core/SoundPlayer.kt @@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.single import kotlinx.coroutines.flow.take import kotlin.coroutines.CoroutineContext +import kotlin.io.path.fileVisitor private val players = mutableMapOf() @@ -70,7 +71,13 @@ class SoundPlayer(guild: GuildBehavior) : CoroutineScope { path("soundboard", "sounds", sound.id.toString(), "audio") }.toString() currentUser = user - player.injectTrack(url, noReplace = alreadyLocked) + player.injectTrack(url, noReplace = alreadyLocked) { + filters { + if (sound.volume != null) { + volume = sound.volume!!.toFloat() + } + } + } launch { // Wait for track to end player.player.events diff --git a/build.gradle.kts b/build.gradle.kts index 205682b..a4d8c89 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ plugins { allprojects { group = "dev.schlaubi.tonbrett" - version = "1.12.12" + version = "1.12.13" repositories { mavenCentral() diff --git a/common/src/commonMain/kotlin/dev/schlaubi/tonbrett/common/Sound.kt b/common/src/commonMain/kotlin/dev/schlaubi/tonbrett/common/Sound.kt index d619166..0bdf49f 100644 --- a/common/src/commonMain/kotlin/dev/schlaubi/tonbrett/common/Sound.kt +++ b/common/src/commonMain/kotlin/dev/schlaubi/tonbrett/common/Sound.kt @@ -30,7 +30,8 @@ public data class Sound( val emoji: Emoji? = null, @EncodeDefault(EncodeDefault.Mode.ALWAYS) val public: Boolean = true, - val tag: String? = null + val tag: String? = null, + val volume: Int? = null ) { /** * The file name of this sounds audio file. diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f29c9d0..ccc93ba 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -38,7 +38,7 @@ ktor-client-auth = { group = "io.ktor", name = "ktor-client-auth", version.ref = ktor-serialization-kotlinx-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" } mikbot-ktor = { group = "dev.schlaubi", name = "mikbot-ktor", version.ref = "mikbot" } -mikbot-music = { group = "dev.schlaubi", name = "mikbot-music-player", version = "3.1.0-SNAPSHOT" } +mikbot-music = { group = "dev.schlaubi", name = "mikbot-music-player", version = "3.1.8-SNAPSHOT" } imageloader = { group = "io.github.qdsfdhvh", name = "image-loader", version = "1.6.4" }