|
@ -1,17 +1,22 @@ |
|
|
package de.yannicpunktdee.yoshibot.command.commands; |
|
|
package de.yannicpunktdee.yoshibot.command.commands; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
import java.util.List; |
|
|
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.audio.AudioLoadResultHandlerImpl; |
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommand; |
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommand; |
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommandContext; |
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommandContext; |
|
|
import de.yannicpunktdee.yoshibot.utils.Resources; |
|
|
import de.yannicpunktdee.yoshibot.utils.Resources; |
|
|
import de.yannicpunktdee.yoshibot.main.YoshiBot; |
|
|
import de.yannicpunktdee.yoshibot.main.YoshiBot; |
|
|
|
|
|
import net.dv8tion.jda.api.entities.Message; |
|
|
import net.dv8tion.jda.api.entities.VoiceChannel; |
|
|
import net.dv8tion.jda.api.entities.VoiceChannel; |
|
|
|
|
|
|
|
|
public class PlayCommand extends YoshiCommand { |
|
|
public class PlayCommand extends YoshiCommand { |
|
|
|
|
|
|
|
|
protected final String[] requiredArguments = new String[] {"channel", "name"}; |
|
|
|
|
|
|
|
|
protected final String[] requiredArguments = new String[] {"name"}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PlayCommand(YoshiCommandContext context) { |
|
|
public PlayCommand(YoshiCommandContext context) { |
|
@ -32,22 +37,57 @@ public class PlayCommand extends YoshiCommand { |
|
|
if(!super.execute()) return false; |
|
|
if(!super.execute()) return false; |
|
|
|
|
|
|
|
|
YoshiBot yoshiBot = YoshiBot.getInstance(); |
|
|
YoshiBot yoshiBot = YoshiBot.getInstance(); |
|
|
|
|
|
|
|
|
List<VoiceChannel> channels = yoshiBot.jda.getVoiceChannelsByName(context.getArgument("channel"), true); |
|
|
|
|
|
if(!(channels.size() > 0)) { |
|
|
|
|
|
context.getEvent().getTextChannel().sendMessage("Der Kanalname konnte nicht gefunden werden.").queue(); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
VoiceChannel vc = channels.get(0); |
|
|
|
|
|
|
|
|
|
|
|
String fileName = Resources.getAudioFilePath(context.getArgument("name")); |
|
|
|
|
|
if(fileName == null) { |
|
|
|
|
|
context.getEvent().getTextChannel().sendMessage("Audio konnte nicht gefunden werden.").queue(); |
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(context.containsArguments(new String[]{"add"})){ |
|
|
|
|
|
List<Message.Attachment> attachments = context.getEvent().getMessage().getAttachments(); |
|
|
|
|
|
if(attachments.isEmpty() || attachments.size() > 1){ |
|
|
|
|
|
sendMessage("Falsche Anzahl an Anhängen"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String path = Resources.buildAudioFilePath(context.getArgument("name")); |
|
|
|
|
|
if((new File(path)).exists()){ |
|
|
|
|
|
sendMessage("Ein Soundeffekt mit diesem Namen existiert bereits."); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
CompletableFuture<File> future = attachments.get(0).downloadToFile(path); |
|
|
|
|
|
future.exceptionally(e -> { |
|
|
|
|
|
sendMessage("Der Anhang konnte nicht gedownloaded werden."); |
|
|
|
|
|
return null; |
|
|
|
|
|
}); |
|
|
|
|
|
try { |
|
|
|
|
|
future.get(); |
|
|
|
|
|
sendMessage("Sound erfolgreich hinzugef\u00fcgt."); |
|
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
|
|
sendMessage("Die Sounddatei konnte nicht ordnungsgemäß erstellt werden."); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
}else{ |
|
|
|
|
|
VoiceChannel vc; |
|
|
|
|
|
if(context.getEvent().getMember() == null || !context.getEvent().getMember().getVoiceState().inVoiceChannel()){ |
|
|
|
|
|
if(!context.containsArguments(new String[]{"channel"})){ |
|
|
|
|
|
context.getEvent().getTextChannel().sendMessage("Es wurde kein channel spezfiziert.").queue(); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
List<VoiceChannel> channels = yoshiBot.jda.getVoiceChannelsByName(context.getArgument("channel"), true); |
|
|
|
|
|
if(!(channels.size() > 0)) { |
|
|
|
|
|
context.getEvent().getTextChannel().sendMessage("Der Kanalname konnte nicht gefunden werden.").queue(); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
vc = channels.get(0); |
|
|
|
|
|
}else{ |
|
|
|
|
|
vc = context.getEvent().getMember().getVoiceState().getChannel(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String fileName = Resources.getAudioFilePath(context.getArgument("name")); |
|
|
|
|
|
if(fileName == null) { |
|
|
|
|
|
context.getEvent().getTextChannel().sendMessage("Audio konnte nicht gefunden werden.").queue(); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
play(fileName, vc); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
play(fileName, vc); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|