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 bufferDurationMs: 400
frameBufferDurationMs: 5000 frameBufferDurationMs: 5000
gc-warnings: true gc-warnings: true
plugins: # Removed dependency plugin loading
- dependency: "dev.lavalink.youtube:youtube-plugin:1.12.0" # Use the new YouTube source plugin pluginsDir: "/plugins" # Specify directory for manually loaded plugins
plugins: plugins:
youtube: youtube:

View File

@ -8,17 +8,38 @@ services:
ports: ports:
- "2333:2333" - "2333:2333"
environment: 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: volumes:
- ./application.yml:/opt/Lavalink/application.yml:ro,Z - ./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 # Add healthcheck to verify Lavalink is ready
healthcheck: healthcheck:
test: > # Use CMD-SHELL to allow environment variable expansion for the password
curl -H "Authorization: ${LAVALINK_PASSWORD}" -f http://localhost:2333/version test: ["CMD-SHELL", "curl -H \"Authorization: $$LAVALINK_SERVER_PASSWORD\" -f http://localhost:2333/version || exit 1"]
interval: 5s interval: 10s # Increased interval slightly
timeout: 5s timeout: 5s
retries: 3 retries: 5
start_period: 5s # Give Lavalink time to start up initially 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: bot:
build: . build: .
@ -29,9 +50,9 @@ services:
env_file: env_file:
- .env - .env
environment: environment:
- LAVALINK_HOST=lavalink LAVALINK_HOST: lavalink
- LAVALINK_PORT=2333 LAVALINK_PORT: 2333
- LAVALINK_PASSWORD=${LAVALINK_PASSWORD} LAVALINK_PASSWORD: ${LAVALINK_PASSWORD}
# Update depends_on to wait for healthcheck # Update depends_on to wait for healthcheck
depends_on: depends_on:
lavalink: lavalink:

View File

@ -102,9 +102,12 @@ class MusicPlayer {
// Destroy the player and disconnect // Destroy the player and disconnect
destroy() { destroy() {
// Use the main Shoukaku instance to leave the channel
this.client.shoukaku.leaveVoiceChannel(this.guild); this.client.shoukaku.leaveVoiceChannel(this.guild);
// Remove the player instance from the manager's map
musicPlayer.players.delete(this.guild); musicPlayer.players.delete(this.guild);
return this; 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 // Add a track to the queue or play it if nothing is playing