Skip to content

Commit

Permalink
Fix issues with events not firing in Java context
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Aug 21, 2023
1 parent a23fe0d commit 83a17e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 4 additions & 5 deletions example/src/commonMain/kotlin/Lavakord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import dev.kord.core.on
import dev.kord.gateway.Intent
import dev.kord.gateway.PrivilegedIntent
import dev.kord.rest.builder.interaction.string
import dev.schlaubi.lavakord.plugins.lavasrc.lavaSrcInfo
import dev.schlaubi.lavakord.audio.Event
import dev.schlaubi.lavakord.audio.Link
import dev.schlaubi.lavakord.audio.TrackEvent
import dev.schlaubi.lavakord.audio.on
import dev.schlaubi.lavakord.kord.getLink
import dev.schlaubi.lavakord.kord.lavakord
Expand Down Expand Up @@ -50,7 +49,7 @@ suspend fun main() {
}
}

lavalink.addNode("wss://joachim.lava-hosts.schlaubi.net", "jcdrNb7Y8D8TTo6D64x&msiA3CzD")
lavalink.addNode("ws://localhost:2333", "youshallnotpass")

kord.on<GuildChatInputCommandInteractionCreateEvent> {
val ack = interaction.deferPublicResponse()
Expand All @@ -61,9 +60,9 @@ suspend fun main() {
val followUpCreator = FollowupPermittingInteractionResponseBehavior(
interaction.applicationId, interaction.token, interaction.kord, interaction.supplier
)
player.on<TrackEvent> {
player.on<Event> {
try {
followUpCreator.createEphemeralFollowup { content = "Event: ${this@on.track.lavaSrcInfo}" }
followUpCreator.createEphemeralFollowup { content = "Event: ${this@on}" }
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public interface JavaEventSource<T : Any> {
*/
public fun <E : T> on(eventType: Class<E>, handler: Consumer<E>) {
events.subscribe(object : Subscriber<T> {
override fun onSubscribe(subscription: Flow.Subscription) = Unit
override fun onSubscribe(subscription: Flow.Subscription) {
subscription.request(Long.MAX_VALUE)
}

override fun onError(throwable: Throwable) {
// This in theory should never happen
Expand Down

0 comments on commit 83a17e6

Please sign in to comment.