Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to shuffle all requests regardless of requester #1358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private static void startBot()
new PauseCmd(bot),
new PlaynextCmd(bot),
new RepeatCmd(bot),
new ShuffleAllCmd(bot),
new SkiptoCmd(bot),
new StopCmd(bot),
new VolumeCmd(bot),
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/commands/dj/ShuffleAllCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2019 John Grosh <[email protected]>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jagrosh.jmusicbot.commands.dj;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.DJCommand;

/**
*
* @author Joshua L.
*/
public class ShuffleAllCmd extends DJCommand
{
public ShuffleAllCmd(Bot bot)
{
super(bot);
this.name = "shuffleall";
this.help = "shuffles all songs in the queue";
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
}

@Override
public void doCommand(CommandEvent event)
{
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
int s = handler.getQueue().shuffle(0, true);
switch (s)
{
case 0:
event.replyError("There isn't any music in the queue to shuffle!");
break;
case 1:
event.replyWarning("There is only one song in the queue!");
break;
default:
event.replySuccess("You successfully shuffled "+s+" entries.");
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ShuffleCmd(Bot bot)
public void doCommand(CommandEvent event)
{
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
int s = handler.getQueue().shuffle(event.getAuthor().getIdLong());
int s = handler.getQueue().shuffle(event.getAuthor().getIdLong(), false);
switch (s)
{
case 0:
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/com/jagrosh/jmusicbot/queue/FairQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,26 @@ public void clear()
list.clear();
}

public int shuffle(long identifier)
public int shuffle(long identifier, Boolean shuffleall)
{
List<Integer> iset = new ArrayList<>();
for(int i=0; i<list.size(); i++)
if (shuffleall)
{
if(list.get(i).getIdentifier()==identifier)
iset.add(i);
for (int i=0; i<list.size(); i++)
{
iset.add(i);
}
}
else
{
for (int i=0; i<list.size(); i++)
{
if (list.get(i).getIdentifier()==identifier)
iset.add(i);
}
}
for(int j=0; j<iset.size(); j++)

for (int j=0; j<iset.size(); j++)
{
int first = iset.get(j);
int second = iset.get((int)(Math.random()*iset.size()));
Expand Down