gavalink

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2019 License: ISC Imports: 14 Imported by: 1

README

Build Status

lavalink wrapper for Go

Requirements

  • Go 1.10+
  • Lavalink v3+

License

Licensed under ISC. See the full license.

Documentation

Index

Constants

View Source
const (
	// TrackLoaded is a Tracks Type for a succesful single track load
	TrackLoaded = "TRACK_LOADED"
	// PlaylistLoaded is a Tracks Type for a succseful playlist load
	PlaylistLoaded = "PLAYLIST_LOADED"
	// SearchResult is a Tracks Type for a search containing many tracks
	SearchResult = "SEARCH_RESULT"
	// NoMatches is a Tracks Type for a query yielding no matches
	NoMatches = "NO_MATCHES"
	// LoadFailed is a Tracks Type for an internal Lavalink error
	LoadFailed = "LOAD_FAILED"
)

Variables

Log sets the log.Logger gavalink will write to

Functions

This section is empty.

Types

type DummyEventHandler

type DummyEventHandler struct{}

DummyEventHandler provides an empty event handler for users who wish to drop events outright. This is not recommended.

func (DummyEventHandler) OnTrackEnd

func (d DummyEventHandler) OnTrackEnd(player *Player, track string, reason string) error

OnTrackEnd is raised when a track ends

func (DummyEventHandler) OnTrackException

func (d DummyEventHandler) OnTrackException(player *Player, track string, reason string) error

OnTrackException is raised when a track throws an exception

func (DummyEventHandler) OnTrackStuck

func (d DummyEventHandler) OnTrackStuck(player *Player, track string, threshold int) error

OnTrackStuck is raised when a track gets stuck

type EventHandler

type EventHandler interface {
	OnTrackEnd(player *Player, track string, reason string) error
	OnTrackException(player *Player, track string, reason string) error
	OnTrackStuck(player *Player, track string, threshold int) error
}

EventHandler defines events that Lavalink may send to a player

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

Lavalink manages a connection to Lavalink Nodes

func NewLavalink(shards string, userID string) *Lavalink

NewLavalink creates a new Lavalink manager

func (*Lavalink) AddNodes

func (lavalink *Lavalink) AddNodes(nodeConfigs ...NodeConfig) error

AddNodes adds a node to the Lavalink manager

func (*Lavalink) BestNode

func (lavalink *Lavalink) BestNode() (*Node, error)

BestNode returns the Node with the lowest latency

func (*Lavalink) GetPlayer

func (lavalink *Lavalink) GetPlayer(guild string) (*Player, error)

GetPlayer gets a player for a guild

type Node

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

Node wraps a Lavalink Node

func (*Node) CreatePlayer

func (node *Node) CreatePlayer(guildID string, sessionID string, event VoiceServerUpdate, handler EventHandler) (*Player, error)

CreatePlayer creates an audio player on this node

func (*Node) LoadTracks

func (node *Node) LoadTracks(query string) (*Tracks, error)

LoadTracks queries lavalink to return a Tracks object

query should be a valid Lavaplayer query, including but not limited to: - A direct media URI - A direct Youtube /watch URI - A search query, prefixed with ytsearch: or scsearch:

See the Lavaplayer Source Code for all valid options.

type NodeConfig

type NodeConfig struct {
	// REST is the host where Lavalink's REST server runs
	//
	// This value is expected without a trailing slash, e.g. like
	// `http://localhost:2333`
	REST string
	// WebSocket is the host where Lavalink's WebSocket server runs
	//
	// This value is expected without a trailing slash, e.g. like
	// `http://localhost:8012`
	WebSocket string
	// Password is the expected Authorization header for the Node
	Password string
}

NodeConfig configures a Lavalink Node

type Player

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

Player is a Lavalink player

func (*Player) Destroy

func (player *Player) Destroy() error

Destroy will destroy this player

func (*Player) Forward

func (player *Player) Forward(sessionID string, event VoiceServerUpdate) error

Forward will forward a new VOICE_SERVER_UPDATE to a Lavalink node for this player.

This should always be used if a VOICE_SERVER_UPDATE is received for a guild which already has a player.

To move a player to a new Node, first player.Destroy() it, and then create a new player on the new node.

func (*Player) GetVolume

func (player *Player) GetVolume() int

GetVolume gets the player's volume level

func (*Player) GuildID

func (player *Player) GuildID() string

GuildID returns this player's Guild ID

func (*Player) Pause

func (player *Player) Pause(pause bool) error

Pause will pause or resume the player, depending on the pause parameter

func (*Player) Paused

func (player *Player) Paused() bool

Paused returns whether or not the player is currently paused

func (*Player) Play

func (player *Player) Play(track string) error

Play will play the given track completely

func (*Player) PlayAt

func (player *Player) PlayAt(track string, startTime int, endTime int) error

PlayAt will play the given track at the specified start and end times

Setting a time to 0 will omit it.

func (*Player) Position

func (player *Player) Position() int

Position returns the player's position, as reported by Lavalink

func (*Player) Seek

func (player *Player) Seek(position int) error

Seek will seek the player to the speicifed position, in millis

func (*Player) Stop

func (player *Player) Stop() error

Stop will stop the currently playing track

func (*Player) Track

func (player *Player) Track() string

Track returns the player's current track

func (*Player) Volume

func (player *Player) Volume(volume int) error

Volume will set the player's volume to the specified value

volume must be within [0, 1000]

type PlaylistInfo

type PlaylistInfo struct {
	// Name is the friendly of the playlist
	Name string `json:"name"`
	// SelectedTrack is the index of the track that loaded the playlist,
	// if one is present.
	SelectedTrack int `json:"selectedTrack"`
}

PlaylistInfo contains information about a loaded playlist

type Track

type Track struct {
	// Data contains the base64 encoded Lavaplayer track
	Data string    `json:"track"`
	Info TrackInfo `json:"info"`
}

Track contains information about a loaded track

type TrackInfo

type TrackInfo struct {
	Identifier string `json:"identifier"`
	Title      string `json:"title"`
	Author     string `json:"author"`
	URI        string `json:"uri"`
	Seekable   bool   `json:"isSeekable"`
	Stream     bool   `json:"isStream"`
	Length     int    `json:"length"`
	Position   int    `json:"position"`
}

TrackInfo contains more data about a loaded track

func Decode

func Decode(r io.Reader) (*TrackInfo, error)

Decode decodes a reader into a TrackInfo

func DecodeString

func DecodeString(data string) (*TrackInfo, error)

DecodeString decodes a base64 Lavaplayer string to a TrackInfo

type Tracks

type Tracks struct {
	// Type contains the type of response
	//
	// This will be one of TrackLoaded, PlaylistLoaded, SearchResult,
	// NoMatches, or LoadFailed
	Type         string        `json:"loadType"`
	PlaylistInfo *PlaylistInfo `json:"playlistInfo"`
	Tracks       []Track       `json:"tracks"`
}

Tracks contains data for a Lavalink Tracks response

type VoiceServerUpdate

type VoiceServerUpdate struct {
	GuildID  string `json:"guild_id"`
	Endpoint string `json:"endpoint"`
	Token    string `json:"token"`
}

VoiceServerUpdate is a raw Discord VOICE_SERVER_UPDATE event

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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