Some music bot functionality added
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
package com.fpghoti.biscuit.commands;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.logging.BiscuitLog;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
public class CommandListener extends ListenerAdapter implements Runnable {
|
||||
|
||||
private Scanner sc;
|
||||
private BiscuitLog log;
|
||||
|
||||
public CommandListener(Scanner sc, BiscuitLog log) {
|
||||
this.sc = sc;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event){
|
||||
if (event.isFromType(ChannelType.TEXT)) {
|
||||
Biscuit b = Biscuit.getBiscuit(event.getGuild());
|
||||
if(PermUtil.isAdmin(event.getMember()) || !b.getProperties().restrictCmdChannels() || (b.getProperties().restrictCmdChannels() && isBotChannel(event.getTextChannel()))) {
|
||||
if(!event.getAuthor().isBot() && event.getMessage().getContentDisplay().startsWith(b.getProperties().getCommandSignifier()) && event.getMessage().getAuthor().getId() != event.getJDA().getSelfUser().getId()){
|
||||
CommandManager.parse(event.getMessage().getContentRaw().toLowerCase(), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isBotChannel(TextChannel c) {
|
||||
Biscuit b = Biscuit.getBiscuit(c.getGuild());
|
||||
for(String s : b.getProperties().getCmdChannels()) {
|
||||
if(s.equals(c.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
while(sc.hasNextLine()) {
|
||||
String command = sc.nextLine();
|
||||
String label = command.split(" ")[0];
|
||||
String[] args = new String[command.split(" ").length - 1];
|
||||
for(int i = 1; i < command.split(" ").length; i++) {
|
||||
args[i - 1] = command.split(" ")[i];
|
||||
}
|
||||
runCommand(label, args);
|
||||
}
|
||||
}
|
||||
|
||||
private void runCommand(String label, String[] args) {
|
||||
log.info(label);
|
||||
CommandManager.dispatch(label, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,10 @@ import java.util.List;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ConsoleCommand;
|
||||
import com.fpghoti.biscuit.commands.base.CustomCommand;
|
||||
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
import com.fpghoti.biscuit.util.Util;
|
||||
|
||||
@@ -69,6 +73,11 @@ public class CommandManager {
|
||||
}
|
||||
|
||||
if(match != null) {
|
||||
|
||||
if(match instanceof MusicClientCommand && !b.getProperties().allowMusicBot()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (trimmedArgs == null || (trimmedArgs.length > 0 && trimmedArgs[0].equals("?"))) {
|
||||
commandReply(e, "``Command:" + " " + match.getName() + "``");
|
||||
commandReply(e, "``Description:" + " " + match.getDescription() + "``");
|
||||
@@ -118,6 +127,9 @@ public class CommandManager {
|
||||
}
|
||||
|
||||
public static void addCommand(BaseCommand command) {
|
||||
if(command instanceof MusicClientCommand && !Main.getMainBiscuit().getProperties().musicBotEnabled()) {
|
||||
return;
|
||||
}
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package com.fpghoti.biscuit.commands;
|
||||
package com.fpghoti.biscuit.commands.base;
|
||||
|
||||
import com.fpghoti.biscuit.commands.BaseCommand;
|
||||
import com.fpghoti.biscuit.commands.CommandType;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package com.fpghoti.biscuit.commands;
|
||||
package com.fpghoti.biscuit.commands.base;
|
||||
|
||||
import com.fpghoti.biscuit.commands.BaseCommand;
|
||||
import com.fpghoti.biscuit.commands.CommandType;
|
||||
|
||||
public abstract class ConsoleCommand extends BaseCommand{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.fpghoti.biscuit.commands;
|
||||
package com.fpghoti.biscuit.commands.base;
|
||||
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.BaseCommand;
|
||||
import com.fpghoti.biscuit.commands.CommandType;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.fpghoti.biscuit.commands.base;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public abstract class MusicClientCommand extends ClientCommand{
|
||||
|
||||
public abstract void execute(String[] args, MessageReceivedEvent event);
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.Util;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.Util;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
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.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class ForceSkipCommand extends MusicClientCommand{
|
||||
|
||||
public ForceSkipCommand() {
|
||||
name = "Force Skip";
|
||||
description = "Forces the current song to be skipped.";
|
||||
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "forceskip";
|
||||
minArgs = 0;
|
||||
maxArgs = 0;
|
||||
identifiers.add("forceskip");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, MessageReceivedEvent event) {
|
||||
Biscuit b = Biscuit.getBiscuit(event.getGuild());
|
||||
b.log(event.getAuthor().getName() + " issued a command: -forceskip");
|
||||
if(PermUtil.isMod(event.getMember())) {
|
||||
event.getChannel().sendMessage("Force skipping current song.").queue();
|
||||
if(b.getAudioScheduler().getNextMessage() != null ) {
|
||||
event.getChannel().sendMessage(b.getAudioScheduler().getNextMessage()).queue();
|
||||
}
|
||||
b.getAudioScheduler().skip();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.logging.BColor;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -6,9 +6,10 @@ import java.util.List;
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.BaseCommand;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.CommandManager;
|
||||
import com.fpghoti.biscuit.commands.CustomCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.CustomCommand;
|
||||
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
|
||||
import com.fpghoti.biscuit.util.Util;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
@@ -38,7 +39,7 @@ public class HelpCommand extends ClientCommand {
|
||||
}
|
||||
}
|
||||
List<BaseCommand> commands = new ArrayList<BaseCommand>();
|
||||
|
||||
|
||||
String[] ccs = biscuit.getProperties().getCustomCmds();
|
||||
for(String s : ccs) {
|
||||
if(!Util.contains(biscuit.getProperties().disabledCommands(), s)) {
|
||||
@@ -53,11 +54,17 @@ public class HelpCommand extends ClientCommand {
|
||||
commands.add(cc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(BaseCommand bc : CommandManager.getCommands()) {
|
||||
String bclabel = bc.getUsage().split(" ")[0];
|
||||
if(!Util.contains(biscuit.getProperties().disabledCommands(), bclabel.replace(Main.getMainBiscuit().getProperties().getCommandSignifier(), ""))) {
|
||||
commands.add(bc);
|
||||
if(bc instanceof MusicClientCommand) {
|
||||
if(biscuit.getProperties().allowMusicBot()) {
|
||||
commands.add(bc);
|
||||
}
|
||||
}else {
|
||||
commands.add(bc);
|
||||
}
|
||||
}
|
||||
}
|
||||
int pageCount = (int) Math.ceil((double) commands.size() / 8);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
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.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class LoopMusicCommand extends MusicClientCommand{
|
||||
|
||||
public LoopMusicCommand() {
|
||||
name = "Loop Music";
|
||||
description = "Enables looping of all songs played.";
|
||||
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "loopmusic";
|
||||
minArgs = 0;
|
||||
maxArgs = 0;
|
||||
identifiers.add("loopmusic");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, MessageReceivedEvent event) {
|
||||
Biscuit b = Biscuit.getBiscuit(event.getGuild());
|
||||
b.log(event.getAuthor().getName() + " issued a command: -loopmusic");
|
||||
if(PermUtil.isMod(event.getMember())) {
|
||||
if(!b.getAudioScheduler().isLooping()) {
|
||||
event.getChannel().sendMessage("Setting all music to loop.").queue();
|
||||
b.getAudioScheduler().setLooping(true);
|
||||
}else {
|
||||
event.getChannel().sendMessage("Disabling music looping.").queue();
|
||||
b.getAudioScheduler().setLooping(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
import com.fpghoti.biscuit.util.Util;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.Util;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
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.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class NowPlayingCommand extends MusicClientCommand{
|
||||
|
||||
public NowPlayingCommand() {
|
||||
name = "Now Playing";
|
||||
description = "Displays the currently playing song.";
|
||||
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "nowplaying";
|
||||
minArgs = 0;
|
||||
maxArgs = 0;
|
||||
identifiers.add("nowplaying");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, MessageReceivedEvent event) {
|
||||
Biscuit b = Biscuit.getBiscuit(event.getGuild());
|
||||
b.log(event.getAuthor().getName() + " issued a command: -nowplaying");
|
||||
if(b.getAudioPlayer().getPlayingTrack() != null) {
|
||||
AudioTrack track = b.getAudioPlayer().getPlayingTrack();
|
||||
event.getChannel().sendMessage(b.getAudioScheduler().getMessage(track, true)).queue();
|
||||
}else {
|
||||
event.getChannel().sendMessage("No song is currently playing.").queue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
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.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class PauseCommand extends MusicClientCommand{
|
||||
|
||||
public PauseCommand() {
|
||||
name = "Pause";
|
||||
description = "Pauses the current track.";
|
||||
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "pause";
|
||||
minArgs = 0;
|
||||
maxArgs = 0;
|
||||
identifiers.add("pause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, MessageReceivedEvent event) {
|
||||
Biscuit b = Biscuit.getBiscuit(event.getGuild());
|
||||
b.log(event.getAuthor().getName() + " issued a command: -pause");
|
||||
if(PermUtil.isMod(event.getMember())) {
|
||||
if(!b.getAudioPlayer().isPaused()) {
|
||||
b.getAudioPlayer().setPaused(true);
|
||||
event.getChannel().sendMessage("Paused the current track.").queue();
|
||||
}else {
|
||||
event.getChannel().sendMessage("The music player is already paused.").queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
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.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.MessageReceivedEvent;
|
||||
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, MessageReceivedEvent event) {
|
||||
Guild guild = event.getGuild();
|
||||
Biscuit b = Biscuit.getBiscuit(guild);
|
||||
TextChannel tchannel = event.getTextChannel();
|
||||
|
||||
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()) {
|
||||
tchannel.sendMessage("You must be in a voice channel to do this!").queue();
|
||||
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) {
|
||||
tchannel.sendMessage("You are not in a channel that is authorized to use the music player.").queue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(b.getAudioPlayer().getPlayingTrack() != null && guild.getAudioManager().isConnected() && !guild.getAudioManager().getConnectedChannel().getMembers().contains(event.getMember())) {
|
||||
tchannel.sendMessage("Music is already playing in a voice channel. Connect to "
|
||||
+ "that channel, then queue your song.").queue();
|
||||
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(b,event.getAuthor().getId(), tchannel, false, searchPhrase));
|
||||
}
|
||||
|
||||
private String getID(String url) {
|
||||
String[] s = url.split("=");
|
||||
if(s.length > 1) {
|
||||
return s[1].split("&")[0];
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
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.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.MessageReceivedEvent;
|
||||
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, MessageReceivedEvent event) {
|
||||
Guild guild = event.getGuild();
|
||||
Biscuit b = Biscuit.getBiscuit(guild);
|
||||
TextChannel tchannel = event.getTextChannel();
|
||||
|
||||
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())) {
|
||||
tchannel.sendMessage("You do not have permission to do this!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!event.getMember().getVoiceState().inVoiceChannel()) {
|
||||
tchannel.sendMessage("You must be in a voice channel to do this!").queue();
|
||||
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) {
|
||||
tchannel.sendMessage("You are not in a channel that is authorized to use the music player.").queue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(b.getAudioPlayer().getPlayingTrack() != null && guild.getAudioManager().isConnected() && !guild.getAudioManager().getConnectedChannel().getMembers().contains(event.getMember())) {
|
||||
tchannel.sendMessage("Music is already playing in a voice channel. Connect to "
|
||||
+ "that channel, then queue your song.").queue();
|
||||
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(b,event.getAuthor().getId(), tchannel, false, searchPhrase, true));
|
||||
}
|
||||
|
||||
private String getID(String url) {
|
||||
String[] s = url.split("=");
|
||||
if(s.length > 1) {
|
||||
return s[1].split("&")[0];
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.Util;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.audio.queue.AudioQueue;
|
||||
import com.fpghoti.biscuit.audio.queue.QueuedTrack;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.base.MusicClientCommand;
|
||||
import com.fpghoti.biscuit.util.Util;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class QueueCommand extends MusicClientCommand{
|
||||
|
||||
public QueueCommand() {
|
||||
name = "Queue";
|
||||
description = "Displays the upcoming songs in the music queue.";
|
||||
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "queue [Page #]";
|
||||
minArgs = 0;
|
||||
maxArgs = 1;
|
||||
identifiers.add("queue");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, MessageReceivedEvent event) {
|
||||
|
||||
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
|
||||
biscuit.log(event.getAuthor().getName() + " issued a command: -queue");
|
||||
int pg = 1;
|
||||
if (args.length > 0) {
|
||||
if(Util.isDigit(args[0])) {
|
||||
pg = Integer.parseInt(args[0]);
|
||||
}else {
|
||||
event.getTextChannel().sendMessage("Usage: ``" + usage + "``").queue();
|
||||
}
|
||||
}
|
||||
|
||||
AudioQueue queue = biscuit.getAudioScheduler().getQueue();
|
||||
|
||||
int pageCount = (int) Math.ceil((double) queue.size() / 8);
|
||||
if (pg > pageCount) {
|
||||
pg = pageCount;
|
||||
}
|
||||
|
||||
if(queue.size() == 0) {
|
||||
if(biscuit.getAudioPlayer().getPlayingTrack() == null) {
|
||||
event.getTextChannel().sendMessage("There is currently no song playing.").queue();
|
||||
}else {
|
||||
event.getTextChannel().sendMessage("Nothing is queued to play after the current track.").queue();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
event.getTextChannel().sendMessage("**Use " + Main.getMainBiscuit().getProperties().getCommandSignifier() + "queue [Page #] to navigate the different pages.**").queue();
|
||||
event.getTextChannel().sendMessage("[" + Integer.toString(pg) + "/" + Integer.toString(pageCount) + "] ** Upcoming Music Tracks:**").queue();
|
||||
String msg = "";
|
||||
for (int i = 0; i < 8; i++) {
|
||||
int index = (pg - 1) * 8 + i;
|
||||
int count = index + 1;
|
||||
String line = "";
|
||||
if (index < queue.size()) {
|
||||
QueuedTrack track = queue.getTrack(index);
|
||||
AudioTrack a = track.getTrack();
|
||||
Member m = track.getMember();
|
||||
line = "**" + count + ".** " + a.getInfo().title + " [" + Util.getTime(a.getInfo().length) + "]";
|
||||
if(m != null) {
|
||||
line = line + " Added by: **" + m.getEffectiveName() + "**";
|
||||
}
|
||||
}
|
||||
if(!(index + 1 >= queue.size() || index == 7)) {
|
||||
line = line + "\n";
|
||||
}
|
||||
if (index < queue.size()) {
|
||||
msg = msg + line;
|
||||
}
|
||||
}
|
||||
event.getTextChannel().sendMessage(msg).queue();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.logging.BColor;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
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 net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
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, MessageReceivedEvent event) {
|
||||
Biscuit b = Biscuit.getBiscuit(event.getGuild());
|
||||
b.log(event.getAuthor().getName() + " issued a command: -skip");
|
||||
|
||||
if(b.getAudioPlayer().getPlayingTrack() == null) {
|
||||
event.getChannel().sendMessage("There is not a song playing for you to skip!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!event.getGuild().getAudioManager().getConnectedChannel().getMembers().contains(event.getMember())) {
|
||||
event.getChannel().sendMessage("You need to be in the same voice channel in order to skip!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
if(b.getAudioScheduler().getVotes() >= (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) / 2) {
|
||||
event.getChannel().sendMessage("Skip vote status: **[" + ( b.getAudioScheduler().getVotes() + 1) + "/"
|
||||
+ (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) + "]**"
|
||||
+ "\nSkipping current track.").queue();
|
||||
if(b.getAudioScheduler().getNextMessage() != null ) {
|
||||
event.getChannel().sendMessage(b.getAudioScheduler().getNextMessage()).queue();
|
||||
}
|
||||
b.getAudioScheduler().skip();
|
||||
return;
|
||||
}
|
||||
if(b.getAudioScheduler().voteSkip(event.getAuthor().getId())) {
|
||||
event.getChannel().sendMessage("You voted to skip the current track.").queue();
|
||||
}else {
|
||||
event.getChannel().sendMessage("You cannot vote to skip this track again."
|
||||
+ "\nSkip vote status: **[" + b.getAudioScheduler().getVotes() + "/"
|
||||
+ (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) + "]**").queue();
|
||||
}
|
||||
|
||||
if(b.getAudioScheduler().getVotes() >= (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) / 2) {
|
||||
event.getChannel().sendMessage("Skip vote status: **[" + b.getAudioScheduler().getVotes() + "/"
|
||||
+ event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() + "]**"
|
||||
+ "\nSkipping current track.").queue();
|
||||
if(b.getAudioScheduler().getNextMessage() != null ) {
|
||||
event.getChannel().sendMessage(b.getAudioScheduler().getNextMessage()).queue();
|
||||
}
|
||||
b.getAudioScheduler().skip();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.Util;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.Util;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
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.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class TogglePauseCommand extends MusicClientCommand{
|
||||
|
||||
public TogglePauseCommand() {
|
||||
name = "Toggle Pause";
|
||||
description = "Toggles the pause status of the current track.";
|
||||
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "togglepause";
|
||||
minArgs = 0;
|
||||
maxArgs = 0;
|
||||
identifiers.add("togglepause");
|
||||
identifiers.add("tp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, MessageReceivedEvent event) {
|
||||
Biscuit b = Biscuit.getBiscuit(event.getGuild());
|
||||
b.log(event.getAuthor().getName() + " issued a command: -togglepause");
|
||||
if(PermUtil.isMod(event.getMember())) {
|
||||
if(b.getAudioPlayer().isPaused()) {
|
||||
b.getAudioPlayer().setPaused(false);
|
||||
event.getChannel().sendMessage("Unpaused the current track.").queue();
|
||||
}else {
|
||||
b.getAudioPlayer().setPaused(true);
|
||||
event.getChannel().sendMessage("Paused the current track.").queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class UnpauseCommand extends ClientCommand{
|
||||
|
||||
public UnpauseCommand() {
|
||||
name = "Unpause";
|
||||
description = "Unpauses the current track.";
|
||||
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "unpause";
|
||||
minArgs = 0;
|
||||
maxArgs = 0;
|
||||
identifiers.add("unpause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, MessageReceivedEvent event) {
|
||||
Biscuit b = Biscuit.getBiscuit(event.getGuild());
|
||||
b.log(event.getAuthor().getName() + " issued a command: -unpause");
|
||||
if(PermUtil.isMod(event.getMember())) {
|
||||
if(b.getAudioPlayer().isPaused()) {
|
||||
b.getAudioPlayer().setPaused(false);
|
||||
event.getChannel().sendMessage("Unpaused the current track.").queue();
|
||||
}else {
|
||||
event.getChannel().sendMessage("The music player is not paused.").queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.client;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ClientCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ClientCommand;
|
||||
import com.fpghoti.biscuit.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
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.util.PermUtil;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class WipeQueueCommand extends MusicClientCommand{
|
||||
|
||||
public WipeQueueCommand() {
|
||||
name = "Wipe Queue";
|
||||
description = "Removes all upcoming tracks from the queue.";
|
||||
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "wipequeue";
|
||||
minArgs = 0;
|
||||
maxArgs = 0;
|
||||
identifiers.add("wipequeue");
|
||||
identifiers.add("wipeq");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, MessageReceivedEvent event) {
|
||||
Biscuit b = Biscuit.getBiscuit(event.getGuild());
|
||||
b.log(event.getAuthor().getName() + " issued a command: -wipequeue");
|
||||
if(PermUtil.isMod(event.getMember())) {
|
||||
b.getAudioScheduler().wipeQueue();
|
||||
event.getChannel().sendMessage("Removed upcoming songs from the music queue.").queue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.console;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ConsoleCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ConsoleCommand;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fpghoti.biscuit.commands.console;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.biscuit.Biscuit;
|
||||
import com.fpghoti.biscuit.commands.ConsoleCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ConsoleCommand;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.fpghoti.biscuit.commands.console;
|
||||
|
||||
import com.fpghoti.biscuit.Main;
|
||||
import com.fpghoti.biscuit.commands.ConsoleCommand;
|
||||
import com.fpghoti.biscuit.commands.base.ConsoleCommand;
|
||||
|
||||
public class ShutdownConsoleCommand extends ConsoleCommand{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user