|
|
@ -9,34 +9,33 @@ import net.dv8tion.jda.api.entities.VoiceChannel; |
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
import java.io.File; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
public class PlayCommand extends YoshiCommand { |
|
|
|
|
|
|
|
|
|
|
|
protected String[] requiredArguments = {"name"}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PlayCommand(YoshiCommandContext context) { |
|
|
|
super(context); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean execute() { |
|
|
|
if (!super.execute()) return false; |
|
|
|
|
|
|
|
if (context.containsArguments(new String[]{"add"})) { |
|
|
|
File download = downloadAttachmentToFile(Resources.getAudioPath(), context.getArgument("name")); |
|
|
|
if(download.isFile()) sendInfoMessage("Audio erfolgreich hinzugefügt."); |
|
|
|
if (download.isFile()) sendInfoMessage("Audio erfolgreich hinzugefügt."); |
|
|
|
else sendErrorMessage("Audio konnte nicht hinzugefügt werden."); |
|
|
|
} else if (context.containsArguments(new String[]{"list"})) { |
|
|
|
File audioDirectory = new File(Resources.getAudioPath()); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
for (File f : audioDirectory.listFiles()) { |
|
|
|
String fName = f.getName(); |
|
|
|
if (!fName.endsWith(".opus")) continue; |
|
|
|
sb.append(fName.substring(0, fName.lastIndexOf(".opus"))); |
|
|
|
sb.append("\n"); |
|
|
|
} |
|
|
|
Arrays.stream(audioDirectory.listFiles()).map(File::getName).filter(name -> name.endsWith(".opus")) |
|
|
|
.map(name -> name.substring(0, name.lastIndexOf(".opus"))).sorted() |
|
|
|
.forEach(name -> sb.append(name).append("\n")); |
|
|
|
EmbedBuilder eb = new EmbedBuilder(); |
|
|
|
eb.setTitle("Es sind folgende Audios verf\u00fcgbar:"); |
|
|
|
eb.setColor(Color.cyan); |
|
|
@ -44,13 +43,13 @@ public class PlayCommand extends YoshiCommand { |
|
|
|
sendCustomMessage(eb.build()); |
|
|
|
} else { |
|
|
|
File file = new File(Resources.getPathToAudioFile(context.getArgument("name"))); |
|
|
|
if(!file.isFile()){ |
|
|
|
if (!file.isFile()) { |
|
|
|
sendErrorMessage(String.format("Konnte keine Audiodatei namens '%s.opus' finden!", |
|
|
|
context.getArgument("name"))); |
|
|
|
context.getArgument("name"))); |
|
|
|
return false; |
|
|
|
} |
|
|
|
VoiceChannel vc = getVoiceChannelByParam(); |
|
|
|
if(vc == null){ |
|
|
|
if (vc == null) { |
|
|
|
sendErrorMessage("Konnte keinen Audiochannel auswählen."); |
|
|
|
return false; |
|
|
|
} |
|
|
|