2020-12-01 01:49:18 +00:00
|
|
|
package voice_test
|
|
|
|
|
|
|
|
import (
|
2021-06-10 23:48:32 +00:00
|
|
|
"context"
|
2020-12-01 01:49:18 +00:00
|
|
|
"log"
|
2022-01-19 02:22:27 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2020-12-01 01:49:18 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-06-02 02:53:19 +00:00
|
|
|
"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"
|
2021-07-02 09:42:00 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/voice/testdata"
|
2020-12-01 01:49:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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() {
|
2022-01-19 02:22:27 +00:00
|
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
|
|
|
defer cancel()
|
|
|
|
|
2021-09-28 20:19:04 +00:00
|
|
|
s := state.New("Bot " + token)
|
2020-12-01 01:49:18 +00:00
|
|
|
|
|
|
|
// This is required for bots.
|
2021-09-28 20:19:04 +00:00
|
|
|
voice.AddIntents(s)
|
2020-12-01 01:49:18 +00:00
|
|
|
|
2022-01-19 02:22:27 +00:00
|
|
|
if err := s.Open(ctx); err != nil {
|
2020-12-01 01:49:18 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-01-19 02:22:27 +00:00
|
|
|
if err := v.JoinChannelAndSpeak(ctx, channelID, false, false); err != nil {
|
2020-12-01 01:49:18 +00:00
|
|
|
log.Fatalln("failed to join voice channel:", err)
|
|
|
|
}
|
2022-01-19 02:22:27 +00:00
|
|
|
defer v.Leave(ctx)
|
2020-12-01 01:49:18 +00:00
|
|
|
|
2021-07-02 09:42:00 +00:00
|
|
|
if err := testdata.WriteOpus(v, "testdata/nico.dca"); err != nil {
|
|
|
|
log.Fatalln("failed to write opus:", err)
|
2020-12-01 01:49:18 +00:00
|
|
|
}
|
|
|
|
}
|