2014-12-13 05:53:18 +01:00
|
|
|
/*
|
|
|
|
* MumbleDJ
|
|
|
|
* By Matthieu Grieger
|
|
|
|
* commands.go
|
2015-01-18 23:44:40 +01:00
|
|
|
* Copyright (c) 2014, 2015 Matthieu Grieger (MIT License)
|
2014-12-13 05:53:18 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-12-14 04:34:33 +01:00
|
|
|
"bytes"
|
2014-12-27 09:25:49 +01:00
|
|
|
"errors"
|
2014-12-13 05:53:18 +01:00
|
|
|
"fmt"
|
2014-12-27 09:25:49 +01:00
|
|
|
"os"
|
2014-12-19 01:28:38 +01:00
|
|
|
"strconv"
|
2014-12-13 05:53:18 +01:00
|
|
|
"strings"
|
2015-04-09 22:23:21 +02:00
|
|
|
|
|
|
|
"github.com/layeh/gumble/gumble"
|
2014-12-13 05:53:18 +01:00
|
|
|
)
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// parseCommand views incoming chat messages and determines if there is a valid command within them.
|
|
|
|
// If a command exists, the arguments (if any) will be parsed and sent to the appropriate helper
|
|
|
|
// function to perform the command's task.
|
2014-12-16 01:40:05 +01:00
|
|
|
func parseCommand(user *gumble.User, username, command string) {
|
2014-12-13 05:53:18 +01:00
|
|
|
var com, argument string
|
2015-02-07 23:10:45 +01:00
|
|
|
split := strings.Split(command, "\n")
|
|
|
|
splitString := split[0]
|
|
|
|
if strings.Contains(splitString, " ") {
|
|
|
|
index := strings.Index(splitString, " ")
|
|
|
|
com, argument = splitString[0:index], splitString[(index+1):]
|
2014-12-13 05:53:18 +01:00
|
|
|
} else {
|
|
|
|
com = command
|
|
|
|
argument = ""
|
|
|
|
}
|
2014-12-16 01:40:05 +01:00
|
|
|
|
2014-12-13 05:53:18 +01:00
|
|
|
switch com {
|
2014-12-27 19:05:13 +01:00
|
|
|
// Add command
|
2014-12-16 01:40:05 +01:00
|
|
|
case dj.conf.Aliases.AddAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminAdd) {
|
2015-10-01 21:56:05 +02:00
|
|
|
add(user, argument)
|
2014-12-16 01:40:05 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2014-12-16 01:40:05 +01:00
|
|
|
}
|
2015-12-15 02:07:12 +01:00
|
|
|
// Addnext command
|
|
|
|
case dj.conf.Aliases.AddNextAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminAddNext) {
|
|
|
|
addNext(user, argument)
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
|
|
|
}
|
2014-12-27 19:05:13 +01:00
|
|
|
// Skip command
|
2014-12-16 01:40:05 +01:00
|
|
|
case dj.conf.Aliases.SkipAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminSkip) {
|
2015-10-01 21:56:05 +02:00
|
|
|
skip(user, false, false)
|
2015-01-03 20:31:29 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2015-01-03 20:31:29 +01:00
|
|
|
}
|
|
|
|
// Skip playlist command
|
|
|
|
case dj.conf.Aliases.SkipPlaylistAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminAddPlaylists) {
|
2015-10-01 21:56:05 +02:00
|
|
|
skip(user, false, true)
|
2014-12-16 01:40:05 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2014-12-16 01:40:05 +01:00
|
|
|
}
|
2014-12-27 19:05:13 +01:00
|
|
|
// Forceskip command
|
2014-12-16 01:40:05 +01:00
|
|
|
case dj.conf.Aliases.AdminSkipAlias:
|
2014-12-27 09:25:49 +01:00
|
|
|
if dj.HasPermission(username, true) {
|
2015-10-01 21:56:05 +02:00
|
|
|
skip(user, true, false)
|
2015-01-03 20:31:29 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2015-01-03 20:31:29 +01:00
|
|
|
}
|
|
|
|
// Playlist forceskip command
|
|
|
|
case dj.conf.Aliases.AdminSkipPlaylistAlias:
|
|
|
|
if dj.HasPermission(username, true) {
|
2015-10-01 21:56:05 +02:00
|
|
|
skip(user, true, true)
|
2014-12-16 01:40:05 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2014-12-16 01:40:05 +01:00
|
|
|
}
|
2015-01-11 00:15:12 +01:00
|
|
|
// Help command
|
|
|
|
case dj.conf.Aliases.HelpAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminHelp) {
|
|
|
|
help(user)
|
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2015-01-11 00:15:12 +01:00
|
|
|
}
|
2014-12-27 19:05:13 +01:00
|
|
|
// Volume command
|
2014-12-16 01:40:05 +01:00
|
|
|
case dj.conf.Aliases.VolumeAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminVolume) {
|
2015-10-01 21:56:05 +02:00
|
|
|
volume(user, argument)
|
2014-12-16 01:40:05 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2014-12-16 01:40:05 +01:00
|
|
|
}
|
2014-12-27 19:05:13 +01:00
|
|
|
// Move command
|
2014-12-16 01:40:05 +01:00
|
|
|
case dj.conf.Aliases.MoveAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminMove) {
|
2015-01-01 16:54:11 +01:00
|
|
|
move(user, argument)
|
2014-12-16 01:40:05 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2014-12-16 01:40:05 +01:00
|
|
|
}
|
2014-12-27 19:05:13 +01:00
|
|
|
// Reload command
|
2014-12-16 01:40:05 +01:00
|
|
|
case dj.conf.Aliases.ReloadAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminReload) {
|
2015-01-01 16:54:11 +01:00
|
|
|
reload(user)
|
2014-12-16 01:40:05 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2014-12-16 01:40:05 +01:00
|
|
|
}
|
2015-01-06 04:16:59 +01:00
|
|
|
// Reset command
|
|
|
|
case dj.conf.Aliases.ResetAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminReset) {
|
|
|
|
reset(username)
|
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2015-01-06 04:16:59 +01:00
|
|
|
}
|
2015-01-10 22:03:52 +01:00
|
|
|
// Numsongs command
|
|
|
|
case dj.conf.Aliases.NumSongsAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminNumSongs) {
|
|
|
|
numSongs()
|
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2015-01-10 22:03:52 +01:00
|
|
|
}
|
2015-01-13 01:21:53 +01:00
|
|
|
// Nextsong command
|
|
|
|
case dj.conf.Aliases.NextSongAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminNextSong) {
|
|
|
|
nextSong(user)
|
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2015-01-13 01:21:53 +01:00
|
|
|
}
|
2015-01-25 20:27:28 +01:00
|
|
|
// Currentsong command
|
|
|
|
case dj.conf.Aliases.CurrentSongAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminCurrentSong) {
|
|
|
|
currentSong(user)
|
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2015-01-25 20:27:28 +01:00
|
|
|
}
|
2015-02-07 23:23:47 +01:00
|
|
|
// Setcomment command
|
|
|
|
case dj.conf.Aliases.SetCommentAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminSetComment) {
|
|
|
|
setComment(user, argument)
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
|
|
|
}
|
2015-02-18 00:43:20 +01:00
|
|
|
// Numcached command
|
|
|
|
case dj.conf.Aliases.NumCachedAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminNumCached) {
|
|
|
|
numCached(user)
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
|
|
|
}
|
|
|
|
// Cachesize command
|
|
|
|
case dj.conf.Aliases.CacheSizeAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminCacheSize) {
|
|
|
|
cacheSize(user)
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
|
|
|
}
|
2014-12-27 19:05:13 +01:00
|
|
|
// Kill command
|
2014-12-16 01:40:05 +01:00
|
|
|
case dj.conf.Aliases.KillAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminKill) {
|
2015-01-01 16:54:11 +01:00
|
|
|
kill()
|
2014-12-16 01:40:05 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
2014-12-16 01:40:05 +01:00
|
|
|
}
|
2015-10-06 20:26:09 +02:00
|
|
|
|
|
|
|
// Shuffle command
|
|
|
|
case dj.conf.Aliases.ShuffleAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminShuffle) {
|
|
|
|
shuffleSongs(user, username)
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
|
|
|
}
|
|
|
|
|
2015-10-07 23:58:54 +02:00
|
|
|
// Shuffleon command
|
2015-12-14 04:34:33 +01:00
|
|
|
case dj.conf.Aliases.ShuffleOnAlias:
|
2015-10-07 23:58:54 +02:00
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminShuffleToggle) {
|
|
|
|
toggleAutomaticShuffle(true, user, username)
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
|
|
|
}
|
|
|
|
|
2015-12-14 04:34:33 +01:00
|
|
|
// Shuffleoff command
|
2015-10-07 23:58:54 +02:00
|
|
|
case dj.conf.Aliases.ShuffleOffAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminShuffleToggle) {
|
|
|
|
toggleAutomaticShuffle(false, user, username)
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
|
|
|
}
|
|
|
|
|
2015-12-14 04:34:33 +01:00
|
|
|
// ListSongs command
|
|
|
|
case dj.conf.Aliases.ListSongsAlias:
|
|
|
|
if dj.HasPermission(username, dj.conf.Permissions.AdminListSongs) {
|
|
|
|
listSongs(user)
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
|
|
|
}
|
2014-12-16 01:40:05 +01:00
|
|
|
default:
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, COMMAND_DOESNT_EXIST_MSG)
|
2014-12-13 05:53:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 21:56:05 +02:00
|
|
|
// add performs !add functionality. Checks input URL for service, and adds
|
2014-12-27 19:05:13 +01:00
|
|
|
// the URL to the queue if the format matches.
|
2015-10-01 21:56:05 +02:00
|
|
|
func add(user *gumble.User, url string) error {
|
2015-01-01 16:54:11 +01:00
|
|
|
if url == "" {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_ARGUMENT_MSG)
|
2015-10-01 21:56:05 +02:00
|
|
|
return errors.New("NO_ARGUMENT")
|
2015-01-01 16:54:11 +01:00
|
|
|
} else {
|
2015-10-01 21:56:05 +02:00
|
|
|
err := FindServiceAndAdd(user, url)
|
|
|
|
if err != nil {
|
|
|
|
dj.SendPrivateMessage(user, err.Error())
|
2014-12-16 01:40:05 +01:00
|
|
|
}
|
2015-10-01 21:56:05 +02:00
|
|
|
return err
|
2014-12-16 01:40:05 +01:00
|
|
|
}
|
2014-12-13 05:53:18 +01:00
|
|
|
}
|
|
|
|
|
2015-12-15 02:07:12 +01:00
|
|
|
// addnext performs !addnext functionality. Checks input URL for service, and adds
|
|
|
|
// the URL to the queue as the next song if the format matches.
|
|
|
|
func addNext(user *gumble.User, url string) error {
|
|
|
|
if !dj.audioStream.IsPlaying() {
|
|
|
|
return add(user, url)
|
|
|
|
} else {
|
|
|
|
if url == "" {
|
|
|
|
dj.SendPrivateMessage(user, NO_ARGUMENT_MSG)
|
|
|
|
return errors.New("NO_ARGUMENT")
|
|
|
|
} else {
|
|
|
|
err := FindServiceAndInsertNext(user, url)
|
|
|
|
if err != nil {
|
|
|
|
dj.SendPrivateMessage(user, err.Error())
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// skip performs !skip functionality. Adds a skip to the skippers slice for the current song, and then
|
2014-12-27 19:05:13 +01:00
|
|
|
// evaluates if a skip should be performed. Both skip and forceskip are implemented here.
|
2015-10-01 21:56:05 +02:00
|
|
|
func skip(user *gumble.User, admin, playlistSkip bool) {
|
2015-01-07 20:06:58 +01:00
|
|
|
if dj.audioStream.IsPlaying() {
|
|
|
|
if playlistSkip {
|
2015-04-16 08:32:32 +02:00
|
|
|
if dj.queue.CurrentSong().Playlist() != nil {
|
2015-10-01 21:56:05 +02:00
|
|
|
if err := dj.queue.CurrentSong().Playlist().AddSkip(user.Name); err == nil {
|
2015-03-21 05:35:19 +01:00
|
|
|
submitterSkipped := false
|
2015-01-07 20:06:58 +01:00
|
|
|
if admin {
|
2015-02-12 00:25:47 +01:00
|
|
|
dj.client.Self.Channel.Send(ADMIN_PLAYLIST_SKIP_MSG, false)
|
2015-10-01 21:56:05 +02:00
|
|
|
} else if dj.queue.CurrentSong().Submitter() == user.Name {
|
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(PLAYLIST_SUBMITTER_SKIP_HTML, user.Name), false)
|
2015-03-21 05:35:19 +01:00
|
|
|
submitterSkipped = true
|
2015-01-07 20:06:58 +01:00
|
|
|
} else {
|
2015-10-01 21:56:05 +02:00
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(PLAYLIST_SKIP_ADDED_HTML, user.Name), false)
|
2015-01-07 20:06:58 +01:00
|
|
|
}
|
2015-04-16 08:32:32 +02:00
|
|
|
if submitterSkipped || dj.queue.CurrentSong().Playlist().SkipReached(len(dj.client.Self.Channel.Users)) || admin {
|
|
|
|
id := dj.queue.CurrentSong().Playlist().ID()
|
|
|
|
dj.queue.CurrentSong().Playlist().DeleteSkippers()
|
2015-02-12 22:27:04 +01:00
|
|
|
for i := 0; i < len(dj.queue.queue); i++ {
|
2015-04-16 08:32:32 +02:00
|
|
|
if dj.queue.queue[i].Playlist() != nil {
|
|
|
|
if dj.queue.queue[i].Playlist().ID() == id {
|
2015-02-12 22:27:04 +01:00
|
|
|
dj.queue.queue = append(dj.queue.queue[:i], dj.queue.queue[i+1:]...)
|
|
|
|
i--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if dj.queue.Len() != 0 {
|
|
|
|
// Set dontSkip to true to avoid audioStream.Stop() callback skipping the new first song.
|
2015-04-16 08:32:32 +02:00
|
|
|
dj.queue.CurrentSong().SetDontSkip(true)
|
2015-02-12 22:27:04 +01:00
|
|
|
}
|
2015-03-21 05:35:19 +01:00
|
|
|
if !(submitterSkipped || admin) {
|
|
|
|
dj.client.Self.Channel.Send(PLAYLIST_SKIPPED_HTML, false)
|
|
|
|
}
|
2015-01-07 20:06:58 +01:00
|
|
|
if err := dj.audioStream.Stop(); err != nil {
|
|
|
|
panic(errors.New("An error occurred while stopping the current song."))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_PLAYLIST_PLAYING_MSG)
|
2015-01-07 20:06:58 +01:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-01 21:56:05 +02:00
|
|
|
if err := dj.queue.CurrentSong().AddSkip(user.Name); err == nil {
|
2015-03-21 05:35:19 +01:00
|
|
|
submitterSkipped := false
|
2015-01-03 20:31:29 +01:00
|
|
|
if admin {
|
2015-02-12 00:25:47 +01:00
|
|
|
dj.client.Self.Channel.Send(ADMIN_SONG_SKIP_MSG, false)
|
2015-10-01 21:56:05 +02:00
|
|
|
} else if dj.queue.CurrentSong().Submitter() == user.Name {
|
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(SUBMITTER_SKIP_HTML, user.Name), false)
|
2015-03-21 05:35:19 +01:00
|
|
|
submitterSkipped = true
|
2015-01-03 20:31:29 +01:00
|
|
|
} else {
|
2015-10-01 21:56:05 +02:00
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(SKIP_ADDED_HTML, user.Name), false)
|
2015-01-03 20:31:29 +01:00
|
|
|
}
|
2015-03-21 05:35:19 +01:00
|
|
|
if submitterSkipped || dj.queue.CurrentSong().SkipReached(len(dj.client.Self.Channel.Users)) || admin {
|
|
|
|
if !(submitterSkipped || admin) {
|
|
|
|
dj.client.Self.Channel.Send(SONG_SKIPPED_HTML, false)
|
|
|
|
}
|
2015-01-03 20:31:29 +01:00
|
|
|
if err := dj.audioStream.Stop(); err != nil {
|
|
|
|
panic(errors.New("An error occurred while stopping the current song."))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_MUSIC_PLAYING_MSG)
|
2014-12-27 09:25:49 +01:00
|
|
|
}
|
2014-12-13 05:53:18 +01:00
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// help performs !help functionality. Displays a list of valid commands.
|
2015-01-11 00:15:12 +01:00
|
|
|
func help(user *gumble.User) {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, HELP_HTML)
|
2015-01-11 00:15:12 +01:00
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// volume performs !volume functionality. Checks input value against LowestVolume and HighestVolume from
|
2014-12-27 19:05:13 +01:00
|
|
|
// config to determine if the volume should be applied. If in the correct range, the new volume
|
|
|
|
// is applied and is immediately in effect.
|
2015-10-01 21:56:05 +02:00
|
|
|
func volume(user *gumble.User, value string) {
|
2015-01-01 16:54:11 +01:00
|
|
|
if value == "" {
|
2015-02-12 00:25:47 +01:00
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(CUR_VOLUME_HTML, dj.audioStream.Volume), false)
|
2015-01-01 16:54:11 +01:00
|
|
|
} else {
|
|
|
|
if parsedVolume, err := strconv.ParseFloat(value, 32); err == nil {
|
|
|
|
newVolume := float32(parsedVolume)
|
|
|
|
if newVolume >= dj.conf.Volume.LowestVolume && newVolume <= dj.conf.Volume.HighestVolume {
|
2015-02-03 02:45:55 +01:00
|
|
|
dj.audioStream.Volume = newVolume
|
2015-10-01 21:56:05 +02:00
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(VOLUME_SUCCESS_HTML, user.Name, dj.audioStream.Volume), false)
|
2015-01-01 16:54:11 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, fmt.Sprintf(NOT_IN_VOLUME_RANGE_MSG, dj.conf.Volume.LowestVolume, dj.conf.Volume.HighestVolume))
|
2015-01-01 16:54:11 +01:00
|
|
|
}
|
2014-12-19 01:28:38 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, fmt.Sprintf(NOT_IN_VOLUME_RANGE_MSG, dj.conf.Volume.LowestVolume, dj.conf.Volume.HighestVolume))
|
2014-12-19 01:28:38 +01:00
|
|
|
}
|
|
|
|
}
|
2014-12-13 05:53:18 +01:00
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// move performs !move functionality. Determines if the supplied channel is valid and moves the bot
|
2014-12-27 19:05:13 +01:00
|
|
|
// to the channel if it is.
|
2015-01-01 16:54:11 +01:00
|
|
|
func move(user *gumble.User, channel string) {
|
|
|
|
if channel == "" {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_ARGUMENT_MSG)
|
2015-01-01 16:54:11 +01:00
|
|
|
} else {
|
2015-05-14 11:15:18 +02:00
|
|
|
if channels := strings.Split(channel, "/"); dj.client.Channels.Find(channels...) != nil {
|
|
|
|
dj.client.Self.Move(dj.client.Channels.Find(channels...))
|
2015-01-01 16:54:11 +01:00
|
|
|
} else {
|
2015-05-14 11:15:18 +02:00
|
|
|
dj.SendPrivateMessage(user, CHANNEL_DOES_NOT_EXIST_MSG+" "+channel)
|
2015-01-01 16:54:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// reload performs !reload functionality. Tells command submitter if the reload completed successfully.
|
2015-01-01 16:54:11 +01:00
|
|
|
func reload(user *gumble.User) {
|
|
|
|
if err := loadConfiguration(); err == nil {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, CONFIG_RELOAD_SUCCESS_MSG)
|
2014-12-27 09:25:49 +01:00
|
|
|
}
|
2014-12-13 05:53:18 +01:00
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// reset performs !reset functionality. Clears the song queue, stops playing audio, and deletes all
|
2015-01-06 04:16:59 +01:00
|
|
|
// remaining songs in the ~/.mumbledj/songs directory.
|
|
|
|
func reset(username string) {
|
|
|
|
dj.queue.queue = dj.queue.queue[:0]
|
2015-02-02 20:41:11 +01:00
|
|
|
if dj.audioStream.IsPlaying() {
|
|
|
|
if err := dj.audioStream.Stop(); err != nil {
|
2015-01-06 04:16:59 +01:00
|
|
|
panic(err)
|
|
|
|
}
|
2015-02-02 20:41:11 +01:00
|
|
|
}
|
|
|
|
if err := deleteSongs(); err == nil {
|
2015-02-12 00:25:47 +01:00
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(QUEUE_RESET_HTML, username), false)
|
2015-01-06 04:16:59 +01:00
|
|
|
} else {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// numSongs performs !numsongs functionality. Uses the SongQueue traversal function to traverse the
|
2015-01-10 22:03:52 +01:00
|
|
|
// queue with a function call that increments a counter. Once finished, the bot outputs
|
|
|
|
// the number of songs in the queue to chat.
|
|
|
|
func numSongs() {
|
|
|
|
songCount := 0
|
2015-04-16 08:32:32 +02:00
|
|
|
dj.queue.Traverse(func(i int, song Song) {
|
2015-04-09 22:52:32 +02:00
|
|
|
songCount++
|
2015-01-10 22:03:52 +01:00
|
|
|
})
|
2015-02-12 00:25:47 +01:00
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(NUM_SONGS_HTML, songCount), false)
|
2015-01-10 22:03:52 +01:00
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// nextSong performs !nextsong functionality. Uses the SongQueue PeekNext function to peek at the next
|
2015-01-13 01:21:53 +01:00
|
|
|
// item if it exists. The user will then be sent a message containing the title and submitter
|
|
|
|
// of the next item if it exists.
|
|
|
|
func nextSong(user *gumble.User) {
|
2015-01-27 07:12:09 +01:00
|
|
|
if song, err := dj.queue.PeekNext(); err != nil {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_SONG_NEXT_MSG)
|
2015-01-13 01:21:53 +01:00
|
|
|
} else {
|
2015-04-16 08:32:32 +02:00
|
|
|
dj.SendPrivateMessage(user, fmt.Sprintf(NEXT_SONG_HTML, song.Title(), song.Submitter()))
|
2015-01-13 01:21:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// currentSong performs !currentsong functionality. Sends the user who submitted the currentsong command
|
2015-01-25 20:27:28 +01:00
|
|
|
// information about the song currently playing.
|
|
|
|
func currentSong(user *gumble.User) {
|
|
|
|
if dj.audioStream.IsPlaying() {
|
2015-04-16 08:32:32 +02:00
|
|
|
if dj.queue.CurrentSong().Playlist() == nil {
|
|
|
|
dj.SendPrivateMessage(user, fmt.Sprintf(CURRENT_SONG_HTML, dj.queue.CurrentSong().Title(), dj.queue.CurrentSong().Submitter()))
|
2015-02-08 02:54:24 +01:00
|
|
|
} else {
|
2015-04-16 08:32:32 +02:00
|
|
|
dj.SendPrivateMessage(user, fmt.Sprintf(CURRENT_SONG_PLAYLIST_HTML, dj.queue.CurrentSong().Title(),
|
|
|
|
dj.queue.CurrentSong().Submitter(), dj.queue.CurrentSong().Playlist().Title()))
|
2015-02-08 02:54:24 +01:00
|
|
|
}
|
2015-01-25 20:27:28 +01:00
|
|
|
} else {
|
2015-01-31 03:26:51 +01:00
|
|
|
dj.SendPrivateMessage(user, NO_MUSIC_PLAYING_MSG)
|
2015-01-25 20:27:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// setComment performs !setcomment functionality. Sets the bot's comment to whatever text is supplied in the argument.
|
2015-02-07 23:23:47 +01:00
|
|
|
func setComment(user *gumble.User, comment string) {
|
2015-02-12 00:25:47 +01:00
|
|
|
dj.client.Self.SetComment(comment)
|
2015-02-07 23:23:47 +01:00
|
|
|
dj.SendPrivateMessage(user, COMMENT_UPDATED_MSG)
|
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// numCached performs !numcached functionality. Displays the number of songs currently cached on disk at ~/.mumbledj/songs.
|
2015-02-18 00:43:20 +01:00
|
|
|
func numCached(user *gumble.User) {
|
|
|
|
if dj.conf.Cache.Enabled {
|
|
|
|
dj.cache.Update()
|
|
|
|
dj.SendPrivateMessage(user, fmt.Sprintf(NUM_CACHED_MSG, dj.cache.NumSongs))
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, CACHE_NOT_ENABLED_MSG)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// cacheSize performs !cachesize functionality. Displays the total file size of the cached audio files.
|
2015-02-18 00:43:20 +01:00
|
|
|
func cacheSize(user *gumble.User) {
|
|
|
|
if dj.conf.Cache.Enabled {
|
|
|
|
dj.cache.Update()
|
|
|
|
dj.SendPrivateMessage(user, fmt.Sprintf(CACHE_SIZE_MSG, float64(dj.cache.TotalFileSize/1048576)))
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, CACHE_NOT_ENABLED_MSG)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// kill performs !kill functionality. First cleans the ~/.mumbledj/songs directory to get rid of any
|
2014-12-27 19:05:13 +01:00
|
|
|
// excess m4a files. The bot then safely disconnects from the server.
|
2015-01-01 16:54:11 +01:00
|
|
|
func kill() {
|
2015-01-06 04:16:59 +01:00
|
|
|
if err := deleteSongs(); err != nil {
|
|
|
|
panic(err)
|
2014-12-27 09:25:49 +01:00
|
|
|
}
|
|
|
|
if err := dj.client.Disconnect(); err == nil {
|
2015-01-01 16:54:11 +01:00
|
|
|
fmt.Println("Kill successful. Goodbye!")
|
|
|
|
os.Exit(0)
|
2014-12-27 09:25:49 +01:00
|
|
|
} else {
|
2015-01-01 16:54:11 +01:00
|
|
|
panic(errors.New("An error occurred while disconnecting from the server."))
|
2014-12-27 09:25:49 +01:00
|
|
|
}
|
2014-12-13 05:53:18 +01:00
|
|
|
}
|
2015-01-06 04:16:59 +01:00
|
|
|
|
2015-05-10 07:00:24 +02:00
|
|
|
// deleteSongs deletes songs from ~/.mumbledj/songs.
|
2015-01-06 04:16:59 +01:00
|
|
|
func deleteSongs() error {
|
|
|
|
songsDir := fmt.Sprintf("%s/.mumbledj/songs", dj.homeDir)
|
|
|
|
if err := os.RemoveAll(songsDir); err != nil {
|
|
|
|
return errors.New("An error occurred while deleting the audio files.")
|
|
|
|
}
|
2015-05-10 07:00:24 +02:00
|
|
|
if err := os.Mkdir(songsDir, 0777); err != nil {
|
|
|
|
return errors.New("An error occurred while recreating the songs directory.")
|
|
|
|
}
|
|
|
|
return nil
|
2015-01-06 04:16:59 +01:00
|
|
|
}
|
2015-10-06 20:26:09 +02:00
|
|
|
|
|
|
|
// shuffles the song list
|
|
|
|
func shuffleSongs(user *gumble.User, username string) {
|
|
|
|
if dj.queue.Len() > 1 {
|
|
|
|
dj.queue.ShuffleSongs()
|
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(SHUFFLE_SUCCESS_MSG, username), false)
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, CANT_SHUFFLE_MSG)
|
|
|
|
}
|
|
|
|
}
|
2015-10-07 23:58:54 +02:00
|
|
|
|
|
|
|
// handles toggling of automatic shuffle playing
|
2015-12-14 04:34:33 +01:00
|
|
|
func toggleAutomaticShuffle(activate bool, user *gumble.User, username string) {
|
|
|
|
if dj.conf.General.AutomaticShuffleOn != activate {
|
2015-10-07 23:58:54 +02:00
|
|
|
dj.conf.General.AutomaticShuffleOn = activate
|
2015-12-14 04:34:33 +01:00
|
|
|
if activate {
|
2015-10-07 23:58:54 +02:00
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(SHUFFLE_ON_MESSAGE, username), false)
|
2015-12-14 04:34:33 +01:00
|
|
|
} else {
|
2015-10-07 23:58:54 +02:00
|
|
|
dj.client.Self.Channel.Send(fmt.Sprintf(SHUFFLE_OFF_MESSAGE, username), false)
|
|
|
|
}
|
2015-12-14 04:34:33 +01:00
|
|
|
} else if activate {
|
2015-10-07 23:58:54 +02:00
|
|
|
dj.SendPrivateMessage(user, SHUFFLE_ACTIVATED_ERROR_MESSAGE)
|
2015-12-14 04:34:33 +01:00
|
|
|
} else {
|
2015-10-07 23:58:54 +02:00
|
|
|
dj.SendPrivateMessage(user, SHUFFLE_DEACTIVATED_ERROR_MESSAGE)
|
|
|
|
}
|
|
|
|
}
|
2015-12-14 04:34:33 +01:00
|
|
|
|
|
|
|
// listSongs handles !listSongs functionality. Sends a private message to the user a list of all songs in the queue
|
|
|
|
func listSongs(user *gumble.User) {
|
|
|
|
if dj.audioStream.IsPlaying() {
|
|
|
|
var buffer bytes.Buffer
|
|
|
|
dj.queue.Traverse(func(i int, song Song) {
|
|
|
|
buffer.WriteString(fmt.Sprintf(SONG_LIST_HTML, song.Title(), song.Submitter()))
|
|
|
|
})
|
|
|
|
dj.SendPrivateMessage(user, buffer.String())
|
|
|
|
} else {
|
|
|
|
dj.SendPrivateMessage(user, NO_MUSIC_PLAYING_MSG)
|
|
|
|
}
|
|
|
|
}
|