forked from jagrosh/MusicBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceRemoveCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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.MusicCommand; | ||
|
||
|
||
public class ForceRemoveCmd extends MusicCommand { | ||
public ForceRemoveCmd(Bot bot) { | ||
super(bot); | ||
this.name = "forceremove"; | ||
this.help = "removes all entries by the mentioned user from the queue"; | ||
this.arguments = "<@user|id>"; | ||
this.aliases = new String[]{"forcedelete"}; | ||
this.beListening = true; | ||
this.bePlaying = true; | ||
} | ||
|
||
@Override | ||
public void doCommand(CommandEvent event) { | ||
if (event.getArgs().isEmpty()) { | ||
event.replyError("You need to mention a user!"); | ||
} | ||
|
||
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler(); | ||
if (handler.getQueue().isEmpty()) { | ||
event.replyError("There is nothing in the queue!"); | ||
return; | ||
} | ||
|
||
long target = -1; | ||
String args = event.getArgs(); | ||
|
||
if (args.startsWith("<@") && args.endsWith(">")) { | ||
try { | ||
target = Long.parseLong(args.substring(2, args.length() - 1)); | ||
} catch (NumberFormatException ignored) {} | ||
} else if (args.startsWith("<@!") && args.endsWith(">")) { | ||
try { | ||
target = Long.parseLong(args.substring(3, args.length() - 1)); | ||
} catch (NumberFormatException ignored) {} | ||
} else { | ||
try { | ||
target = Long.parseLong(args); | ||
} catch (NumberFormatException ignored) { | ||
event.replyError("You need to mention a user!"); | ||
return; | ||
} | ||
} | ||
if (target <= 0) { | ||
event.replyError("You need to mention a user!"); | ||
return; | ||
} | ||
|
||
int count = handler.getQueue().removeAll(target); | ||
if (count == 0) | ||
event.replyWarning("This user doesn't have any songs in the queue!"); | ||
else | ||
event.replySuccess("Successfully removed their " + count + " entries."); | ||
|
||
} | ||
} |