mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-05 06:26:08 +00:00
diamondburned
b8994ed0da
This commit gets rid of all the code that previously managed different voice sessions in different guilds. This is because there is rarely ever a need for this, and most bots that need this could do their own keeping. This change, although removes some features off of the package, adds a lot of clarity on what to do exactly when it comes to connecting to a voice channel. In order to make the migration process a bit easier, an example has been added which guides through using the voice.Session API.
71 lines
1.3 KiB
Go
71 lines
1.3 KiB
Go
// +build !unitonly
|
|
|
|
package voice_test
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"testing"
|
|
|
|
"github.com/diamondburned/arikawa/v2/discord"
|
|
"github.com/diamondburned/arikawa/v2/internal/testenv"
|
|
"github.com/diamondburned/arikawa/v2/state"
|
|
"github.com/diamondburned/arikawa/v2/voice"
|
|
)
|
|
|
|
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() {
|
|
s, err := state.New("Bot " + token)
|
|
if err != nil {
|
|
log.Fatalln("failed to make state:", err)
|
|
}
|
|
|
|
// This is required for bots.
|
|
voice.AddIntents(s.Gateway)
|
|
|
|
if err := s.Open(); err != nil {
|
|
log.Fatalln("failed to open gateway:", err)
|
|
}
|
|
defer s.Close()
|
|
|
|
c, err := s.Channel(channelID)
|
|
if err != nil {
|
|
log.Fatalln("failed to get channel:", err)
|
|
}
|
|
|
|
v, err := voice.NewSession(s)
|
|
if err != nil {
|
|
log.Fatalln("failed to create voice session:", err)
|
|
}
|
|
|
|
if err := v.JoinChannel(c.GuildID, c.ID, false, false); err != nil {
|
|
log.Fatalln("failed to join voice channel:", err)
|
|
}
|
|
defer v.Leave()
|
|
|
|
// Start writing Opus frames.
|
|
for {
|
|
writeOpusInto(v)
|
|
}
|
|
}
|