fix(lavalink): Update Lavalink configuration and enhance healthcheck with plugin management

This commit is contained in:
Jose Daniel G. Percy 2025-04-24 01:50:06 +08:00
parent ca9e531541
commit 8f8ff6aa81
3 changed files with 39 additions and 15 deletions

View File

@ -22,8 +22,8 @@ lavalink:
bufferDurationMs: 400
frameBufferDurationMs: 5000
gc-warnings: true
plugins:
- dependency: "dev.lavalink.youtube:youtube-plugin:1.12.0" # Use the new YouTube source plugin
# Removed dependency plugin loading
pluginsDir: "/plugins" # Specify directory for manually loaded plugins
plugins:
youtube:
@ -37,4 +37,4 @@ plugins:
- MUSIC
- ANDROID_VR
- WEB
- WEBEMBEDDED
- WEBEMBEDDED

View File

@ -8,17 +8,38 @@ services:
ports:
- "2333:2333"
environment:
- LAVALINK_SERVER_PASSWORD=${LAVALINK_PASSWORD}
LAVALINK_SERVER_PASSWORD: ${LAVALINK_PASSWORD}
# Add environment variable for plugin URLs (using the format you provided)
LAVALINK_PLUGIN_URLS: |
https://github.com/lavalink-devs/youtube-source/releases/download/1.12.0/youtube-plugin-1.12.0.jar
volumes:
- ./application.yml:/opt/Lavalink/application.yml:ro,Z
# Optional: Persist downloaded plugins if needed, though downloading on start is fine
# - lavalink-plugins:/plugins
# Add healthcheck to verify Lavalink is ready
healthcheck:
test: >
curl -H "Authorization: ${LAVALINK_PASSWORD}" -f http://localhost:2333/version
interval: 5s
# Use CMD-SHELL to allow environment variable expansion for the password
test: ["CMD-SHELL", "curl -H \"Authorization: $$LAVALINK_SERVER_PASSWORD\" -f http://localhost:2333/version || exit 1"]
interval: 10s # Increased interval slightly
timeout: 5s
retries: 3
start_period: 5s # Give Lavalink time to start up initially
retries: 5
start_period: 15s # Give Lavalink time to start up initially
# Override entrypoint/command to download plugins first
command: >
sh -c "
apk add --no-cache curl && \
mkdir -p /plugins && \
echo 'Downloading Lavalink plugins...' && \
echo \"$$LAVALINK_PLUGIN_URLS\" | while IFS= read -r url; do \
if [ -n \"$$url\" ]; then \
filename=$(basename \"$$url\") && \
echo \"Downloading $$url to /plugins/$$filename\" && \
curl -L -o \"/plugins/$$filename\" \"$$url\"; \
fi \
done && \
echo 'Downloads complete. Starting Lavalink...' && \
java -jar Lavalink.jar
"
bot:
build: .
@ -29,9 +50,9 @@ services:
env_file:
- .env
environment:
- LAVALINK_HOST=lavalink
- LAVALINK_PORT=2333
- LAVALINK_PASSWORD=${LAVALINK_PASSWORD}
LAVALINK_HOST: lavalink
LAVALINK_PORT: 2333
LAVALINK_PASSWORD: ${LAVALINK_PASSWORD}
# Update depends_on to wait for healthcheck
depends_on:
lavalink:

View File

@ -102,9 +102,12 @@ class MusicPlayer {
// Destroy the player and disconnect
destroy() {
this.client.shoukaku.leaveVoiceChannel(this.guild);
musicPlayer.players.delete(this.guild);
return this;
// Use the main Shoukaku instance to leave the channel
this.client.shoukaku.leaveVoiceChannel(this.guild);
// Remove the player instance from the manager's map
musicPlayer.players.delete(this.guild);
logger.debug(`Destroyed player for guild ${this.guild}`);
return this; // Return this for potential chaining, though unlikely needed here
},
// Add a track to the queue or play it if nothing is playing