[WIP] Added support for !shuffleon and !shuffleoff commands #39
This commit is contained in:
parent
03a51ed3b6
commit
2246695220
32
commands.go
32
commands.go
|
@ -161,6 +161,22 @@ func parseCommand(user *gumble.User, username, command string) {
|
||||||
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shuffleon command
|
||||||
|
case dj.conf.Aliases.ShuffleOnAlias:
|
||||||
|
if dj.HasPermission(username, dj.conf.Permissions.AdminShuffleToggle) {
|
||||||
|
toggleAutomaticShuffle(true, user, username)
|
||||||
|
} else {
|
||||||
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shuffleoff command
|
||||||
|
case dj.conf.Aliases.ShuffleOffAlias:
|
||||||
|
if dj.HasPermission(username, dj.conf.Permissions.AdminShuffleToggle) {
|
||||||
|
toggleAutomaticShuffle(false, user, username)
|
||||||
|
} else {
|
||||||
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dj.SendPrivateMessage(user, COMMAND_DOESNT_EXIST_MSG)
|
dj.SendPrivateMessage(user, COMMAND_DOESNT_EXIST_MSG)
|
||||||
}
|
}
|
||||||
|
@ -410,3 +426,19 @@ func shuffleSongs(user *gumble.User, username string) {
|
||||||
dj.SendPrivateMessage(user, CANT_SHUFFLE_MSG)
|
dj.SendPrivateMessage(user, CANT_SHUFFLE_MSG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handles toggling of automatic shuffle playing
|
||||||
|
func toggleAutomaticShuffle(activate bool, user *gumble.User, username string){
|
||||||
|
if (dj.conf.General.AutomaticShuffleOn != activate){
|
||||||
|
dj.conf.General.AutomaticShuffleOn = activate
|
||||||
|
if (activate){
|
||||||
|
dj.client.Self.Channel.Send(fmt.Sprintf(SHUFFLE_ON_MESSAGE, username), false)
|
||||||
|
} else{
|
||||||
|
dj.client.Self.Channel.Send(fmt.Sprintf(SHUFFLE_OFF_MESSAGE, username), false)
|
||||||
|
}
|
||||||
|
} else if (activate){
|
||||||
|
dj.SendPrivateMessage(user, SHUFFLE_ACTIVATED_ERROR_MESSAGE)
|
||||||
|
} else{
|
||||||
|
dj.SendPrivateMessage(user, SHUFFLE_DEACTIVATED_ERROR_MESSAGE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
12
config.gcfg
12
config.gcfg
|
@ -26,6 +26,10 @@ DefaultComment = "Hello! I am a bot. Type !help for a list of commands."
|
||||||
# Default Value: 0
|
# Default Value: 0
|
||||||
MaxSongDuration = 0
|
MaxSongDuration = 0
|
||||||
|
|
||||||
|
# Is playlist shuffling enabled when the bot starts?
|
||||||
|
# Default Value: false
|
||||||
|
AutomaticShuffleOn = false
|
||||||
|
|
||||||
[Cache]
|
[Cache]
|
||||||
|
|
||||||
# Cache songs as they are downloaded?
|
# Cache songs as they are downloaded?
|
||||||
|
@ -130,6 +134,14 @@ KillAlias = "kill"
|
||||||
# DEFAULT VALUE: "shuffle"
|
# DEFAULT VALUE: "shuffle"
|
||||||
ShuffleAlias = "shuffle"
|
ShuffleAlias = "shuffle"
|
||||||
|
|
||||||
|
# Alias used for shuffleon command
|
||||||
|
# DEFAULT VALUE: "shuffleon"
|
||||||
|
ShuffleOnAlias = "shuffleon"
|
||||||
|
|
||||||
|
# Alias used for shuffleoff command
|
||||||
|
# DEFAULT VALUE: "shuffleoff"
|
||||||
|
ShuffleOffAlias = "shuffleoff"
|
||||||
|
|
||||||
[Permissions]
|
[Permissions]
|
||||||
|
|
||||||
# Enable admins
|
# Enable admins
|
||||||
|
|
|
@ -22,6 +22,7 @@ type DjConfig struct {
|
||||||
PlaylistSkipRatio float32
|
PlaylistSkipRatio float32
|
||||||
DefaultComment string
|
DefaultComment string
|
||||||
MaxSongDuration int
|
MaxSongDuration int
|
||||||
|
AutomaticShuffleOn bool
|
||||||
}
|
}
|
||||||
Cache struct {
|
Cache struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
|
@ -52,6 +53,8 @@ type DjConfig struct {
|
||||||
CacheSizeAlias string
|
CacheSizeAlias string
|
||||||
KillAlias string
|
KillAlias string
|
||||||
ShuffleAlias string
|
ShuffleAlias string
|
||||||
|
ShuffleOnAlias string
|
||||||
|
ShuffleOffAlias string
|
||||||
}
|
}
|
||||||
Permissions struct {
|
Permissions struct {
|
||||||
AdminsEnabled bool
|
AdminsEnabled bool
|
||||||
|
@ -72,6 +75,7 @@ type DjConfig struct {
|
||||||
AdminCacheSize bool
|
AdminCacheSize bool
|
||||||
AdminKill bool
|
AdminKill bool
|
||||||
AdminShuffle bool
|
AdminShuffle bool
|
||||||
|
AdminShuffleToggle bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,10 @@ func (q *SongQueue) NextSong() {
|
||||||
// PeekNext peeks at the next Song and returns it.
|
// PeekNext peeks at the next Song and returns it.
|
||||||
func (q *SongQueue) PeekNext() (Song, error) {
|
func (q *SongQueue) PeekNext() (Song, error) {
|
||||||
if q.Len() > 1 {
|
if q.Len() > 1 {
|
||||||
|
if (dj.conf.General.AutomaticShuffleOn){ //Shuffle mode is active
|
||||||
|
swapIndex := 1 + rand.Intn(q.Len())
|
||||||
|
q.queue[offset], q.queue[swapIndex] = q.queue[swapIndex], q.queue[offset]
|
||||||
|
}
|
||||||
return q.queue[1], nil
|
return q.queue[1], nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("There isn't a Song coming up next.")
|
return nil, errors.New("There isn't a Song coming up next.")
|
||||||
|
|
20
strings.go
20
strings.go
|
@ -74,8 +74,20 @@ const CACHE_NOT_ENABLED_MSG = "The cache is not currently enabled."
|
||||||
// Message shown to user when they attempt to shuffle the a playlist with less than 2 elements.
|
// Message shown to user when they attempt to shuffle the a playlist with less than 2 elements.
|
||||||
const CANT_SHUFFLE_MSG = "Can't shuffle the playlist if there is less than 2 songs."
|
const CANT_SHUFFLE_MSG = "Can't shuffle the playlist if there is less than 2 songs."
|
||||||
|
|
||||||
// Message shown to user when the playlist has been successfully shuffled.
|
// Message shown to users when the playlist has been successfully shuffled.
|
||||||
const SHUFFLE_SUCCESS_MSG = "The playlist has been successfully shuffled by <b>%s</b> (starting from next song)."
|
const SHUFFLE_SUCCESS_MSG = "The current playlist has been successfully shuffled by <b>%s</b> (starting from next song)."
|
||||||
|
|
||||||
|
// Message shown to users when automatic shuffle is activated
|
||||||
|
const SHUFFLE_ON_MESSAGE = "<b>%s</b> has turned automatic shuffle on."
|
||||||
|
|
||||||
|
// Message shown to users when automatic shuffle is deactivated
|
||||||
|
const SHUFFLE_OFF_MESSAGE = "<b>%s</b> has turned automatic shuffle off."
|
||||||
|
|
||||||
|
// Message shown to user when they attempt to enable automatic shuffle while it's already activated
|
||||||
|
const SHUFFLE_ACTIVATED_ERROR_MESSAGE = "Automatic shuffle is already activated."
|
||||||
|
|
||||||
|
// Message shown to user when they attempt to disable automatic shuffle while it's already deactivated
|
||||||
|
const SHUFFLE_DEACTIVATED_ERROR_MESSAGE = "Automatic shuffle is already deactivated."
|
||||||
|
|
||||||
// Message shown to channel when a song is added to the queue by a user.
|
// Message shown to channel when a song is added to the queue by a user.
|
||||||
const SONG_ADDED_HTML = `
|
const SONG_ADDED_HTML = `
|
||||||
|
@ -113,7 +125,9 @@ const HELP_HTML = `<br/>
|
||||||
<p><b>!reset</b> - An admin command that resets the song queue. </p>
|
<p><b>!reset</b> - An admin command that resets the song queue. </p>
|
||||||
<p><b>!forceskip</b> - An admin command that forces a song skip. </p>
|
<p><b>!forceskip</b> - An admin command that forces a song skip. </p>
|
||||||
<p><b>!forceskipplaylist</b> - An admin command that forces a playlist skip. </p>
|
<p><b>!forceskipplaylist</b> - An admin command that forces a playlist skip. </p>
|
||||||
<p><b>!shuffle</b> - An admin command that shuffles the playlist. </p>
|
<p><b>!shuffle</b> - An admin command that shuffles the current playlist. </p>
|
||||||
|
<p><b>!shuffleon</b> - An admin command that enables auto shuffling.</p>
|
||||||
|
<p><b>!shuffleoff</b> - An admin command that disables auto shuffling.</p>
|
||||||
<p><b>!move </b>- Moves MumbleDJ into channel if it exists.</p>
|
<p><b>!move </b>- Moves MumbleDJ into channel if it exists.</p>
|
||||||
<p><b>!reload</b> - Reloads mumbledj.gcfg configuration settings.</p>
|
<p><b>!reload</b> - Reloads mumbledj.gcfg configuration settings.</p>
|
||||||
<p><b>!setcomment</b> - Sets the comment for the bot.</p>
|
<p><b>!setcomment</b> - Sets the comment for the bot.</p>
|
||||||
|
|
Reference in a new issue