feat: schedule rework
This commit is contained in:
+20
-11
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user