Skip to content

Commit

Permalink
Also remove it on track stop
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Dec 3, 2023
1 parent 12615a3 commit d4ecf36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/main/kotlin/dev/arbjerg/lavalink/internal/LavalinkSocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ class LavalinkSocket(private val node: LavalinkNode) : WebSocketListener(), Clos
Message.Op.Event -> {
event as Message.EmittedEvent

if (event is Message.EmittedEvent.TrackStartEvent) {
node.playerCache[event.guildId.toLong()]?.track = event.track
when (event) {
is Message.EmittedEvent.TrackStartEvent -> {
node.playerCache[event.guildId.toLong()]?.track = event.track
}
is Message.EmittedEvent.TrackEndEvent -> {
node.playerCache[event.guildId.toLong()]?.track = null
}
else -> {}
}

// TODO: handle websocket closed event from discord?
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/JavaJDAExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even
public void ontrackLoaded(@NotNull LoadResult.TrackLoaded result) {
final Track track = result.getData();

link.createOrUpdatePlayer()
.setEncodedTrack(track.getEncoded())
.setVolume(35)
.asMono()
.subscribe((ignored) -> {
event.getHook().sendMessage("Now playing: " + track.getInfo().getTitle()).queue();
});
link.getPlayer()
.flatMap((p) -> p.setTrack(track)
.setVolume(35)
.asMono())
.subscribe((ignored) -> {
event.getHook().sendMessage("Now playing: " + track.getInfo().getTitle()).queue();
});
}

@Override
Expand Down

0 comments on commit d4ecf36

Please sign in to comment.