Skip to content

Commit e434ff7

Browse files
committed
Don't mark node as available before we have a session id
1 parent 16a7cad commit e434ff7

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

settings.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fun VersionCatalogBuilder.common() {
3939
}
4040

4141
fun VersionCatalogBuilder.discordLibs() {
42-
library("jda", "net.dv8tion", "JDA").version("5.0.0-beta.11")
42+
library("jda", "net.dv8tion", "JDA").version("5.1.0")
4343
library("d4j", "com.discord4j", "discord4j-core").version("3.2.3")
4444
}
4545

src/main/kotlin/dev/arbjerg/lavalink/internal/LavalinkSocket.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class LavalinkSocket(private val node: LavalinkNode) : WebSocketListener(), Clos
3838

3939
override fun onOpen(webSocket: WebSocket, response: Response) {
4040
logger.info("${node.name} has been connected!")
41-
node.available = true
4241
open = true
4342
reconnectsAttempted = 0
4443
}
@@ -52,6 +51,7 @@ class LavalinkSocket(private val node: LavalinkNode) : WebSocketListener(), Clos
5251
Message.Op.Ready -> {
5352
val sessionId = (event as Message.ReadyEvent).sessionId
5453
node.sessionId = sessionId
54+
node.available = true
5555
logger.info("${node.name} is ready with session id $sessionId")
5656

5757
node.playerCache.values.forEach { player ->

testbot/src/main/java/me/duncte123/testbot/JDAListener.java

+25
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ public void onReady(@NotNull ReadyEvent event) {
6868
"The identifier of the song you want to play",
6969
true
7070
),
71+
Commands.slash("play-file", "Play a song from a file")
72+
.addOption(
73+
OptionType.ATTACHMENT,
74+
"file",
75+
"the file to play",
76+
true
77+
),
7178
Commands.slash("karaoke", "Turn karaoke on or off")
7279
.addSubcommands(
7380
new SubcommandData("on", "Turn karaoke on"),
@@ -214,6 +221,24 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even
214221

215222
break;
216223
}
224+
case "play-file": {
225+
// We are already connected, go ahead and play
226+
if (guild.getSelfMember().getVoiceState().inAudioChannel()) {
227+
event.deferReply(false).queue();
228+
} else {
229+
// Connect to VC first
230+
joinHelper(event);
231+
}
232+
233+
final var file = event.getOption("file").getAsAttachment();
234+
final long guildId = guild.getIdLong();
235+
final Link link = this.client.getOrCreateLink(guildId);
236+
final var mngr = this.getOrCreateMusicManager(guildId);
237+
238+
link.loadItem(file.getUrl()).subscribe(new AudioLoader(event, mngr));
239+
240+
break;
241+
}
217242
// Required plugin: https://github.com/DuncteBot/java-timed-lyrics
218243
case "lyrics": {
219244
final Link link = this.client.getOrCreateLink(guild.getIdLong());

testbot/src/main/java/me/duncte123/testbot/Main.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,21 @@ public static void main(String[] args) throws InterruptedException {
6565

6666
private static void registerLavalinkNodes(LavalinkClient client) {
6767
List.of(
68-
client.addNode(
69-
new NodeOptions.Builder()
70-
.setName("optiplex")
71-
.setServerUri("ws://optiplex.local.duncte123.lgbt")
72-
.setPassword("youshallnotpass")
73-
.build()
74-
),
75-
68+
// client.addNode(
69+
// new NodeOptions.Builder()
70+
// .setName("localhost")
71+
// .setServerUri("ws://localhost")
72+
// .setPassword("youshallnotpass")
73+
// .build()
74+
// )
75+
// client.addNode(
76+
// new NodeOptions.Builder()
77+
// .setName("optiplex")
78+
// .setServerUri("ws://optiplex.local.duncte123.lgbt")
79+
// .setPassword("youshallnotpass")
80+
// .build()
81+
// ),
82+
//
7683
client.addNode(
7784
new NodeOptions.Builder()
7885
.setName("pi")

0 commit comments

Comments
 (0)