Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
- Fix bug causing tonbrett sounds not to load
- Fix bug in lavalink plugin route
- Fix exception when calling lavalink api due to missing content type
  • Loading branch information
DRSchlaubi committed Nov 10, 2024
1 parent e54d773 commit 50f6c41
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,}")
Expand All @@ -45,7 +45,7 @@ fun Route.sounds() {
}.singleOrNull() ?: return null
cachedSound.toSound()
} else {
SoundBoardDatabase.sounds.findOneById(id)
SoundBoardDatabase.sounds.findOneById(ObjectId(id))
}
}

Expand Down Expand Up @@ -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)
)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

allprojects {
group = "dev.schlaubi.tonbrett"
version = "2.1.3"
version = "2.1.4"

repositories {
mavenCentral()
Expand Down
3 changes: 1 addition & 2 deletions lavalink-plugin/src/main/kotlin/RestHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 50f6c41

Please sign in to comment.