|
@ -11,42 +11,43 @@ 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 lombok.NonNull; |
|
|
import net.dv8tion.jda.api.entities.Message; |
|
|
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[] {"name"}; |
|
|
|
|
|
|
|
|
protected final String[] requiredArguments = new String[]{"name"}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PlayCommand(YoshiCommandContext context) { |
|
|
public PlayCommand(YoshiCommandContext context) { |
|
|
super(context); |
|
|
super(context); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static boolean play(String fileName, VoiceChannel vc){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean play(String fileName, VoiceChannel vc) { |
|
|
YoshiBot yoshiBot = YoshiBot.getInstance(); |
|
|
YoshiBot yoshiBot = YoshiBot.getInstance(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vc.getGuild().getAudioManager().openAudioConnection(vc); |
|
|
vc.getGuild().getAudioManager().openAudioConnection(vc); |
|
|
yoshiBot.audioPlayerManager.loadItem(fileName, new AudioLoadResultHandlerImpl()); |
|
|
yoshiBot.audioPlayerManager.loadItem(fileName, new AudioLoadResultHandlerImpl()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean execute() { |
|
|
public boolean execute() { |
|
|
if(!super.execute()) return false; |
|
|
|
|
|
|
|
|
if (!super.execute()) return false; |
|
|
|
|
|
|
|
|
YoshiBot yoshiBot = YoshiBot.getInstance(); |
|
|
YoshiBot yoshiBot = YoshiBot.getInstance(); |
|
|
|
|
|
|
|
|
if(context.containsArguments(new String[]{"add"})){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (context.containsArguments(new String[]{"add"})) { |
|
|
List<Message.Attachment> attachments = context.getEvent().getMessage().getAttachments(); |
|
|
List<Message.Attachment> attachments = context.getEvent().getMessage().getAttachments(); |
|
|
if(attachments.isEmpty() || attachments.size() > 1){ |
|
|
|
|
|
|
|
|
if (attachments.size() != 1) { |
|
|
sendMessage("Falsche Anzahl an Anhängen"); |
|
|
sendMessage("Falsche Anzahl an Anhängen"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String path = Resources.buildAudioFilePath(context.getArgument("name")); |
|
|
String path = Resources.buildAudioFilePath(context.getArgument("name")); |
|
|
if((new File(path)).exists()){ |
|
|
|
|
|
|
|
|
if ((new File(path)).exists()) { |
|
|
sendMessage("Ein Soundeffekt mit diesem Namen existiert bereits."); |
|
|
sendMessage("Ein Soundeffekt mit diesem Namen existiert bereits."); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
@ -62,33 +63,35 @@ public class PlayCommand extends YoshiCommand { |
|
|
sendMessage("Die Sounddatei konnte nicht ordnungsgemäß erstellt werden."); |
|
|
sendMessage("Die Sounddatei konnte nicht ordnungsgemäß erstellt werden."); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
VoiceChannel vc; |
|
|
VoiceChannel vc; |
|
|
if(context.getEvent().getMember() == null || !context.getEvent().getMember().getVoiceState().inVoiceChannel()){ |
|
|
|
|
|
if(!context.containsArguments(new String[]{"channel"})){ |
|
|
|
|
|
|
|
|
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(); |
|
|
context.getEvent().getTextChannel().sendMessage("Es wurde kein channel spezfiziert.").queue(); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
List<VoiceChannel> channels = yoshiBot.jda.getVoiceChannelsByName(context.getArgument("channel"), true); |
|
|
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(); |
|
|
|
|
|
|
|
|
if (!(channels.size() > 0)) { |
|
|
|
|
|
context.getEvent().getTextChannel().sendMessage("Der Kanalname konnte nicht gefunden werden.") |
|
|
|
|
|
.queue(); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
vc = channels.get(0); |
|
|
vc = channels.get(0); |
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
vc = context.getEvent().getMember().getVoiceState().getChannel(); |
|
|
vc = context.getEvent().getMember().getVoiceState().getChannel(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String fileName = Resources.getAudioFilePath(context.getArgument("name")); |
|
|
String fileName = Resources.getAudioFilePath(context.getArgument("name")); |
|
|
if(fileName == null) { |
|
|
|
|
|
|
|
|
if (fileName == null) { |
|
|
context.getEvent().getTextChannel().sendMessage("Audio konnte nicht gefunden werden.").queue(); |
|
|
context.getEvent().getTextChannel().sendMessage("Audio konnte nicht gefunden werden.").queue(); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
play(fileName, vc); |
|
|
play(fileName, vc); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |