Skip to content

Commit

Permalink
Fix some concurrency issues with the music plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Dec 25, 2024
1 parent 83636d3 commit 08d08c7
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Config : EnvironmentConfig() {
val POD_ID by getEnv(transform = String::toInt)
val SHARDS_PER_POD by getEnv(2, String::toInt)
val TOTAL_SHARDS by getEnv(transform = String::toInt)
val PORT by getEnv(8081, String::toInt)
val KUBERNETES_PORT by getEnv(8081, String::toInt)
val STATEFUL_SET_NAME by this
val NAMESPACE by getEnv("default")
val CONTAINER_NAME by this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import io.ktor.server.routing.*
import mu.KotlinLogging

fun startServer(checks: List<HealthCheck>, context: PluginContext) =
embeddedServer(Netty, Config.PORT) {
embeddedServer(Netty, Config.KUBERNETES_PORT) {
install(Resources)

routing {
Expand Down
2 changes: 1 addition & 1 deletion music/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
subprojects {
version = "4.2.0-SNAPSHOT"
version = "4.3.0-SNAPSHOT"

repositories {
maven("https://maven.topi.wtf/releases")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import kotlinx.coroutines.launch
import org.koin.core.component.inject
import org.litote.kmongo.serialization.registerSerializer
import org.pf4j.ExtensionPoint
import java.util.concurrent.ConcurrentHashMap
import kotlin.reflect.KMutableProperty1

interface MusicExtensionPoint : ExtensionPoint {
Expand All @@ -47,7 +48,7 @@ interface MusicExtensionPoint : ExtensionPoint {

class MusicModule(context: PluginContext) : MikBotModule(context) {
private val lavalink: LavalinkManager by extension()
private val musicPlayers: MutableMap<Snowflake, MusicPlayer> = mutableMapOf()
private val musicPlayers: MutableMap<Snowflake, MusicPlayer> = ConcurrentHashMap()
override val name: String = "music"
override val allowApplicationCommandInDMs: Boolean = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class MusicPlayer(val link: Link, private val guild: GuildBehavior) : Link by li
return remainingTrackDuration + remainingQueue
}

val nextSongIsFirst: Boolean get() = queue.isEmpty() && link.player.playingTrack == null
val nextSongIsFirst: Boolean get() = queue.isEmpty() && playingTrack == null

suspend fun queueTrack(
force: Boolean,
Expand Down Expand Up @@ -229,7 +229,7 @@ class MusicPlayer(val link: Link, private val guild: GuildBehavior) : Link by li
updateMusicChannelMessage()
}

private fun onTrackStart(@Suppress("unused") event: TrackStartEvent) {
private fun onTrackStart(@Suppress("unused_parameter") event: TrackStartEvent) {
leaveTimeout?.cancel()
updateMusicChannelMessage()
}
Expand Down Expand Up @@ -300,7 +300,6 @@ class MusicPlayer(val link: Link, private val guild: GuildBehavior) : Link by li
}
if (canSkip) {
startNextSong()
updateMusicChannelMessage()
} else {
stop()
}
Expand All @@ -321,7 +320,6 @@ class MusicPlayer(val link: Link, private val guild: GuildBehavior) : Link by li
queue.addTracks(SimpleQueuedTrack(autoPlayTrack, guild.kord.selfId))
}
if (queue.isEmpty() && !repeat) {
updateMusicChannelMessage()
return
}
val nextTrack: QueuedTrack = when {
Expand Down

0 comments on commit 08d08c7

Please sign in to comment.