feat: schedule rework

This commit is contained in:
2026-08-18 19:22:21 +01:00
parent 483dc666d1
commit 5024af2789
13 changed files with 997 additions and 392 deletions
+20 -11
View File
@@ -3,6 +3,7 @@ package music
import (
"context"
"fmt"
"log"
"net/url"
"sync"
"time"
@@ -67,18 +68,26 @@ func Init(session *discordgo.Session, appID, lavalinkHost, lavalinkPass string)
password = "youshallnotpass"
}
_, err = m.client.AddNode(context.Background(), disgolink.NodeConfig{
Name: "main",
Address: u.Host,
Password: password,
Secure: secure,
})
if err != nil {
return fmt.Errorf("add lavalink node: %w", err)
}
// Connecting to the Lavalink node is a blocking network call (and, on
// failure, disgolink retries indefinitely with backoff) — do it in the
// background so bot startup isn't held hostage by it. Music commands
// simply fail with "not initialized" via the manager==nil checks until
// this completes.
go func() {
_, err := m.client.AddNode(context.Background(), disgolink.NodeConfig{
Name: "main",
Address: u.Host,
Password: password,
Secure: secure,
})
if err != nil {
log.Printf("music: failed to connect to lavalink node: %v", err)
return
}
manager = m
go idleDisconnectLoop()
}()
manager = m
go idleDisconnectLoop()
return nil
}