bot

package
v0.0.0-...-d2e9830 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Assets = assets.Assets

Assets embedded in binary

Functions

func CheckForDuplicateAliases

func CheckForDuplicateAliases() error

CheckForDuplicateAliases validates that all commands have unique aliases.

func GetSampleList

func GetSampleList() []string

GetSampleList returns map[string]int with folders name and number of files in folder

func PerformStartupChecks

func PerformStartupChecks()

PerformStartupChecks executes the suite of startup checks that are run before the bot connects to the server.

func ReadConfigFile

func ReadConfigFile() error

ReadConfigFile reads in the config file and updates the configuration accordingly.

func SetDefaultConfig

func SetDefaultConfig()

SetDefaultConfig sets default values for all configuration options.

Types

type Cache

type Cache struct {
	NumAudioFiles int
	TotalFileSize int64
}

Cache keeps track of the filesize of the audio cache and provides methods for pruning the cache.

func NewCache

func NewCache() *Cache

NewCache creates an empty Cache and returns it.

func (*Cache) CheckDirectorySize

func (c *Cache) CheckDirectorySize()

CheckDirectorySize checks the cache directory to determine if the filesize of the files within exceed the user-specified size limit. If so, the oldest files are cleared until it is no longer exceeding the limit.

func (*Cache) CleanPeriodically

func (c *Cache) CleanPeriodically(ctx context.Context)

CleanPeriodically loops forever, deleting expired cached audio files as necessary.

func (*Cache) DeleteAll

func (c *Cache) DeleteAll() error

DeleteAll deletes all cached audio files.

func (*Cache) DeleteOldest

func (c *Cache) DeleteOldest() error

DeleteOldest deletes the oldest file in the cache.

func (*Cache) PrefetchPeriodically

func (c *Cache) PrefetchPeriodically(ctx context.Context)

PrefetchPeriodically loops forever, prefetching next audio files in Queue

func (*Cache) UpdateStatistics

func (c *Cache) UpdateStatistics()

UpdateStatistics updates the statistics relevant to the cache (number of audio files cached, total current size of the cache).

type MumbleDJ

type MumbleDJ struct {
	AvailableServices []interfaces.Service
	Client            *gumble.Client
	GumbleConfig      *gumble.Config
	TLSConfig         *tls.Config
	AudioStream       *gumbleffmpeg.Stream
	Queue             interfaces.Queue
	Cache             *Cache
	Skips             interfaces.SkipTracker
	Player            interfaces.Player
	Ohohoho           interfaces.Ohohoho
	Commands          []interfaces.Command
	Version           string
	Volume            float32
	YouTubeDL         *YouTubeDL
	KeepAlive         chan bool
	// contains filtered or unexported fields
}

MumbleDJ is a struct that keeps track of all aspects of the bot's state.

var DJ *MumbleDJ

DJ is a struct that keeps track of all aspects of MumbleDJ's environment.

func NewMumbleDJ

func NewMumbleDJ() *MumbleDJ

NewMumbleDJ initializes and returns a MumbleDJ type.

func (*MumbleDJ) Connect

func (dj *MumbleDJ) Connect() error

Connect starts the process for connecting to a Mumble server.

func (*MumbleDJ) FindAndExecuteCommand

func (dj *MumbleDJ) FindAndExecuteCommand(user *gumble.User, message string) (string, bool, error)

FindAndExecuteCommand attempts to find a reference to a command in an incoming message. If found, the command is executed and the resulting message/error is returned.

func (*MumbleDJ) GetService

func (dj *MumbleDJ) GetService(url string) (interfaces.Service, error)

GetService loops through the available services and determines if a URL matches a particular service. If a match is found, the service object is returned.

func (*MumbleDJ) IsAdmin

func (dj *MumbleDJ) IsAdmin(user *gumble.User) bool

IsAdmin checks whether a particular Mumble user is a MumbleDJ admin. Returns true if the user is an admin, and false otherwise.

func (*MumbleDJ) OnConnect

func (dj *MumbleDJ) OnConnect(e *gumble.ConnectEvent)

OnConnect event. First moves MumbleDJ into the default channel if one exists. The configuration is loaded and the audio stream is initialized.

func (*MumbleDJ) OnDisconnect

func (dj *MumbleDJ) OnDisconnect(e *gumble.DisconnectEvent)

OnDisconnect event. Terminates MumbleDJ process or retries connection if automatic connection retries are enabled.

func (*MumbleDJ) OnTextMessage

func (dj *MumbleDJ) OnTextMessage(e *gumble.TextMessageEvent)

OnTextMessage event. Checks for command prefix and passes it to the Commander if it exists. Ignores the incoming message otherwise.

func (*MumbleDJ) OnUserChange

func (dj *MumbleDJ) OnUserChange(e *gumble.UserChangeEvent)

OnUserChange event. Checks UserChange type and adjusts skip trackers to reflect the current status of the users on the server.

func (*MumbleDJ) SendPrivateMessage

func (dj *MumbleDJ) SendPrivateMessage(user *gumble.User, message string)

SendPrivateMessage sends a private message to the specified user. This method verifies that the targeted user is still present in the server before attempting to send the message.

type OhohohoPlayer

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

OhohohoPlayer is a command that plays random Frieza laughs from Dragon Ball series

func NewOhohohoPlayer

func NewOhohohoPlayer() *OhohohoPlayer

NewOhohohoPlayer returns new instance of OhohohoPlayer

func (*OhohohoPlayer) EmptyStop

func (c *OhohohoPlayer) EmptyStop() error

func (*OhohohoPlayer) IsInterrupting

func (c *OhohohoPlayer) IsInterrupting() bool

IsInterrupting informs if Queue command should remove track from queue. If it's true, track should remain on list

func (*OhohohoPlayer) PlaySample

func (c *OhohohoPlayer) PlaySample(sampleName string, howMany int) error

PlaySample plays random file from folder given by user as argument, which is located in assets directory

func (*OhohohoPlayer) Stop

func (c *OhohohoPlayer) Stop() error

type Player

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

Player should be special goroutine, which prefetch sound from videos and plays audio stream

func NewPlayer

func NewPlayer() *Player

func (*Player) CurrentTrack

func (p *Player) CurrentTrack() (interfaces.Track, error)

CurrentTrack returns the current Track.

func (*Player) HoldOnTrack

func (p *Player) HoldOnTrack() error

func (*Player) PauseCurrent

func (p *Player) PauseCurrent() error

PauseCurrent pauses the current audio stream if it exists and is not already paused.

func (*Player) PlayCurrentForeverLoop

func (p *Player) PlayCurrentForeverLoop(ctx context.Context)

PlayCurrentForeverLoop plays tracks from queue and waits for new tracks if queue is empty

func (*Player) RepeatMode

func (p *Player) RepeatMode() bool

RepeatMode turns on special mode, so if track has been played, it will be added to the end of queue.

func (*Player) ResumeCurrent

func (p *Player) ResumeCurrent()

ResumeCurrent resumes playback of the current audio stream if it exists and is paused. It also notifies PlayCurrentForeverLoop() that

func (*Player) Skip

func (p *Player) Skip()

Skip performs the necessary actions that take place when a track is skipped via a command.

func (*Player) SkipPlaylist

func (p *Player) SkipPlaylist()

SkipPlaylist performs the necessary actions that take place when a playlist is skipped via a command.

func (*Player) StopCurrent

func (p *Player) StopCurrent() error

StopCurrent stops the playback of the current audio stream if it exists.

type Playlist

type Playlist struct {
	ID        string
	Title     string
	Submitter string
	Service   string
}

Playlist stores all metadata related to a playlist of tracks.

func (*Playlist) GetID

func (p *Playlist) GetID() string

GetID returns the ID of the playlist.

func (*Playlist) GetService

func (p *Playlist) GetService() string

GetService returns the name of the service from which the playlist was retrieved from.

func (*Playlist) GetSubmitter

func (p *Playlist) GetSubmitter() string

GetSubmitter returns the submitter of the playlist.

func (*Playlist) GetTitle

func (p *Playlist) GetTitle() string

GetTitle returns the title of the playlist.

type Queue

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

Queue holds the audio tracks queue itself along with useful methods for performing actions on the queue. It checks if track conform current config values.

func NewQueue

func NewQueue() *Queue

NewQueue initializes a new queue and returns it.

func (*Queue) AppendTrack

func (q *Queue) AppendTrack(t interfaces.Track) error

AppendTrack adds a track to the back of the queue.

func (*Queue) AppendTracks

func (q *Queue) AppendTracks(ts []interfaces.Track) error

AppendTracks adds a tracks to the back of the queue.

func (*Queue) GetTrack

func (q *Queue) GetTrack(index int) interfaces.Track

GetTrack takes an `index` argument to determine which track to return. If the track in position `index` exists, it is returned. Otherwise, nil is returned. If queue is empty it will block calling goroutine until track appear.

func (*Queue) GetTrackNoWait

func (q *Queue) GetTrackNoWait(index int) interfaces.Track

GetTrackNoWait takes an `index` argument to determine which track to return. If the track in position `index` exists, it is returned. Otherwise, nil is returned.

func (*Queue) InsertTrack

func (q *Queue) InsertTrack(i int, t interfaces.Track) error

func (*Queue) Length

func (q *Queue) Length() int

Length returns the length of the queue.

func (*Queue) PeekNextTrack

func (q *Queue) PeekNextTrack() (interfaces.Track, error)

PeekNextTrack peeks at the next track and returns it.

func (*Queue) PrependTrack

func (q *Queue) PrependTrack(t interfaces.Track) error

AppendTrack adds a track to the back of the queue.

func (*Queue) RandomNextTrack

func (q *Queue) RandomNextTrack(queueWasEmpty bool)

RandomNextTrack sets a random track as the next track to be played.

func (*Queue) RemoveTrack

func (q *Queue) RemoveTrack(index int) interfaces.Track

RemoveTrack takes an `index` argument [0:q.Length(queue)) and removes track connected with that index from the queue. If the track in position `index` exists, it is returned. Otherwise, nil is returned. Note that it may not be the same track as in GetTrack, because other goroutine could RemoveTrack earlier.

func (*Queue) RemoveTrackIf

func (q *Queue) RemoveTrackIf(fun func(int, interfaces.Track) bool) int

RemoveTrackIf removes item if given function returns true. Function returns number of removed elements TODO: Improve implementation to reuse memory instead creating new slice

func (*Queue) Reset

func (q *Queue) Reset()

Reset removes all tracks from the queue and reset state of queue.

func (*Queue) ShuffleTracks

func (q *Queue) ShuffleTracks()

ShuffleTracks shuffles the queue using an inside-out algorithm.

func (*Queue) Traverse

func (q *Queue) Traverse(visit func(i int, t interfaces.Track))

Traverse is a traversal function for Queue. Allows a visit function to be passed in which performs the specified action on each queue item.

type SkipTracker

type SkipTracker struct {
	TrackSkips    []*gumble.User
	PlaylistSkips []*gumble.User
	// contains filtered or unexported fields
}

SkipTracker keeps track of the list of users who have skipped the current track or playlist.

func NewSkipTracker

func NewSkipTracker() *SkipTracker

NewSkipTracker returns an empty SkipTracker.

func (*SkipTracker) AddPlaylistSkip

func (s *SkipTracker) AddPlaylistSkip(skipper *gumble.User) error

AddPlaylistSkip adds a skip to the SkipTracker for the current playlist.

func (*SkipTracker) AddTrackSkip

func (s *SkipTracker) AddTrackSkip(skipper *gumble.User) error

AddTrackSkip adds a skip to the SkipTracker for the current track.

func (*SkipTracker) NumPlaylistSkips

func (s *SkipTracker) NumPlaylistSkips() int

NumPlaylistSkips returns the number of users who have skipped the current playlist.

func (*SkipTracker) NumTrackSkips

func (s *SkipTracker) NumTrackSkips() int

NumTrackSkips returns the number of users who have skipped the current track.

func (*SkipTracker) RemovePlaylistSkip

func (s *SkipTracker) RemovePlaylistSkip(skipper *gumble.User) error

RemovePlaylistSkip removes a skip from the SkipTracker for the current playlist.

func (*SkipTracker) RemoveTrackSkip

func (s *SkipTracker) RemoveTrackSkip(skipper *gumble.User) error

RemoveTrackSkip removes a skip from the SkipTracker for the current track.

func (*SkipTracker) ResetPlaylistSkips

func (s *SkipTracker) ResetPlaylistSkips()

ResetPlaylistSkips resets the skip slice for the current playlist.

func (*SkipTracker) ResetTrackSkips

func (s *SkipTracker) ResetTrackSkips()

ResetTrackSkips resets the skip slice for the current track.

type SortFilesByAge

type SortFilesByAge []os.FileInfo

SortFilesByAge is a type that holds file information for cached items for sorting.

func (SortFilesByAge) Len

func (a SortFilesByAge) Len() int

Len returns the length of the file slice.

func (SortFilesByAge) Less

func (a SortFilesByAge) Less(i, j int) bool

Less compares two file modification times to determine if one is less than the other. Returns true if the item in index i is older than the item in index j, false otherwise.

func (SortFilesByAge) Swap

func (a SortFilesByAge) Swap(i, j int)

Swap swaps two elements in the file slice.

type Track

type Track struct {
	ID              string
	URL             string
	Title           string
	Author          string
	AuthorURL       string
	Submitter       string
	Service         string
	Filename        string
	ThumbnailURL    string
	ThumbnailBase64 string
	Duration        time.Duration
	PlaybackOffset  time.Duration
	Playlist        interfaces.Playlist
}

Track stores all metadata related to an audio track.

func (Track) GetAuthor

func (t Track) GetAuthor() string

GetAuthor returns the author of the track.

func (Track) GetAuthorURL

func (t Track) GetAuthorURL() string

GetAuthorURL returns the URL that links to the author of the track.

func (Track) GetDuration

func (t Track) GetDuration() time.Duration

GetDuration returns the duration of the track.

func (Track) GetFilename

func (t Track) GetFilename() string

GetFilename returns the name of the file stored on disk, if it exists. If no file on disk exists an empty string and error are returned.

func (Track) GetID

func (t Track) GetID() string

GetID returns the ID of the track.

func (Track) GetPlaybackOffset

func (t Track) GetPlaybackOffset() time.Duration

GetPlaybackOffset returns the playback offset for the track. A duration of 0 is given to tracks that do not specify an offset.

func (Track) GetPlaylist

func (t Track) GetPlaylist() interfaces.Playlist

GetPlaylist returns the playlist the track is associated with, if it exists. If the track is not associated with a playlist a nil playlist and error are returned.

func (Track) GetService

func (t Track) GetService() string

GetService returns the name of the service from which the track was retrieved from.

func (Track) GetSubmitter

func (t Track) GetSubmitter() string

GetSubmitter returns the submitter of the track.

func (Track) GetThumbnailBase64

func (t Track) GetThumbnailBase64() string

GetThumbnailBase64 returns the base64 encoded JPEG of the thumbnail for the track. If no thumbnail exists an empty string and error are returned.

func (Track) GetThumbnailURL

func (t Track) GetThumbnailURL() string

GetThumbnailURL returns the URL to the thumbnail for the track. If no thumbnail exists an empty string and error are returned.

func (Track) GetTitle

func (t Track) GetTitle() string

GetTitle returns the title of the track.

func (Track) GetURL

func (t Track) GetURL() string

GetURL returns the URL of the track.

type YouTubeDL

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

YouTubeDL is a struct that gathers all methods related to the youtube-dl software. youtube-dl: https://rg3.github.io/youtube-dl/

func (*YouTubeDL) Delete

func (yt *YouTubeDL) Delete(t interfaces.Track) error

Delete deletes the audio file associated with the incoming `track` object.

func (*YouTubeDL) Download

func (yt *YouTubeDL) Download(t interfaces.Track) error

Download downloads the audio associated with the incoming `track` object and stores it `track.Filename`.

Jump to

Keyboard shortcuts

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