api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyTrack = errors.New("track is empty")
View Source
var ErrEmptyTrackInfo = errors.New("trackinfo is empty")
View Source
var SpotifyURIPattern = regexp.MustCompile("^spotify:(track|album|playlist):([a-zA-Z0-9-_]+)")
View Source
var SpotifyURLPattern = regexp.MustCompile("^(https?://)?(www\\.)?open\\.spotify\\.com/(track|album|playlist)/([a-zA-Z0-9-_]+)(\\?si=[a-zA-Z0-9-_]+)?")

SpotifyURLPattern is a spotify url pattern with regions to get track/album/playlist

View Source
var URLPattern = regexp.MustCompile("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]?")

URLPattern is a general url pattern

Functions

func EncodeToString

func EncodeToString(info TrackInfo) (str *string, err error)

Types

type AudioLoaderResultHandler

type AudioLoaderResultHandler interface {
	TrackLoaded(track Track)
	PlaylistLoaded(playlist *Playlist)
	SearchResultLoaded(tracks []Track)
	NoMatches()
	LoadFailed(e *Exception)
}

func NewResultHandler

func NewResultHandler(trackLoaded func(track Track), playlistLoaded func(playlist *Playlist), searchResultLoaded func(tracks []Track), noMatches func(), loadFailed func(e *Exception)) AudioLoaderResultHandler

type CPU

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

type DefaultTrack

type DefaultTrack struct {
	Track_ *string           `json:"track"`
	Info_  *DefaultTrackInfo `json:"info"`
}

func (*DefaultTrack) DecodeInfo

func (t *DefaultTrack) DecodeInfo() (err error)

func (*DefaultTrack) EncodeInfo

func (t *DefaultTrack) EncodeInfo() (err error)

func (*DefaultTrack) Info

func (t *DefaultTrack) Info() TrackInfo

func (*DefaultTrack) Track

func (t *DefaultTrack) Track() *string

type DefaultTrackInfo

type DefaultTrackInfo struct {
	Identifier_ string  `json:"identifier"`
	IsSeekable_ bool    `json:"isSeekable"`
	Author_     string  `json:"author"`
	Length_     int     `json:"length"`
	IsStream_   bool    `json:"isStream"`
	Position_   int     `json:"position"`
	Title_      string  `json:"title"`
	URI_        *string `json:"uri"`
	SourceName_ string  `json:"sourceName"`
}

func DecodeString

func DecodeString(str string) (info *DefaultTrackInfo, err error)

DecodeString thx to https://github.com/foxbot/gavalink/blob/master/decoder.go

func (*DefaultTrackInfo) Author

func (i *DefaultTrackInfo) Author() string

func (*DefaultTrackInfo) Identifier

func (i *DefaultTrackInfo) Identifier() string

func (*DefaultTrackInfo) IsSeekable

func (i *DefaultTrackInfo) IsSeekable() bool

func (*DefaultTrackInfo) IsStream

func (i *DefaultTrackInfo) IsStream() bool

func (*DefaultTrackInfo) Length

func (i *DefaultTrackInfo) Length() int

func (*DefaultTrackInfo) Position

func (i *DefaultTrackInfo) Position() int

func (*DefaultTrackInfo) SourceName

func (i *DefaultTrackInfo) SourceName() string

func (*DefaultTrackInfo) Title

func (i *DefaultTrackInfo) Title() string

func (*DefaultTrackInfo) URI

func (i *DefaultTrackInfo) URI() *string

type DestroyPlayerCommand

type DestroyPlayerCommand struct {
	PlayerCommand
}

type EndReason

type EndReason string
const (
	Finished   EndReason = "FINISHED"
	LoadFailed EndReason = "LOAD_FAILED"
	Stopped    EndReason = "STOPPED"
	Replaced   EndReason = "REPLACED"
	Cleanup    EndReason = "CLEANUP"
)

func (EndReason) MayStartNext

func (e EndReason) MayStartNext() bool

type EventCommand

type EventCommand struct {
	GenericOp
	SessionID string      `json:"sessionId"`
	Event     interface{} `json:"event"`
	GuildID   string      `json:"guildId"`
}

type Exception

type Exception struct {
	Message  string   `json:"message"`
	Severity Severity `json:"severity"`
	Cause    *string  `json:"cause,omitempty"`
}

func NewException

func NewException(message string, severity Severity) *Exception

func NewExceptionFromErr

func NewExceptionFromErr(err error) *Exception

func (*Exception) Error

func (e *Exception) Error() string

type FilterPlayerCommand

type FilterPlayerCommand struct {
	PlayerCommand
	*filters.Filters
}

type FrameStats

type FrameStats struct {
	Sent    int `json:"sent"`
	Nulled  int `json:"nulled"`
	Deficit int `json:"deficit"`
}

type FunctionalResultHandler

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

func (*FunctionalResultHandler) LoadFailed

func (h *FunctionalResultHandler) LoadFailed(e *Exception)

func (*FunctionalResultHandler) NoMatches

func (h *FunctionalResultHandler) NoMatches()

func (*FunctionalResultHandler) PlaylistLoaded

func (h *FunctionalResultHandler) PlaylistLoaded(playlist *Playlist)

func (*FunctionalResultHandler) SearchResultLoaded

func (h *FunctionalResultHandler) SearchResultLoaded(tracks []Track)

func (*FunctionalResultHandler) TrackLoaded

func (h *FunctionalResultHandler) TrackLoaded(track Track)

type GenericOp

type GenericOp struct {
	Op Op `json:"op"`
}

type GenericPlayerEvent

type GenericPlayerEvent struct {
	GenericWebsocketEvent
	GuildID string `json:"guildId"`
}

type GenericTrackEvent

type GenericTrackEvent struct {
	GenericPlayerEvent
	RawTrack string `json:"track"`
}

func (GenericTrackEvent) Track

func (e GenericTrackEvent) Track() Track

type GenericWebsocketEvent

type GenericWebsocketEvent struct {
	GenericOp
	Type WebsocketEvent `json:"type"`
}
type Lavalink interface {
	Logger() log.Logger
	AddNode(options *NodeOptions)
	Node(name string) Node
	BestNode() Node
	RemoveNode(name string)
	Player(guildID string) Player
	ExistingPlayer(guildID string) Player
	Players() map[string]Player
	RestClient() RestClient
	UserID() string
	ClientName() string
	Close()
	VoiceServerUpdate(voiceServerUpdate *VoiceServerUpdate)
	VoiceStateUpdate(voiceStateUpdate *VoiceStateUpdate)
}

type LoadResult

type LoadResult struct {
	LoadType     LoadType        `json:"loadType"`
	PlaylistInfo *PlaylistInfo   `json:"playlistInfo"`
	Tracks       []*DefaultTrack `json:"tracks"`
	Exception    *Exception      `json:"exception"`
}

type LoadType

type LoadType string
const (
	LoadTypeTrackLoaded    LoadType = "TRACK_LOADED"
	LoadTypePlaylistLoaded LoadType = "PLAYLIST_LOADED"
	LoadTypeSearchResult   LoadType = "SEARCH_RESULT"
	LoadTypeNoMatches      LoadType = "NO_MATCHES"
	LoadTypeLoadFailed     LoadType = "LOAD_FAILED"
)

type Memory

type Memory struct {
	Free       int `json:"free"`
	Used       int `json:"used"`
	Allocated  int `json:"allocated"`
	Reservable int `json:"reservable"`
}

type Node

type Node interface {
	Lavalink() Lavalink
	Send(d interface{})
	Open() error
	Close()
	Name() string
	RestClient() RestClient
	RestURL() string
	Options() *NodeOptions
	Stats() *Stats
}

type NodeOptions

type NodeOptions struct {
	Name     string
	Host     string
	Port     int
	Password string
	Secure   bool
}

type NodeStatus

type NodeStatus int
const (
	Connecting NodeStatus = iota
	Reconnecting
	Disconnected
)

Indicates how far along the client is to connecting

type Op

type Op string
const (
	OpPlay              Op = "play"
	OpStop              Op = "stop"
	OpPause             Op = "pause"
	OpSeek              Op = "seek"
	OpVolume            Op = "volume"
	OpEqualizer         Op = "equalizer"
	OpDestroy           Op = "destroy"
	OpStats             Op = "stats"
	OpVoiceUpdate       Op = "voiceUpdate"
	OpPlayerUpdate      Op = "playerUpdate"
	OpEvent             Op = "event"
	OpConfigureResuming Op = "configureResuming"
	OpFilters           Op = "filters"
)

type PausePlayerCommand

type PausePlayerCommand struct {
	PlayerCommand
	Pause bool `json:"pause"`
}

type PlayPlayerCommand

type PlayPlayerCommand struct {
	PlayerCommand
	Track     string `json:"track"`
	StartTime *int   `json:"startTime,omitempty"`
	EndTime   *int   `json:"endTime,omitempty"`
	Volume    *int   `json:"volume,omitempty"`
	NoReplace *bool  `json:"noReplace,omitempty"`
	Pause     *bool  `json:"pause,omitempty"`
}

type Player

type Player interface {
	Track() Track
	SetTrack(track Track)
	Play(track Track)
	PlayAt(track Track, start int, end int)
	Stop()
	Destroy()
	Pause(paused bool)
	Paused() bool
	Position() int
	Seek(position int)
	Volume() int
	SetVolume(volume int)
	Filters() *filters.Filters
	SetFilters(filters *filters.Filters)

	GuildID() string
	ChannelID() *string
	SetChannelID(channelID *string)
	LastSessionID() *string
	SetLastSessionID(sessionID string)

	Node() Node
	ChangeNode(node Node)

	PlayerUpdate(state State)
	EmitEvent(listenerCaller func(listener PlayerEventListener))
	AddListener(playerListener PlayerEventListener)
	RemoveListener(playerListener PlayerEventListener)
}

type PlayerCommand

type PlayerCommand struct {
	GenericOp
	GuildID string `json:"guildId"`
}

func NewPlayerCommand

func NewPlayerCommand(op Op, p Player) PlayerCommand

type PlayerEventListener

type PlayerEventListener interface {
	OnPlayerPause(player Player)
	OnPlayerResume(player Player)
	OnPlayerUpdate(player Player, state State)
	OnTrackStart(player Player, track Track)
	OnTrackEnd(player Player, track Track, endReason EndReason)
	OnTrackException(player Player, track Track, exception Exception)
	OnTrackStuck(player Player, track Track, thresholdMs int)
	OnWebSocketClosed(player Player, code int, reason string, byRemote bool)
}

type PlayerUpdateEvent

type PlayerUpdateEvent struct {
	GenericOp
	GuildID string `json:"guildId"`
	State   State  `json:"state"`
}

type Playlist

type Playlist struct {
	Info   *PlaylistInfo
	Tracks []Track
}

func NewPlaylist

func NewPlaylist(result *LoadResult) *Playlist

func (Playlist) SelectedTrack

func (p Playlist) SelectedTrack() Track

type PlaylistInfo

type PlaylistInfo struct {
	Name          string `json:"name"`
	SelectedTrack int    `json:"selectedTrack"`
}

type RestClient

type RestClient interface {
	SearchItem(searchType SearchType, query string) ([]Track, *Exception)
	LoadItemAsync(identifier string, audioLoaderResultHandler AudioLoaderResultHandler)
	LoadItem(identifier string) (*LoadResult, error)
}

type SearchType

type SearchType string
const (
	SearchTypeYoutube      SearchType = "ytsearch:"
	SearchTypeYoutubeMusic SearchType = "ytmsearch:"
	SearchTypeSoundCloud   SearchType = "scsearch:"
)

search prefixes

func (SearchType) Apply

func (t SearchType) Apply(searchString string) string

type SeekPlayerCommand

type SeekPlayerCommand struct {
	PlayerCommand
	Position int `json:"position"`
}

type Severity

type Severity string
const (
	SeverityCommon     Severity = "COMMON"
	SeveritySuspicious Severity = "SUSPICIOUS"
	SeverityFault      Severity = "FAULT"
)

type State

type State struct {
	Time      int  `json:"time"`
	Position  int  `json:"position"`
	Connected bool `json:"connected"`
}

type Stats

type Stats struct {
	Players        int         `json:"players"`
	PlayingPlayers int         `json:"playingPlayers"`
	Uptime         int         `json:"uptime"`
	Memory         *Memory     `json:"memory"`
	CPU            *CPU        `json:"cpu"`
	FrameStats     *FrameStats `json:"frameStats"`
}

func (*Stats) Better

func (s *Stats) Better(stats *Stats) bool

type StatsEvent

type StatsEvent struct {
	GenericOp
	*Stats
}

type StopPlayerCommand

type StopPlayerCommand struct {
	PlayerCommand
}

type Track

type Track interface {
	Track() *string
	Info() TrackInfo
	EncodeInfo() error
	DecodeInfo() error
}

func DefaultTracksToTracks

func DefaultTracksToTracks(defaultTracks []*DefaultTrack) []Track

type TrackEndEvent

type TrackEndEvent struct {
	GenericTrackEvent
	EndReason EndReason `json:"reason"`
}

type TrackExceptionEvent

type TrackExceptionEvent struct {
	GenericTrackEvent
	Exception Exception `json:"exception"`
}

type TrackInfo

type TrackInfo interface {
	Identifier() string
	IsSeekable() bool
	Author() string
	Length() int
	IsStream() bool
	Position() int
	Title() string
	URI() *string
	SourceName() string
}

type TrackStartEvent

type TrackStartEvent struct {
	GenericTrackEvent
}

type TrackStuckEvent

type TrackStuckEvent struct {
	GenericTrackEvent
	ThresholdMs int `json:"thresholdMs"`
}

type VoiceServerUpdate

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

type VoiceStateUpdate

type VoiceStateUpdate struct {
	GuildID   string  `json:"guild_id"`
	ChannelID *string `json:"channel_id"`
	UserID    string  `json:"user_id"`
	SessionID string  `json:"session_id"`
}

type VolumePlayerCommand

type VolumePlayerCommand struct {
	PlayerCommand
	Volume int `json:"volume"`
}

type WebSocketClosedEvent

type WebSocketClosedEvent struct {
	GenericPlayerEvent
	Code     int    `json:"code"`
	Reason   string `json:"reason"`
	ByRemote bool   `json:"byRemote"`
}

type WebsocketEvent

type WebsocketEvent string
const (
	WebsocketEventTrackStart     WebsocketEvent = "TrackStartEvent"
	WebsocketEventTrackEnd       WebsocketEvent = "TrackEndEvent"
	WebsocketEventTrackException WebsocketEvent = "TrackExceptionEvent"
	WebsocketEventTrackStuck     WebsocketEvent = "TrackStuckEvent"
	WebSocketEventClosed         WebsocketEvent = "WebSocketClosedEvent"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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