diff --git a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/core/LavalinkPlugin.kt b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/core/LavalinkPlugin.kt index e5a4716..fb97483 100644 --- a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/core/LavalinkPlugin.kt +++ b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/core/LavalinkPlugin.kt @@ -20,10 +20,12 @@ import io.ktor.client.request.header import io.ktor.client.request.request import io.ktor.client.request.setBody import io.ktor.http.ContentType +import io.ktor.http.ContentType.Application import io.ktor.http.HttpHeaders import io.ktor.http.HttpMethod import io.ktor.http.URLProtocol import io.ktor.http.appendPathSegments +import io.ktor.http.contentType import io.ktor.http.isSecure import io.ktor.http.takeFrom import io.ktor.resources.Resource @@ -47,6 +49,7 @@ object Tonbrett : Plugin { suspend fun Node.syncSounds() = request(HttpMethod.Post, "v4", "sounds", "sync") suspend fun Node.deleteSound(id: String) = request(HttpMethod.Delete, "v4", "sounds", id) suspend fun Node.syncSound(sound: Sound) = request(HttpMethod.Put, "v4", "sounds") { + contentType(Application.Json) setBody(sound) } diff --git a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/server/SoundsRoute.kt b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/server/SoundsRoute.kt index 38df5a9..a95ddd9 100644 --- a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/server/SoundsRoute.kt +++ b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/server/SoundsRoute.kt @@ -4,7 +4,6 @@ import dev.kord.cache.api.query import dev.kord.common.annotation.KordExperimental import dev.kord.common.annotation.KordUnsafe import dev.kord.core.Kord -import dev.kord.core.behavior.edit import dev.kord.core.cache.data.SoundboardSoundData import dev.kord.core.cache.idEq import dev.kordex.core.koin.KordExContext @@ -13,7 +12,6 @@ import dev.schlaubi.tonbrett.bot.core.soundPlayer import dev.schlaubi.tonbrett.bot.core.voiceState import dev.schlaubi.tonbrett.bot.io.SoundBoardDatabase import dev.schlaubi.tonbrett.bot.io.findAllTags -import dev.schlaubi.tonbrett.bot.io.findById import dev.schlaubi.tonbrett.bot.io.searchGrouped import dev.schlaubi.tonbrett.bot.util.badRequest import dev.schlaubi.tonbrett.bot.util.soundNotFound @@ -30,6 +28,8 @@ import io.ktor.server.response.* import io.ktor.server.routing.Route import kotlinx.coroutines.delay import kotlinx.coroutines.flow.toList +import org.bson.types.ObjectId +import org.litote.kmongo.toId import kotlin.time.Duration.Companion.milliseconds private val discordIdPattern = Regex("\\d{18,}") @@ -45,7 +45,7 @@ fun Route.sounds() { }.singleOrNull() ?: return null cachedSound.toSound() } else { - SoundBoardDatabase.sounds.findOneById(id) + SoundBoardDatabase.sounds.findOneById(ObjectId(id)) } } @@ -91,7 +91,11 @@ fun Route.sounds() { } call.respond( - (SoundBoardDatabase.sounds.searchGrouped(queryString, onlyMine, if(isLavalink) Snowflake.min else call.userId) + (SoundBoardDatabase.sounds.searchGrouped( + queryString, + onlyMine, + if (isLavalink) Snowflake.min else call.userId + ) .toList() + discordSound) .convertForNonJvmPlatforms(!useUnicode) ) diff --git a/build.gradle.kts b/build.gradle.kts index d9a4a18..ce691ae 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { allprojects { group = "dev.schlaubi.tonbrett" - version = "2.1.3" + version = "2.1.4" repositories { mavenCentral() diff --git a/lavalink-plugin/src/main/kotlin/RestHandler.kt b/lavalink-plugin/src/main/kotlin/RestHandler.kt index 5bb73e8..61e3d6b 100644 --- a/lavalink-plugin/src/main/kotlin/RestHandler.kt +++ b/lavalink-plugin/src/main/kotlin/RestHandler.kt @@ -22,8 +22,7 @@ class RestHandler(private val soundDownloader: SoundDownloader) : CoroutineScope override val coroutineContext: CoroutineContext = Dispatchers.IO + SupervisorJob() - - @PutMapping(value = ["/v4/sounds/"]) + @PutMapping(value = ["/v4/sounds"]) fun downloadSound(@RequestBody sound: Sound) = runBlocking { soundDownloader.downloadSound(sound)