Added and improved music player controls

This commit is contained in:
2020-08-05 22:29:17 -05:00
parent b63ec31138
commit 6c2f1900c2
38 changed files with 958 additions and 377 deletions

View File

@@ -1,90 +0,0 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.audio.AudioHandler;
import com.fpghoti.biscuit.audio.AudioResultHandler;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.managers.AudioManager;
public class PlayCommand extends MusicClientCommand{
public PlayCommand() {
name = "Play";
description = "Plays the specified song or plays a song found using search parameters.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "play <YouTube link OR Search Phrase>";
minArgs = 1;
maxArgs = 2000;
identifiers.add("play");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Guild guild = event.getGuild();
Biscuit b = Biscuit.getBiscuit(guild);
TextChannel tchannel = event.getChannel();
String searchPhrase = args[0];
if(args.length > 1) {
for(int i = 1; i < args.length; i++) {
searchPhrase = searchPhrase + " " + args[i];
}
}
b.log(event.getAuthor().getName() + " issued a command: -play " + searchPhrase);
String vcname = "";
if(!event.getMember().getVoiceState().inVoiceChannel()) {
MessageText.send(tchannel, "You must be in a voice channel to do this!");
return;
}
vcname = event.getMember().getVoiceState().getChannel().getName();
String[] musicChannels = b.getProperties().getMusicChannels();
if(musicChannels.length >= 1) {
boolean found = false;
for(String cname : musicChannels) {
if(event.getMember().getVoiceState().getChannel().getName().equalsIgnoreCase(cname)) {
found = true;
break;
}
}
if(found == false) {
MessageText.send(tchannel, "You are not in a channel that is authorized to use the music player.");
return;
}
}
if(b.getAudioPlayer().getPlayingTrack() != null && guild.getAudioManager().isConnected() && !guild.getAudioManager().getConnectedChannel().getMembers().contains(event.getMember())) {
MessageText.send(tchannel, "Music is already playing in a voice channel. Connect to "
+ "that channel, then queue your song.");
return;
}
VoiceChannel channel = guild.getVoiceChannelsByName(vcname, true).get(0);
AudioManager manager = guild.getAudioManager();
manager.setSendingHandler(new AudioHandler(b.getAudioPlayer()));
manager.openAudioConnection(channel);
AudioPlayerManager playerManager = Main.getPlayerManager();
String vidid = getID(event.getMessage().getContentRaw().split(" ")[1]);
playerManager.loadItemOrdered(guild, vidid, new AudioResultHandler(event.getAuthor().getId(), tchannel, false, searchPhrase, false, false));
}
private String getID(String url) {
String[] s = url.split("=");
if(s.length > 1) {
return s[1].split("&")[0];
}
return url;
}
}

View File

@@ -1,97 +0,0 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.audio.AudioHandler;
import com.fpghoti.biscuit.audio.AudioResultHandler;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.managers.AudioManager;
public class PlayFirstCommand extends MusicClientCommand{
public PlayFirstCommand() {
name = "Play First";
description = "Places specified song at the front of the queue.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "playfirst <YouTube link OR Search Phrase>";
minArgs = 1;
maxArgs = 2000;
identifiers.add("playfirst");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Guild guild = event.getGuild();
Biscuit b = Biscuit.getBiscuit(guild);
TextChannel tchannel = event.getChannel();
String searchPhrase = args[0];
if(args.length > 1) {
for(int i = 1; i < args.length; i++) {
searchPhrase = searchPhrase + " " + args[i];
}
}
b.log(event.getAuthor().getName() + " issued a command: -play " + searchPhrase);
String vcname = "";
if(!PermUtil.isMod(event.getMember())) {
MessageText.send(tchannel, "You do not have permission to do this!");
return;
}
if(!event.getMember().getVoiceState().inVoiceChannel()) {
MessageText.send(tchannel, "You must be in a voice channel to do this!");
return;
}
vcname = event.getMember().getVoiceState().getChannel().getName();
String[] musicChannels = b.getProperties().getMusicChannels();
if(musicChannels.length >= 1) {
boolean found = false;
for(String cname : musicChannels) {
if(event.getMember().getVoiceState().getChannel().getName().equalsIgnoreCase(cname)) {
found = true;
break;
}
}
if(found == false) {
MessageText.send(tchannel, "You are not in a channel that is authorized to use the music player.");
return;
}
}
if(b.getAudioPlayer().getPlayingTrack() != null && guild.getAudioManager().isConnected() && !guild.getAudioManager().getConnectedChannel().getMembers().contains(event.getMember())) {
MessageText.send(tchannel, "Music is already playing in a voice channel. Connect to "
+ "that channel, then queue your song.");
return;
}
VoiceChannel channel = guild.getVoiceChannelsByName(vcname, true).get(0);
AudioManager manager = guild.getAudioManager();
manager.setSendingHandler(new AudioHandler(b.getAudioPlayer()));
manager.openAudioConnection(channel);
AudioPlayerManager playerManager = Main.getPlayerManager();
String vidid = getID(event.getMessage().getContentRaw().split(" ")[1]);
playerManager.loadItemOrdered(guild, vidid, new AudioResultHandler(event.getAuthor().getId(), tchannel, false, searchPhrase, true, false));
}
private String getID(String url) {
String[] s = url.split("=");
if(s.length > 1) {
return s[1].split("&")[0];
}
return url;
}
}

View File

@@ -1,72 +0,0 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class SkipCommand extends MusicClientCommand{
public SkipCommand() {
name = "Skip";
description = "Sends a vote to skip the song that is currently playing.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "skip";
minArgs = 0;
maxArgs = 0;
identifiers.add("skip");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
//TODO Redo vote skipping. It does not function correctly.
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -skip");
if(b.getAudioPlayer().getPlayingTrack() == null) {
MessageText.send(event.getChannel(), "There is not a song playing for you to skip!");
return;
}
if(!event.getGuild().getAudioManager().getConnectedChannel().getMembers().contains(event.getMember())) {
MessageText.send(event.getChannel(), "You need to be in the same voice channel in order to skip!");
return;
}
if(b.getAudioScheduler().getVotes() >= (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) / 2) {
MessageText.send(event.getChannel(), "Skip vote status: **[" + ( b.getAudioScheduler().getVotes() + 1) + "/"
+ (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) + "]**"
+ "\nSkipping current track.");
if(b.getAudioScheduler().getQueue().getNext() != null ) {
MessageEmbed next = b.getAudioScheduler().getQueue().getNext().getEmbedMessage("Now Playing:");
MessageText.send(event.getChannel(), next);
}
b.getAudioScheduler().skip();
return;
}
if(b.getAudioScheduler().voteSkip(event.getAuthor().getId())) {
MessageText.send(event.getChannel(), "You voted to skip the current track.");
}else {
MessageText.send(event.getChannel(), "You cannot vote to skip this track again."
+ "\nSkip vote status: **[" + b.getAudioScheduler().getVotes() + "/"
+ (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) + "]**");
}
if(b.getAudioScheduler().getVotes() >= (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) / 2) {
MessageText.send(event.getChannel(), "Skip vote status: **[" + b.getAudioScheduler().getVotes() + "/"
+ event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() + "]**"
+ "\nSkipping current track.");
if(b.getAudioScheduler().getQueue().getNext() != null ) {
MessageEmbed next = b.getAudioScheduler().getQueue().getNext().getEmbedMessage("Now Playing:");
MessageText.send(event.getChannel(), next);
}
b.getAudioScheduler().skip();
}
}
}

View File

@@ -0,0 +1,32 @@
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class ClearCommand extends MusicClientCommand{
public ClearCommand() {
name = "Clear";
description = "Clears all upcoming songs from the queue.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "clear";
minArgs = 0;
maxArgs = 0;
identifiers.add("clear");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -clear");
if(PermUtil.hasMusicControl(event.getMember())) {
MessageText.send(event.getChannel(), "Cleared all upcoming songs from the queue.");
b.getAudioScheduler().getQueue().clear();
}
}
}

View File

@@ -0,0 +1,36 @@
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class ClearUserSongsCommand extends MusicClientCommand{
public ClearUserSongsCommand() {
name = "Clear User Songs";
description = "Clears all upcoming songs from specified user.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "clearusersongs <@user>";
minArgs = 1;
maxArgs = 1;
identifiers.add("clearusersongs");
identifiers.add("cus");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -clearusersongs " + args[0]);
if(PermUtil.hasMusicControl(event.getMember())) {
for(Member m : event.getMessage().getMentionedMembers()) {
MessageText.send(event.getChannel(), "Clearing all upcoming tracks added by **" + m.getEffectiveName() + "**.");
b.getAudioScheduler().getQueue().removeUserTracks(m.getId());
}
}
}
}

View File

@@ -1,4 +1,4 @@
package com.fpghoti.biscuit.commands.client;
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
@@ -6,7 +6,6 @@ import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class ForceSkipCommand extends MusicClientCommand{
@@ -24,13 +23,9 @@ public class ForceSkipCommand extends MusicClientCommand{
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -forceskip");
if(PermUtil.isMod(event.getMember())) {
if(PermUtil.hasMusicControl(event.getMember())) {
MessageText.send(event.getChannel(), "Force skipping current song.");
if(b.getAudioScheduler().getQueue().getNext() != null ) {
MessageEmbed next = b.getAudioScheduler().getQueue().getNext().getEmbedMessage("Now Playing:");
MessageText.send(event.getChannel(), next);
}
b.getAudioScheduler().skip();
b.getAudioScheduler().skip(event.getChannel());
}
}

View File

@@ -0,0 +1,38 @@
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class ForceSkipToCommand extends MusicClientCommand{
public ForceSkipToCommand() {
name = "Force Skip To";
description = "Force skips all songs until the specified track.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "forceskipto <Track #>";
minArgs = 1;
maxArgs = 1;
identifiers.add("forceskipto");
identifiers.add("fst");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -forceskipto " + args[0]);
if(PermUtil.hasMusicControl(event.getMember())) {
if(Util.isDigit(args[0])) {
int place = Integer.parseInt(args[0]);
MessageText.send(event.getChannel(), "Force skipping to queue position **" + place + "**.");
b.getAudioScheduler().getQueue().removeTracksBefore(place);
b.getAudioScheduler().skip(event.getChannel());
}
}
}
}

View File

@@ -1,4 +1,4 @@
package com.fpghoti.biscuit.commands.client;
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
@@ -23,7 +23,7 @@ public class LoopMusicCommand extends MusicClientCommand{
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -loopmusic");
if(PermUtil.isMod(event.getMember())) {
if(PermUtil.hasMusicControl(event.getMember())) {
if(!b.getAudioScheduler().isLooping()) {
MessageText.send(event.getChannel(), "Setting all music to loop.");
b.getAudioScheduler().setLooping(true);

View File

@@ -0,0 +1,37 @@
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class MoveToCommand extends MusicClientCommand{
public MoveToCommand() {
name = "Move To";
description = "Moves track to specified position.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "moveto <Track #>";
minArgs = 2;
maxArgs = 2;
identifiers.add("moveto");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -moveto " + args[0] + " " + args[1]);
if(PermUtil.hasMusicControl(event.getMember())) {
if(Util.isDigit(args[0]) && Util.isDigit(args[1])) {
int oldPlace = Integer.parseInt(args[0]);
int newPlace = Integer.parseInt(args[1]);
MessageText.send(event.getChannel(), "The specified track was moved." );
b.getAudioScheduler().getQueue().moveToPlace(oldPlace, newPlace);
}
}
}
}

View File

@@ -1,4 +1,4 @@
package com.fpghoti.biscuit.commands.client;
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;

View File

@@ -1,4 +1,4 @@
package com.fpghoti.biscuit.commands.client;
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
@@ -23,7 +23,7 @@ public class PauseCommand extends MusicClientCommand{
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -pause");
if(PermUtil.isMod(event.getMember())) {
if(PermUtil.hasMusicControl(event.getMember())) {
if(!b.getAudioPlayer().isPaused()) {
b.getAudioPlayer().setPaused(true);
MessageText.send(event.getChannel(), "Paused the current track.");

View File

@@ -0,0 +1,42 @@
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.audio.PlayCommandUtil;
import com.fpghoti.biscuit.audio.request.youtube.YTRequest;
import com.fpghoti.biscuit.audio.result.YTResultHandler;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class PlayCommand extends MusicClientCommand{
public PlayCommand() {
name = "Play";
description = "Plays the specified song or plays a song found using search parameters.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "play <YouTube link OR Search Phrase>";
minArgs = 1;
maxArgs = 2000;
identifiers.add("play");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Guild guild = event.getGuild();
Biscuit b = Biscuit.getBiscuit(guild);
String searchPhrase = PlayCommandUtil.getSearchPhrase(args);
b.log(event.getAuthor().getName() + " issued a command: -play " + searchPhrase);
boolean connected = PlayCommandUtil.connectToChannel(event);
if(!connected) {
return;
}
YTRequest request = new YTRequest(event.getMessage(), searchPhrase);
Main.getPlayerManager().loadItemOrdered(guild, PlayCommandUtil.getID(event), new YTResultHandler(request));
}
}

View File

@@ -0,0 +1,52 @@
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.audio.PlayCommandUtil;
import com.fpghoti.biscuit.audio.request.youtube.YTPriorityRequest;
import com.fpghoti.biscuit.audio.request.youtube.YTRequest;
import com.fpghoti.biscuit.audio.result.YTResultHandler;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class PlayFirstCommand extends MusicClientCommand{
public PlayFirstCommand() {
name = "Play First";
description = "Places specified song at the front of the queue.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "playfirst <YouTube link OR Search Phrase>";
minArgs = 1;
maxArgs = 2000;
identifiers.add("playfirst");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Guild guild = event.getGuild();
Biscuit b = Biscuit.getBiscuit(guild);
TextChannel tchannel = event.getChannel();
String searchPhrase = PlayCommandUtil.getSearchPhrase(args);
b.log(event.getAuthor().getName() + " issued a command: -playfirst " + searchPhrase);
if(!PermUtil.hasMusicControl(event.getMember())) {
MessageText.send(tchannel, "You do not have permission to do this!");
return;
}
boolean connected = PlayCommandUtil.connectToChannel(event);
if(!connected) {
return;
}
YTRequest request = new YTPriorityRequest(event.getMessage(), searchPhrase, 1);
Main.getPlayerManager().loadItemOrdered(guild, PlayCommandUtil.getID(event), new YTResultHandler(request));
}
}

View File

@@ -1,4 +1,4 @@
package com.fpghoti.biscuit.commands.client;
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.audio.queue.AudioQueue;

View File

@@ -0,0 +1,36 @@
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class RemoveCommand extends MusicClientCommand{
public RemoveCommand() {
name = "Remove";
description = "Removes song from specified position in queue.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "remove <Track #>";
minArgs = 1;
maxArgs = 1;
identifiers.add("remove");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -remove " + args[0]);
if(PermUtil.hasMusicControl(event.getMember())) {
if(Util.isDigit(args[0])) {
int place = Integer.parseInt(args[0]);
MessageText.send(event.getChannel(), "Removing track at position **" + place + "**.");
b.getAudioScheduler().getQueue().removeTrack(place);
}
}
}
}

View File

@@ -0,0 +1,33 @@
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class ShuffleCommand extends MusicClientCommand{
public ShuffleCommand() {
name = "Shuffle";
description = "Shuffles the sender's songs in the queue.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "shuffle";
minArgs = 0;
maxArgs = 0;
identifiers.add("shuffle");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -shuffle");
if(b.getAudioScheduler().getQueue().getLastTrack() != null ) {
b.getAudioScheduler().getQueue().shuffleUserTracks(event.getAuthor().getId());
MessageText.send(event.getChannel(), "All songs that you have added to the queue have been shuffled.");
}else {
MessageText.send(event.getChannel(), "No song is currently playing.");
}
}
}

View File

@@ -0,0 +1,33 @@
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class SkipAllCommand extends MusicClientCommand{
public SkipAllCommand() {
name = "Skip All";
description = "Forces the all songs to be skipped.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "skipall";
minArgs = 0;
maxArgs = 0;
identifiers.add("skipall");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -skipall");
if(PermUtil.hasMusicControl(event.getMember())) {
MessageText.send(event.getChannel(), "Force skipping all songs.");
b.getAudioScheduler().getQueue().clear();
b.getAudioScheduler().skip(event.getChannel());
}
}
}

View File

@@ -0,0 +1,126 @@
package com.fpghoti.biscuit.commands.client.music;
import java.util.ArrayList;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.audio.AudioScheduler;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class SkipCommand extends MusicClientCommand{
public SkipCommand() {
name = "Skip";
description = "Sends a vote to skip the song that is currently playing.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "skip";
minArgs = 0;
maxArgs = 0;
identifiers.add("skip");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Guild guild = event.getGuild();
Biscuit biscuit = Biscuit.getBiscuit(guild);
biscuit.log(event.getAuthor().getName() + " issued a command: -skip");
TextChannel cmdChannel = event.getChannel();
//Bot is not connected to voice channel. Do nothing.
if(!guild.getAudioManager().isConnected()) {
MessageText.send(event.getChannel(), "The music player is not connected to a voice channel!");
return;
}
VoiceChannel voice = guild.getAudioManager().getConnectedChannel();
//Bot is connected to a voice channel in the guild, and the command sender is not in the channel.
//Do nothing
if(!voice.getMembers().contains(event.getMember())) {
MessageText.send(cmdChannel, "You need to be in the same voice channel in order to skip!");
return;
}
//No song is playing. Do nothing.
if(biscuit.getAudioPlayer().getPlayingTrack() == null) {
MessageText.send(cmdChannel, "There is not a song playing for you to skip!");
return;
}
AudioScheduler sched = biscuit.getAudioScheduler();
boolean skip = false;
//Get number of users connected to the channel
int count = nonBotCount(voice);
//Determine amount of votes needed to skip
int votesNeeded = count / 2;
if(votesNeeded * 2 < count) {
votesNeeded++;
}
int votes = 1;
//If sender alone
if(count == 1) {
skip = true; //approve skip
}else{
String id = event.getAuthor().getId();
//Check if command sender has already voted
if(sched.hasSkipped(id)) {
MessageText.send(cmdChannel, "You have already voted to skip!");
return;
}
//Save vote
sched.voteSkip(id);
//Get updated vote count
votes = sched.getVotes();
//Check if enough to skip
if(votes >= votesNeeded) {
skip = true; //approve skip
}
}
if(skip) {
//Skip has been approved, so skip
MessageText.send(cmdChannel, "**" + votes + "/" + count + "** voted to skip. Skipping current track.");
sched.skip(cmdChannel);
}else {
//Skip has not been approved, so send vote update message
int remaining = votesNeeded - votes;
String words = " vote is ";
if(remaining != 1) { //make word singular/plural as needed
words = " votes are ";
}
MessageText.send(cmdChannel, "**" + votes + "/" + count + "** voted to skip. **" + remaining + "** more" + words + "needed to"
+ " skip the current track.");
}
}
private int nonBotCount(VoiceChannel c) {
int count = 0;
ArrayList<Member> members = new ArrayList<Member>(c.getMembers());
for(Member m : members) {
if(!m.getUser().isBot()) {
count++;
}
}
return count;
}
}

View File

@@ -1,4 +1,4 @@
package com.fpghoti.biscuit.commands.client;
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
@@ -24,7 +24,7 @@ public class TogglePauseCommand extends MusicClientCommand{
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -togglepause");
if(PermUtil.isMod(event.getMember())) {
if(PermUtil.hasMusicControl(event.getMember())) {
if(b.getAudioPlayer().isPaused()) {
b.getAudioPlayer().setPaused(false);
MessageText.send(event.getChannel(), "Unpaused the current track.");

View File

@@ -1,14 +1,14 @@
package com.fpghoti.biscuit.commands.client;
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.ClientCommand;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class UnpauseCommand extends ClientCommand{
public class UnpauseCommand extends MusicClientCommand{
public UnpauseCommand() {
name = "Unpause";
@@ -17,13 +17,14 @@ public class UnpauseCommand extends ClientCommand{
minArgs = 0;
maxArgs = 0;
identifiers.add("unpause");
identifiers.add("resume");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -unpause");
if(PermUtil.isMod(event.getMember())) {
if(PermUtil.hasMusicControl(event.getMember())) {
if(b.getAudioPlayer().isPaused()) {
b.getAudioPlayer().setPaused(false);
MessageText.send(event.getChannel(), "Unpaused the current track.");

View File

@@ -0,0 +1,50 @@
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
import com.fpghoti.biscuit.rest.MessageText;
import com.fpghoti.biscuit.util.PermUtil;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class VolumeCommand extends MusicClientCommand{
public VolumeCommand() {
name = "Volume";
description = "Changes the player volume or displays the current volume.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "volume [0-150]";
minArgs = 0;
maxArgs = 1;
identifiers.add("volume");
identifiers.add("vol");
}
@Override
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
if(args.length < 1) {
b.log(event.getAuthor().getName() + " issued a command: -volume");
MessageText.send(event.getChannel(), "The current volume is: **" + b.getAudioPlayer().getVolume() + "**.");
return;
}
b.log(event.getAuthor().getName() + " issued a command: -volume " + args[0]);
if(PermUtil.hasMusicControl(event.getMember())) {
if(Util.isDigit(args[0])) {
int vol = Integer.parseInt(args[0]);
if(vol < 0) {
vol = 0;
}else if(vol > 150) {
vol = 150;
}
b.getAudioPlayer().setVolume(vol);
MessageText.send(event.getChannel(), "The volume was set to **" + b.getAudioPlayer().getVolume() + "**.");
}
}
}
}

View File

@@ -1,4 +1,4 @@
package com.fpghoti.biscuit.commands.client;
package com.fpghoti.biscuit.commands.client.music;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
@@ -24,7 +24,7 @@ public class WipeQueueCommand extends MusicClientCommand{
public void execute(String[] args, GuildMessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -wipequeue");
if(PermUtil.isMod(event.getMember())) {
if(PermUtil.hasMusicControl(event.getMember())) {
b.getAudioScheduler().wipeQueue();
MessageText.send(event.getChannel(), "Removed upcoming songs from the music queue.");
}