1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-09-19 00:19:59 +00:00
arikawa/internal/testenv/testenv.go
diamondburned b8994ed0da Voice: Remove state-keeping of sessions
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.
2020-11-30 19:12:20 -08:00

76 lines
1.1 KiB
Go

// +build !uintonly
package testenv
import (
"os"
"sync"
"testing"
"github.com/diamondburned/arikawa/v2/discord"
"github.com/pkg/errors"
)
type Env struct {
BotToken string
ChannelID discord.ChannelID
VoiceChID discord.ChannelID
}
var (
env Env
err error
once sync.Once
)
func Must(t *testing.T) Env {
e, err := GetEnv()
if err != nil {
t.Fatal(err)
}
return e
}
func GetEnv() (Env, error) {
once.Do(getEnv)
return env, err
}
func getEnv() {
var token = os.Getenv("BOT_TOKEN")
if token == "" {
err = errors.New("missing $BOT_TOKEN")
return
}
var cid = os.Getenv("CHANNEL_ID")
if cid == "" {
err = errors.New("missing $CHANNEL_ID")
return
}
id, err := discord.ParseSnowflake(cid)
if err != nil {
err = errors.Wrap(err, "invalid $CHANNEL_ID")
return
}
var sid = os.Getenv("VOICE_ID")
if sid == "" {
err = errors.New("missing $VOICE_ID")
return
}
vid, err := discord.ParseSnowflake(sid)
if err != nil {
err = errors.Wrap(err, "invalid $VOICE_ID")
return
}
env = Env{
BotToken: token,
ChannelID: discord.ChannelID(id),
VoiceChID: discord.ChannelID(vid),
}
}