Documentation ¶
Index ¶
- Constants
- Variables
- type CpuStats
- type EventHandler
- type EventInterfaceProvider
- type Exception
- type FrameStats
- type Lavalink
- func (l *Lavalink) AddCapability(key string, i interface{})
- func (l *Lavalink) AddHandler(handler interface{}) func()
- func (l *Lavalink) AddHandlerOnce(handler interface{}) func()
- func (l *Lavalink) AddNodes(nodeConfigs ...NodeConfig) error
- func (l *Lavalink) BestNode() (*Node, error)
- func (l *Lavalink) GetPlayer(guild string) (*Player, error)
- type MemoryStats
- type Node
- type NodeConfig
- type Player
- func (player *Player) ChangeNode(node *Node) error
- func (player *Player) Destroy() error
- func (player *Player) Forward(sessionID string, event VoiceServerUpdate) error
- func (player *Player) GetVolume() int
- func (player *Player) GuildID() string
- func (player *Player) Listen(userId string, override bool) error
- func (player *Player) Pause(pause bool) error
- func (player *Player) Paused() bool
- func (player *Player) Play(track string) error
- func (player *Player) PlayAt(track string, startTime int, endTime int) error
- func (player *Player) Position() int
- func (player *Player) Seek(position int) error
- func (player *Player) Stop() error
- func (player *Player) Track() string
- func (player *Player) UserJoin(userId string) error
- func (player *Player) UserLeave(userId string) error
- func (player *Player) Volume(volume int) error
- type PlaylistInfo
- type RemoteStats
- type Track
- type TrackEnd
- type TrackException
- type TrackInfo
- type TrackStart
- type TrackStuck
- type Tracks
- type VoiceProcessed
- type VoiceProcessingData
- type VoiceServerUpdate
- type WebSocketClosed
Constants ¶
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 CpuStats ¶ added in v0.1.2
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
Exception is a message from the Lavalink server
type FrameStats ¶ added in v0.1.2
type Lavalink ¶
type Lavalink struct { BestNodeFunc func([]*Node) (*Node, error) // contains filtered or unexported fields }
Lavalink manages a connection to Lavalink Nodes
func NewLavalink ¶
NewLavalink creates a new Lavalink manager
func (*Lavalink) AddCapability ¶ added in v0.1.2
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 ¶
BestNode returns the Node with the lowest latency
type MemoryStats ¶ added in v0.1.2
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) (*Player, error)
CreatePlayer creates an audio player on this node
func (*Node) LoadTracks ¶
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) 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 ¶
GetVolume gets the player's volume level
func (*Player) GuildID ¶
GuildID returns this player's Guild ID
func (*Player) Listen ¶
Listen will override the listening settings for the user
func (*Player) Pause ¶
Pause will pause or resume the player, depending on the pause parameter
func (*Player) Paused ¶
Paused returns whether or not the player is currently paused
func (*Player) Play ¶
Play will play the given track completely
func (*Player) PlayAt ¶
PlayAt will play the given track at the specified start and end times
Setting a time to 0 will omit it.
func (*Player) Position ¶
Position returns the player's position, as reported by Lavalink
func (*Player) Seek ¶
Seek will seek the player to the speicifed position, in millis
func (*Player) Track ¶
Track returns the player's current track
func (*Player) UserJoin ¶
Join will notify the player that a user has joined the channel
func (*Player) UserLeave ¶
Leave will notify the player that a user has left the channel
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
Event for when a track ends.
type TrackException ¶ added in v1.0.0
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 DecodeString ¶
DecodeString decodes a base64 Lavaplayer string to a TrackInfo
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
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