disgolink

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2023 License: Apache-2.0 Imports: 16 Imported by: 13

Documentation

Index

Constants

View Source
const (
	Name   = "disgolink"
	Module = "github.com/disgoorg/disgolink/v3"
	GitHub = "https://github.com/disgoorg/disgo"
)

Variables

View Source
var (
	EndpointBase    Endpoint = "/v4"
	EndpointVersion Endpoint = "/version"
	EndpointInfo             = EndpointBase + "/info"
	EndpointStats            = EndpointBase + "/stats"

	EndpointUpdateSession = EndpointBase + "/sessions/%s"
	EndpointPlayers       = EndpointBase + "/sessions/%s/players"
	EndpointPlayer        = EndpointBase + "/sessions/%s/players/%s"
	EndpointUpdatePlayer  = EndpointBase + "/sessions/%s/players/%s?noReplace=%t"
	EndpointDestroyPlayer = EndpointBase + "/sessions/%s/players/%s"

	EndpointLoadTracks   = EndpointBase + "/loadtracks?identifier=%s"
	EndpointDecodeTrack  = EndpointBase + "/decodetrack?track=%s"
	EndpointDecodeTracks = EndpointBase + "/decodetracks"

	EndpointWebSocket = EndpointBase + "/websocket"
)
View Source
var ErrNodeAlreadyConnected = errors.New("node already connected")
View Source
var ErrPlayerNoNode = errors.New("player has no node")
View Source
var (
	Version = getVersion()
)

Functions

This section is empty.

Types

type AudioLoadResultHandler

type AudioLoadResultHandler interface {
	TrackLoaded(track lavalink.Track)
	PlaylistLoaded(playlist lavalink.Playlist)
	SearchResultLoaded(tracks []lavalink.Track)
	NoMatches()
	LoadFailed(err error)
}

func NewResultHandler

func NewResultHandler(trackLoaded func(track lavalink.Track), playlistLoaded func(playlist lavalink.Playlist), searchResultLoaded func(tracks []lavalink.Track), noMatches func(), loadFailed func(err error)) AudioLoadResultHandler

type Client

type Client interface {
	AddNode(ctx context.Context, config NodeConfig) (Node, error)
	ForNodes(nodeFunc func(node Node))
	Node(name string) Node
	BestNode() Node
	RemoveNode(name string)

	Player(guildID snowflake.ID) Player
	PlayerOnNode(node Node, guildID snowflake.ID) Player
	ExistingPlayer(guildID snowflake.ID) Player
	RemovePlayer(guildID snowflake.ID)
	ForPlayers(playerFunc func(player Player))

	EmitEvent(player Player, event lavalink.Message)
	AddListeners(listeners ...EventListener)
	RemoveListeners(listeners ...EventListener)

	AddPlugins(plugins ...Plugin)
	ForPlugins(pluginFunc func(plugin Plugin))
	RemovePlugins(plugins ...Plugin)

	UserID() snowflake.ID
	Close()

	OnVoiceServerUpdate(ctx context.Context, guildID snowflake.ID, token string, endpoint string)
	OnVoiceStateUpdate(ctx context.Context, guildID snowflake.ID, channelID *snowflake.ID, sessionID string)
}

func New

func New(userID snowflake.ID, opts ...ConfigOpt) Client

type Config

type Config struct {
	Logger     *slog.Logger
	HTTPClient *http.Client
	Listeners  []EventListener
	Plugins    []Plugin
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) Apply

func (c *Config) Apply(opts []ConfigOpt)

type ConfigOpt

type ConfigOpt func(config *Config)

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ConfigOpt

func WithListenerFunc

func WithListenerFunc[E lavalink.Message](listenerFunc func(p Player, e E)) ConfigOpt

func WithListeners

func WithListeners(listeners ...EventListener) ConfigOpt

func WithLogger

func WithLogger(logger *slog.Logger) ConfigOpt

WithLogger lets you inject your own logger implementing log.Logger

func WithPlugins

func WithPlugins(plugins ...Plugin) ConfigOpt

type Endpoint

type Endpoint string

func (Endpoint) Format

func (e Endpoint) Format(a ...any) string

type EventListener

type EventListener interface {
	OnEvent(player Player, event lavalink.Message)
}

func NewListenerFunc

func NewListenerFunc[E lavalink.Message](f func(p Player, e E)) EventListener

type EventPlugin

type EventPlugin interface {
	Event() lavalink.EventType
	OnEventInvocation(player Player, data []byte)
}

type EventPlugins

type EventPlugins interface {
	EventPlugins() []EventPlugin
}

type FunctionalResultHandler

type FunctionalResultHandler struct {
	// contains filtered or unexported fields
}

func (FunctionalResultHandler) LoadFailed

func (h FunctionalResultHandler) LoadFailed(err error)

func (FunctionalResultHandler) NoMatches

func (h FunctionalResultHandler) NoMatches()

func (FunctionalResultHandler) PlaylistLoaded

func (h FunctionalResultHandler) PlaylistLoaded(playlist lavalink.Playlist)

func (FunctionalResultHandler) SearchResultLoaded

func (h FunctionalResultHandler) SearchResultLoaded(tracks []lavalink.Track)

func (FunctionalResultHandler) TrackLoaded

func (h FunctionalResultHandler) TrackLoaded(track lavalink.Track)

type Node

type Node interface {
	Lavalink() Client
	Config() NodeConfig
	Rest() RestClient

	Stats() lavalink.Stats
	Status() Status
	SessionID() string

	Version(ctx context.Context) (string, error)
	Info(ctx context.Context) (*lavalink.Info, error)
	Update(ctx context.Context, update lavalink.SessionUpdate) error
	LoadTracks(ctx context.Context, identifier string) (*lavalink.LoadResult, error)
	LoadTracksHandler(ctx context.Context, identifier string, handler AudioLoadResultHandler)

	DecodeTrack(ctx context.Context, encodedTrack string) (*lavalink.Track, error)
	DecodeTracks(ctx context.Context, encodedTracks []string) ([]lavalink.Track, error)

	Open(ctx context.Context) error
	Close()
}

type NodeConfig

type NodeConfig struct {
	Name      string `json:"name"`
	Address   string `json:"address"`
	Password  string `json:"password"`
	Secure    bool   `json:"secure"`
	SessionID string `json:"session_id"`
}

func (NodeConfig) RestURL

func (c NodeConfig) RestURL() string

func (NodeConfig) WsURL

func (c NodeConfig) WsURL() string

type OpPlugin

type OpPlugin interface {
	Op() lavalink.Op
	OnOpInvocation(node Node, data []byte)
}

type Player

type Player interface {
	GuildID() snowflake.ID
	ChannelID() *snowflake.ID
	Track() *lavalink.Track
	Paused() bool
	Position() lavalink.Duration
	State() lavalink.PlayerState
	Volume() int
	Filters() lavalink.Filters

	Update(ctx context.Context, opts ...lavalink.PlayerUpdateOpt) error
	Destroy(ctx context.Context) error

	Lavalink() Client
	Node() Node

	Restore(player lavalink.Player)
	OnEvent(event lavalink.Event)
	OnPlayerUpdate(state lavalink.PlayerState)
	OnVoiceServerUpdate(ctx context.Context, token string, endpoint string)
	OnVoiceStateUpdate(ctx context.Context, channelID *snowflake.ID, sessionID string)
}

func NewPlayer

func NewPlayer(lavalink Client, node Node, guildID snowflake.ID) Player

type Plugin

type Plugin interface {
	Name() string
	Version() string
}

type PluginEventHandler

type PluginEventHandler interface {
	OnNodeOpen(node Node)
	OnNodeClose(node Node)
	OnNodeMessageIn(node Node, data []byte)
	OnNewPlayer(player Player)
	OnDestroyPlayer(player Player)
}

type RestClient

type RestClient interface {
	// Do executes a http.Request and replaces the host and scheme with the node's config. It also sets the Authorization header to the node's password. It returns the http.Response or an error
	Do(rq *http.Request) (*http.Response, error)

	Version(ctx context.Context) (string, error)
	Info(ctx context.Context) (*lavalink.Info, error)
	Stats(ctx context.Context) (*lavalink.Stats, error)

	UpdateSession(ctx context.Context, sessionID string, sessionUpdate lavalink.SessionUpdate) (*lavalink.Session, error)

	Players(ctx context.Context, sessionID string) ([]lavalink.Player, error)
	Player(ctx context.Context, sessionID string, guildID snowflake.ID) (*lavalink.Player, error)
	UpdatePlayer(ctx context.Context, sessionID string, guildID snowflake.ID, playerUpdate lavalink.PlayerUpdate) (*lavalink.Player, error)
	DestroyPlayer(ctx context.Context, sessionID string, guildID snowflake.ID) error

	LoadTracks(ctx context.Context, identifier string) (*lavalink.LoadResult, error)
	DecodeTrack(ctx context.Context, encodedTrack string) (*lavalink.Track, error)
	DecodeTracks(ctx context.Context, encodedTracks []string) ([]lavalink.Track, error)
}

type Status

type Status string
const (
	StatusConnecting   Status = "CONNECTING"
	StatusConnected    Status = "CONNECTED"
	StatusReconnecting Status = "RECONNECTING"
	StatusDisconnected Status = "DISCONNECTED"
)

Indicates how far along the client is to connecting

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL