mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-07-14 17:36:13 +00:00
This commit refactors a lot of voice's internals to be more stable and handle more edge cases from Discord's voice servers. It should result in an overall more stable voice connection. A few helper functions have been added into voice.Session. Some fields will have been broken and changed to accomodate for the refactor, as well. Below are some commits that have been squashed in: voice: Fix Speaking() panic on closed voice: StopSpeaking should not error out The rationale is added as a comment into the Speaking() method. voice: Add TestKickedOut voice: Fix region change disconnecting
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package voice_test
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"testing"
|
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
"github.com/diamondburned/arikawa/v3/internal/testenv"
|
|
"github.com/diamondburned/arikawa/v3/state"
|
|
"github.com/diamondburned/arikawa/v3/voice"
|
|
"github.com/diamondburned/arikawa/v3/voice/testdata"
|
|
)
|
|
|
|
var (
|
|
token string
|
|
channelID discord.ChannelID
|
|
)
|
|
|
|
func init() {
|
|
e, err := testenv.GetEnv()
|
|
if err == nil {
|
|
token = e.BotToken
|
|
channelID = e.VoiceChID
|
|
}
|
|
}
|
|
|
|
// make godoc not show the full file
|
|
func TestNoop(t *testing.T) {
|
|
t.Skip("noop")
|
|
}
|
|
|
|
func ExampleSession() {
|
|
s := state.New("Bot " + token)
|
|
|
|
// This is required for bots.
|
|
voice.AddIntents(s)
|
|
|
|
if err := s.Open(context.TODO()); err != nil {
|
|
log.Fatalln("failed to open gateway:", err)
|
|
}
|
|
defer s.Close()
|
|
|
|
v, err := voice.NewSession(s)
|
|
if err != nil {
|
|
log.Fatalln("failed to create voice session:", err)
|
|
}
|
|
|
|
if err := v.JoinChannel(context.TODO(), channelID, false, false); err != nil {
|
|
log.Fatalln("failed to join voice channel:", err)
|
|
}
|
|
defer v.Leave(context.TODO())
|
|
|
|
if err := testdata.WriteOpus(v, "testdata/nico.dca"); err != nil {
|
|
log.Fatalln("failed to write opus:", err)
|
|
}
|
|
}
|