Skip to content

Commit

Permalink
Apply requested changes (Pass 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichailiK committed Oct 5, 2019
1 parent e6f2b23 commit d616c1e
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceRemoveCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.DJCommand;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.User;

import java.util.List;
import java.util.concurrent.TimeUnit;


public class ForceRemoveCmd extends DJCommand
Expand All @@ -23,6 +25,7 @@ public ForceRemoveCmd(Bot bot)
this.aliases = new String[]{"forcedelete", "modremove", "moddelete"};
this.beListening = false;
this.bePlaying = true;
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
}

@Override
Expand Down Expand Up @@ -59,26 +62,16 @@ else if(found.size()>1)
builder.addChoice("**"+member.getUser().getName()+"**#"+member.getUser().getDiscriminator());
}

builder.setSelection((msg, i) ->
{
User selectedUser = found.get(i-1).getUser();
int count = handler.getQueue().removeAll(selectedUser.getIdLong());
if (count == 0)
{
event.replyWarning("**"+selectedUser.getName()+"** doesn't have any songs in the queue!");
}
else
{
event.replySuccess("Successfully removed `"+count+"` entries from **"+selectedUser.getName()+"**#"+selectedUser.getDiscriminator()+".");
}
})
builder
.setSelection((msg, i) -> removeAllEntries(found.get(i-1).getUser(), event))
.setText("Found multiple users:")
.setColor(event.getSelfMember().getColor())
.useNumbers()
.setUsers(event.getAuthor())
.useCancelButton(true)
.setCancel((msg) -> {})
.setEventWaiter(bot.getWaiter())
.setTimeout(1, TimeUnit.MINUTES)

.build().display(event.getChannel());

Expand All @@ -89,8 +82,13 @@ else if(found.size()>1)
target = found.get(0).getUser();
}

removeAllEntries(target, event);

}

int count = handler.getQueue().removeAll(target.getIdLong());
private void removeAllEntries(User target, CommandEvent event)
{
int count = ((AudioHandler) event.getGuild().getAudioManager().getSendingHandler()).getQueue().removeAll(target.getIdLong());
if (count == 0)
{
event.replyWarning("**"+target.getName()+"** doesn't have any songs in the queue!");
Expand All @@ -99,6 +97,5 @@ else if(found.size()>1)
{
event.replySuccess("Successfully removed `"+count+"` entries from **"+target.getName()+"**#"+target.getDiscriminator()+".");
}

}
}

0 comments on commit d616c1e

Please sign in to comment.