bot

package
v3.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2016 License: MIT Imports: 20 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckForDuplicateAliases

func CheckForDuplicateAliases() error

CheckForDuplicateAliases validates that all commands have unique aliases.

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

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) 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
	Commands          []interfaces.Command
	Version           string
	Volume            float32
	YouTubeDL         *YouTubeDL
	KeepAlive         chan bool
}

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 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 {
	Queue []interfaces.Track
	// contains filtered or unexported fields
}

Queue holds the audio queue itself along with useful methods for performing actions on the queue.

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

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

CurrentTrack returns the current Track.

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.

func (*Queue) InsertTrack

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

InsertTrack inserts track `t` at position `i` in the queue.

func (*Queue) Length

func (q *Queue) Length() int

Length returns the length of the queue.

func (*Queue) PauseCurrent

func (q *Queue) PauseCurrent() error

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

func (*Queue) PeekNextTrack

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

PeekNextTrack peeks at the next track and returns it.

func (*Queue) PlayCurrent

func (q *Queue) PlayCurrent() error

PlayCurrent creates a new audio stream and begins playing the current track.

func (*Queue) RandomNextTrack

func (q *Queue) RandomNextTrack(queueWasEmpty bool)

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

func (*Queue) Reset

func (q *Queue) Reset()

Reset removes all tracks from the queue.

func (*Queue) ResumeCurrent

func (q *Queue) ResumeCurrent() error

ResumeCurrent resumes playback of the current audio stream if it exists and is paused.

func (*Queue) ShuffleTracks

func (q *Queue) ShuffleTracks()

ShuffleTracks shuffles the queue using an inside-out algorithm.

func (*Queue) Skip

func (q *Queue) Skip()

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

func (*Queue) SkipPlaylist

func (q *Queue) SkipPlaylist()

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

func (*Queue) StopCurrent

func (q *Queue) StopCurrent() error

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

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
	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) 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{}

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