Browse Source

Play command so erweitert, dass nun auch über Anhang neue Sounds hinzugefügt werden können.

pull/2/head
yl60lepu 4 years ago
parent
commit
b9e6028cda
3 changed files with 61 additions and 17 deletions
  1. +2
    -1
      app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/HelpCommand.java
  2. +55
    -15
      app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java
  3. +4
    -1
      app/src/main/java/de/yannicpunktdee/yoshibot/utils/Resources.java

+ 2
- 1
app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/HelpCommand.java View File

@ -27,7 +27,8 @@ public class HelpCommand extends YoshiCommand {
eb.addField("help", "Zeigt genau diesen Hilfetext an.", false);
eb.addField("joke", "Schreibt einen random Jokus in den \u00fcber -channel angegebenen Textchannel.", false);
eb.addField("list", "Listet alle derzeit verf\u00fcgbaren Sounds auf.", false);
eb.addField("play", "Spielt den Sound mit dem Namen -name in dem Voicechannel -channel ab.", false);
eb.addField("play", "Spielt den Sound mit dem Namen -name in dem Voicechannel -channel ab. Oder mit Option -add (ohne Wert) wird "
+ "neuer Sound hinzugef\u00fcgt. Es muss ein -name vergeben werden und der Sound als .opus-Datei im Anganh vorhanden sein.", false);
eb.addField("say", "Sagt Sachen. Mittels Google übersetzer. Macht damit was ihr wollt. Ist halt nur deutsch",
false);
eb.addField("sauce", "Was erwartest du? Gibt dir halt Soße. Pack nen -tags dahinter und dann bisschen \" um " +


+ 55
- 15
app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java View File

@ -1,17 +1,22 @@
package de.yannicpunktdee.yoshibot.command.commands;
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 net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.VoiceChannel;
public class PlayCommand extends YoshiCommand {
protected final String[] requiredArguments = new String[] {"channel", "name"};
protected final String[] requiredArguments = new String[] {"name"};
public PlayCommand(YoshiCommandContext context) {
@ -32,22 +37,57 @@ public class PlayCommand extends YoshiCommand {
if(!super.execute()) return false;
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;
}


+ 4
- 1
app/src/main/java/de/yannicpunktdee/yoshibot/utils/Resources.java View File

@ -189,7 +189,10 @@ public final class Resources {
return true;
}
public static String buildAudioFilePath(String name) {
return audio_source_directory + (audio_source_directory.endsWith("/") ? "" : "/") + name + ".opus";
}
public static String getAudioFilePath(String name) {
name = audio_source_directory + (audio_source_directory.endsWith("/") ? "" : "/") + name + ".opus";
if ((new File(name)).exists()) return name;


Loading…
Cancel
Save