gavalink

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: ISC Imports: 22 Imported by: 0

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

View Source
var Log *log.Logger

Log sets the log.Logger gavalink will write to

Functions

This section is empty.

Types

type CpuStats added in v0.1.2

type CpuStats struct {
	Cores        int     `json:"cores"`
	SystemLoad   float64 `json:"systemLoad"`
	LavalinkLoad float64 `json:"lavalinkLoad"`
}

type EventHandler

type EventHandler interface {
	// Type returns the type of event this handler belongs to.
	Type() string

	// Handle is called whenever an event of Type() happens.
	// It is the receivers responsibility to type assert that the interface
	// is the expected struct.
	Handle(*Player, interface{})
}

EventHandler is an interface for Lavalink events.

type EventInterfaceProvider added in v1.0.0

type EventInterfaceProvider interface {
	// Type is the type of event this handler belongs to.
	Type() string

	// New returns a new instance of the struct this event handler handles.
	// This is called once per event.
	// The struct is provided to all handlers of the same Type().
	New() interface{}
}

EventInterfaceProvider is an interface for providing empty interfaces for Lavalink events.

type Exception added in v1.0.0

type Exception struct {
	Message  string
	Severity string
	Cause    string
}

Exception is a message from the Lavalink server

type FrameStats added in v0.1.2

type FrameStats struct {
	Sent    int `json:"sent"`
	Nulled  int `json:"nulled"`
	Deficit int `json:"deficit"`
}
type Lavalink struct {
	BestNodeFunc func([]*Node) (*Node, error)
	// contains filtered or unexported fields
}

Lavalink manages a connection to Lavalink Nodes

func NewLavalink(shards int, userID string) *Lavalink

NewLavalink creates a new Lavalink manager

func (*Lavalink) AddCapability added in v0.1.2

func (l *Lavalink) AddCapability(key string, i interface{})

Add capabilities mappings to the client, letting the server know what we support

func (*Lavalink) AddHandler added in v1.0.0

func (l *Lavalink) AddHandler(handler interface{}) func()

AddHandler allows you to add an event handler that will be fired anytime the Lavalink event that matches the function fires. The first parameter is a *Session, and the second parameter is a pointer to a struct corresponding to the event for which you want to listen.

eg:

Player.AddHandler(func(s *gavalink.Player, m *gavalink.TrackStart) {
})

or:

Player.AddHandler(func(s *gavalink.Player, m *gavalink.TrackEnd) {
})

The return value of this method is a function, that when called will remove the event handler.

func (*Lavalink) AddHandlerOnce added in v1.0.0

func (l *Lavalink) AddHandlerOnce(handler interface{}) func()

AddHandlerOnce allows you to add an event handler that will be fired the next time the Lavalink event that matches the function fires. See AddHandler for more details.

func (*Lavalink) AddNodes

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

AddNodes adds a node to the Lavalink manager This function calls all of the node connect methods at once. TODO perhaps add a pool/max at a time limit?

func (*Lavalink) BestNode

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

BestNode returns the Node with the lowest latency

func (*Lavalink) GetPlayer

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

GetPlayer gets a player for a guild

type MemoryStats added in v0.1.2

type MemoryStats struct {
	Free        uint64 `json:"free"`
	Used        uint64 `json:"used"`
	Allocated   uint64 `json:"allocated"`
	Reserveable uint64 `json:"reserveable"`
}

type Node

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

Node wraps a Lavalink Node

func BestNodeByLoad added in v0.1.1

func BestNodeByLoad(n []*Node) (*Node, error)

func BestNodeByPenalties added in v0.1.2

func BestNodeByPenalties(nodes []*Node) (*Node, error)

func (*Node) CreatePlayer

func (node *Node) CreatePlayer(guildID string, sessionID string, event VoiceServerUpdate) (*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 {
	// Node identifier (uuid, hostname, etc)
	Identifier string

	// 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) ChangeNode added in v0.1.1

func (player *Player) ChangeNode(node *Node) error

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) Listen

func (player *Player) Listen(userId string, override bool) error

Listen will override the listening settings for the user

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) UserJoin

func (player *Player) UserJoin(userId string) error

Join will notify the player that a user has joined the channel

func (*Player) UserLeave

func (player *Player) UserLeave(userId string) error

Leave will notify the player that a user has left the channel

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 RemoteStats added in v0.1.2

type RemoteStats struct {
	Op            string       `json:"op"`
	Players       int          `json:"players"`
	ActivePlayers int          `json:"playingPlayers"`
	Uptime        int64        `json:"uptime"`
	Memory        *MemoryStats `json:"memory"`
	Cpu           *CpuStats    `json:"cpu"`
	Frames        *FrameStats  `json:"frameStats"`
}

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 TrackEnd added in v1.0.0

type TrackEnd struct {
	Track  string
	Reason string
}

Event for when a track ends.

type TrackException added in v1.0.0

type TrackException struct {
	Track     string
	Error     string
	Exception Exception
}

Event for when a track encounters an error in playback.

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     time.Duration `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

func (*TrackInfo) MarshalJSON added in v0.2.0

func (t *TrackInfo) MarshalJSON() ([]byte, error)

func (*TrackInfo) UnmarshalJSON added in v0.2.0

func (t *TrackInfo) UnmarshalJSON(data []byte) error

type TrackStart added in v1.0.0

type TrackStart struct {
	Track string
}

Event for when a track starts playing

type TrackStuck added in v1.0.0

type TrackStuck struct {
	Track     string
	Threshold time.Duration
}

Event when a track gets stuck

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 VoiceProcessed added in v1.0.0

type VoiceProcessed struct {
	Data     *VoiceProcessingData
	Hotword  bool
	Override bool
}

Event for when voice is processed and sent back to the client.

type VoiceProcessingData

type VoiceProcessingData struct {
	io.ReadCloser

	UserID string
	URL    string
	File   string
	// contains filtered or unexported fields
}

VoiceProcessingData is an event containing methods to easily download captured voice data

func (*VoiceProcessingData) Close

func (v *VoiceProcessingData) Close() error

func (*VoiceProcessingData) Read

func (v *VoiceProcessingData) Read(buf []byte) (n int, err error)

func (*VoiceProcessingData) SaveTo

func (v *VoiceProcessingData) SaveTo(file string) error

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

type WebSocketClosed added in v1.0.0

type WebSocketClosed struct {
	Code     int
	Reason   string
	ByRemote bool
}

Event fired when the websocket is closed.

Directories

Path Synopsis
tools
cmd

Jump to

Keyboard shortcuts

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