Documentation
¶
Index ¶
- Constants
- func CreateConfigIfNotExists(path string) error
- func CreatePlaylistIfNotExists(path string) error
- type Config
- type Entity
- type Metrics
- type Playlist
- func (p *Playlist) AddEntry(entry PlaylistEntry)
- func (p *Playlist) Clear()
- func (p *Playlist) Format(format string, n int, reversed bool) (string, error)
- func (p *Playlist) MarshalJSON() ([]byte, error)
- func (p *Playlist) PeakBackN(n int) []PlaylistEntry
- func (p *Playlist) Pop() (PlaylistEntry, bool)
- func (p *Playlist) PopN(n int) []PlaylistEntry
- func (p *Playlist) Push(entry PlaylistEntry)
- func (p *Playlist) PushFront(entry PlaylistEntry)
- func (p *Playlist) Store(path string) error
- func (p *Playlist) UnmarshalJSON(data []byte) error
- type PlaylistEntry
- type PrometheusConfig
- type Role
- type Source
- type State
Constants ¶
const DefaultPrompt = `` /* 680-byte string literal not displayed */
const GenerateThemesPrompt = `` /* 573-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
func CreateConfigIfNotExists ¶
CreateConfigIfNotExists makes sure that a config file exists. If it doesn't, it is created and populated with the default config.
func CreatePlaylistIfNotExists ¶
CreatePlaylistIfNotExists makes sure that a playlist file exists. If it doesn't, it is created.
Types ¶
type Config ¶
type Config struct { DiscordBotToken string `yaml:"discordBotToken,omitempty" env:"DISCORD_BOT_TOKEN"` OpenAIKey string `yaml:"openAiApiKey,omitempty" env:"OPENAI_API_KEY"` ExtrapolateWhenEmpty bool `yaml:"extrapolateWhenEmpty"` ExtrapolationLookback int `yaml:"extrapolationLookback"` Prometheus *PrometheusConfig `yaml:"prometheus,omitempty"` Prompt string `yaml:"-"` ThemesPrompt string `yaml:"-"` LogLevel slog.Level `yaml:"logLevel"` }
func ReadConfig ¶
ReadConfig reads a config file from the specified path.
func (*Config) PopulateFromEnvironment ¶
PopulateFromEnvironment populates the config with values from environment variables.
type Metrics ¶
type Metrics struct { SongsPlayed prometheus.Counter DurationPlayed prometheus.Counter ActiveStreams prometheus.Gauge TokensConsumed prometheus.Counter }
func NewMetrics ¶
func NewMetrics() *Metrics
func (*Metrics) Collect ¶
func (m *Metrics) Collect(c chan<- prometheus.Metric)
Collect implements prometheus.Collector.
func (*Metrics) Describe ¶
func (m *Metrics) Describe(d chan<- *prometheus.Desc)
Describe implements prometheus.Collector.
type Playlist ¶
type Playlist struct {
// contains filtered or unexported fields
}
func NewPlaylist ¶
func NewPlaylist() *Playlist
func ReadPlaylist ¶
ReadPlaylist reads a playlist file from the specified path.
func (*Playlist) AddEntry ¶
func (p *Playlist) AddEntry(entry PlaylistEntry)
AddEntry adds an entry to the playlist.
func (*Playlist) Format ¶
Format formats the first n entries of the playlist using the specified format template.
The template has the following values exposed:
- Index: index of the entry
- EntityName: name of the entity that added the entry
- Title: title of the entry
- RelativeTime: duration since the entry was added
func (*Playlist) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Playlist) PeakBackN ¶
func (p *Playlist) PeakBackN(n int) []PlaylistEntry
PeakBackN returns at most n entries from the back of the playlist.
func (*Playlist) Pop ¶
func (p *Playlist) Pop() (PlaylistEntry, bool)
Pop removes and returns the top entry.
func (*Playlist) PopN ¶
func (p *Playlist) PopN(n int) []PlaylistEntry
PopN returns at most n entries from the front of the playlist, removing them in the process.
func (*Playlist) Push ¶
func (p *Playlist) Push(entry PlaylistEntry)
Push the entry to the back of the playlist.
func (*Playlist) PushFront ¶
func (p *Playlist) PushFront(entry PlaylistEntry)
PushFront pushes the entry to the front of the playlist.
func (*Playlist) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type PlaylistEntry ¶
type PlaylistEntry struct { // Time is the time the entry was added to the playlist. Time time.Time `json:"time"` // Title is the title of the playlist. Title string `json:"title"` // AddedBy holds information on who added the entry to the playlist. AddedBy Entity `json:"addedBy"` // Source defines the source from which the entry can be found. Source Source `json:"source"` // URI is a source-specific URI that uniquely refers to the entry. URI string `json:"uri"` }
type PrometheusConfig ¶
type State ¶
type State struct { Config *Config Queue *Playlist Suggestions *Playlist History *Playlist Metrics *Metrics // contains filtered or unexported fields }
State holds application state.
func LoadOrInit ¶
LoadOrInit loads the state from the specified base path. If the state is not initialized (i.e. config files etc. not created), the state is initialized.