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
|
|
|
"io"
|
|
|
|
"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"
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pseudo function for example
|
|
|
|
func writeOpusInto(w io.Writer) {}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
// Start writing Opus frames.
|
|
|
|
for {
|
|
|
|
writeOpusInto(v)
|
|
|
|
}
|
|
|
|
}
|