|
|
@ -1,22 +1,20 @@ |
|
|
|
package de.yannicpunktdee.yoshibot.command.commands; |
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
import java.io.File; |
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
import de.yannicpunktdee.yoshibot.audio.AudioLoadResultHandlerImpl; |
|
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommand; |
|
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommandContext; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.Resources; |
|
|
|
import de.yannicpunktdee.yoshibot.main.YoshiBot; |
|
|
|
import lombok.NonNull; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.Resources; |
|
|
|
import net.dv8tion.jda.api.EmbedBuilder; |
|
|
|
import net.dv8tion.jda.api.entities.Message; |
|
|
|
import net.dv8tion.jda.api.entities.VoiceChannel; |
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
import java.io.File; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
public class PlayCommand extends YoshiCommand { |
|
|
|
|
|
|
|
protected final String[] requiredArguments = new String[]{"name"}; |
|
|
@ -27,6 +25,8 @@ public class PlayCommand extends YoshiCommand { |
|
|
|
} |
|
|
|
|
|
|
|
public static boolean play(String fileName, VoiceChannel vc) { |
|
|
|
if (!new File(fileName).isFile()) return false; |
|
|
|
|
|
|
|
YoshiBot yoshiBot = YoshiBot.getInstance(); |
|
|
|
|
|
|
|
vc.getGuild().getAudioManager().openAudioConnection(vc); |
|
|
@ -65,12 +65,12 @@ public class PlayCommand extends YoshiCommand { |
|
|
|
sendMessage("Die Sounddatei konnte nicht ordnungsgemäß erstellt werden."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} else if (context.containsArguments(new String[]{"list"})){ |
|
|
|
} else if (context.containsArguments(new String[]{"list"})) { |
|
|
|
File audioDirectory = new File(Resources.getAudioPath()); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
for(File f : audioDirectory.listFiles()){ |
|
|
|
for (File f : audioDirectory.listFiles()) { |
|
|
|
String fName = f.getName(); |
|
|
|
if(!fName.endsWith(".opus")) continue; |
|
|
|
if (!fName.endsWith(".opus")) continue; |
|
|
|
sb.append(fName.substring(0, fName.lastIndexOf(".opus"))); |
|
|
|
sb.append("\n"); |
|
|
|
} |
|
|
@ -79,7 +79,7 @@ public class PlayCommand extends YoshiCommand { |
|
|
|
eb.setColor(Color.blue); |
|
|
|
eb.setDescription(sb.toString()); |
|
|
|
sendMessage(eb.build()); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
VoiceChannel vc; |
|
|
|
if (context.getEvent().getMember() == null || |
|
|
|
!context.getEvent().getMember().getVoiceState().inVoiceChannel()) { |
|
|
@ -97,14 +97,13 @@ public class PlayCommand extends YoshiCommand { |
|
|
|
} else { |
|
|
|
vc = context.getEvent().getMember().getVoiceState().getChannel(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String fileName = Resources.getPathToAudioFile(context.getArgument("name")); |
|
|
|
if(fileName == null) { |
|
|
|
context.getEvent().getTextChannel().sendMessage("Audio konnte nicht gefunden werden.").queue(); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
play(fileName, vc); |
|
|
|
if (!play(fileName, vc)) { |
|
|
|
sendMessage(String.format("Konnte keine Audiodatei namens '%s.opus' finden!", |
|
|
|
context.getArgument("name"))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|