| @ -1,15 +1,68 @@ | |||||
| package de.yannicpunktdee.yoshibot.command.commands; | package de.yannicpunktdee.yoshibot.command.commands; | ||||
| import de.yannicpunktdee.yoshibot.audio.AudioController; | |||||
| 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.main.Resources; | |||||
| import de.yannicpunktdee.yoshibot.main.YoshiBot; | |||||
| import de.yannicpunktdee.yoshibot.utils.Logger; | |||||
| import net.dv8tion.jda.api.entities.VoiceChannel; | |||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import java.util.List; | |||||
| import java.util.UUID; | |||||
| public class SayCommand extends YoshiCommand { | public class SayCommand extends YoshiCommand { | ||||
| protected final String[] requiredArguments = {"text", "channel"}; | |||||
| public SayCommand(YoshiCommandContext context) { | public SayCommand(YoshiCommandContext context) { | ||||
| super(context); | super(context); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public boolean execute() {return true;} | |||||
| public boolean execute() { | |||||
| if(!super.execute()) return false; | |||||
| String path = Resources.buildTempAudioFilePath("tts"); | |||||
| try { | |||||
| ProcessBuilder pb = new ProcessBuilder( | |||||
| "python", | |||||
| "rsc/tts.py", | |||||
| "--text", | |||||
| context.getArgument("text"), | |||||
| "--lang", | |||||
| "de", | |||||
| "--out", | |||||
| path); | |||||
| pb.redirectError(); | |||||
| Process p = pb.start(); | |||||
| int exitCode = p.waitFor(); | |||||
| } catch (IOException | InterruptedException e) { | |||||
| e.printStackTrace(); | |||||
| return false; | |||||
| } | |||||
| List<VoiceChannel> channels = YoshiBot.getInstance().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); | |||||
| AudioController ac = YoshiBot.getInstance().audioControllerManager.getController(vc.getGuild().getIdLong()); | |||||
| YoshiBot.getInstance().audioPlayerManager.loadItem(path, new AudioLoadResultHandlerImpl(ac)); | |||||
| vc.getGuild().getAudioManager().openAudioConnection(vc); | |||||
| File deleteFile = new File(path); | |||||
| deleteFile.delete(); //FIXME Funktioniert noch nicht | |||||
| return false; | |||||
| } | |||||
| } | } | ||||