Browse Source

Singelton-Verwendung angepasst und Say-Command

say_command
Yannic Link 4 years ago
parent
commit
1bb3ee48cb
11 changed files with 78 additions and 10 deletions
  1. +2
    -0
      README.md
  2. +1
    -1
      app/src/main/java/de/yannicpunktdee/yoshibot/audio/AudioController.java
  3. +1
    -1
      app/src/main/java/de/yannicpunktdee/yoshibot/audio/AudioControllerManager.java
  4. +1
    -1
      app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/JokeCommand.java
  5. +3
    -3
      app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/PlayCommand.java
  6. +54
    -1
      app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/SayCommand.java
  7. +1
    -1
      app/src/main/java/de/yannicpunktdee/yoshibot/command/commands/StopCommand.java
  8. +1
    -1
      app/src/main/java/de/yannicpunktdee/yoshibot/listeners/CommandLine.java
  9. +4
    -0
      app/src/main/java/de/yannicpunktdee/yoshibot/main/Main.java
  10. +9
    -1
      app/src/main/java/de/yannicpunktdee/yoshibot/main/Resources.java
  11. +1
    -0
      rsc/Ordnerstruktur.txt

+ 2
- 0
README.md View File

@ -12,6 +12,8 @@ Werte enthalten:
(dieses Verzeichnis sollte natürlich existieren) (dieses Verzeichnis sollte natürlich existieren)
- restrict_commands_to_channel -> Textkanalname, auf dem die Botkommandos empfangen werden - restrict_commands_to_channel -> Textkanalname, auf dem die Botkommandos empfangen werden
Python gTTS installieren mit pip install gTTS
##Export ##Export
Zum Exportieren der Applikation führe den Befehl "gradlew clean build" im Root Verzeichnis aus. Die fertige Jar liegt Zum Exportieren der Applikation führe den Befehl "gradlew clean build" im Root Verzeichnis aus. Die fertige Jar liegt


+ 1
- 1
app/src/main/java/de/yannicpunktdee/yoshibot/audio/AudioController.java View File

@ -13,7 +13,7 @@ public class AudioController {
public AudioController(Guild guild) { public AudioController(Guild guild) {
this.guild = guild; this.guild = guild;
this.audioPlayer = YoshiBot.audioPlayerManager.createPlayer();
this.audioPlayer = YoshiBot.getInstance().audioPlayerManager.createPlayer();
audioPlayer.addListener(new AudioPlayerListener(guild.getAudioManager())); audioPlayer.addListener(new AudioPlayerListener(guild.getAudioManager()));
this.guild.getAudioManager().setSendingHandler(new AudioSendHandlerImpl(audioPlayer)); this.guild.getAudioManager().setSendingHandler(new AudioSendHandlerImpl(audioPlayer));


+ 1
- 1
app/src/main/java/de/yannicpunktdee/yoshibot/audio/AudioControllerManager.java View File

@ -19,7 +19,7 @@ public class AudioControllerManager {
if(audioController.containsKey(guildId)) if(audioController.containsKey(guildId))
ac = audioController.get(guildId); ac = audioController.get(guildId);
else { else {
ac = new AudioController(YoshiBot.jda.getGuildById(guildId));
ac = new AudioController(YoshiBot.getInstance().jda.getGuildById(guildId));
audioController.put(guildId, ac); audioController.put(guildId, ac);
} }
return ac; return ac;


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

@ -52,7 +52,7 @@ public class JokeCommand extends YoshiCommand {
sendMessage("Es wurde kein channel angegeben."); sendMessage("Es wurde kein channel angegeben.");
return false; return false;
} }
List<TextChannel> channels = YoshiBot.jda.getTextChannelsByName(context.getArgument("channel"), true);
List<TextChannel> channels = YoshiBot.getInstance().jda.getTextChannelsByName(context.getArgument("channel"), true);
if(channels.isEmpty()) { if(channels.isEmpty()) {
sendMessage("Der Kanalname konnte nicht gefunden werden."); sendMessage("Der Kanalname konnte nicht gefunden werden.");
return false; return false;


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

@ -23,7 +23,7 @@ public class PlayCommand extends YoshiCommand {
public boolean execute() { public boolean execute() {
if(!super.execute()) return false; if(!super.execute()) return false;
List<VoiceChannel> channels = YoshiBot.jda.getVoiceChannelsByName(context.getArgument("channel"), true);
List<VoiceChannel> channels = YoshiBot.getInstance().jda.getVoiceChannelsByName(context.getArgument("channel"), true);
if(!(channels.size() > 0)) { if(!(channels.size() > 0)) {
context.getEvent().getTextChannel().sendMessage("Der Kanalname konnte nicht gefunden werden.").queue(); context.getEvent().getTextChannel().sendMessage("Der Kanalname konnte nicht gefunden werden.").queue();
return false; return false;
@ -36,9 +36,9 @@ public class PlayCommand extends YoshiCommand {
return false; return false;
} }
AudioController ac = YoshiBot.audioControllerManager.getController(vc.getGuild().getIdLong());
AudioController ac = YoshiBot.getInstance().audioControllerManager.getController(vc.getGuild().getIdLong());
vc.getGuild().getAudioManager().openAudioConnection(vc); vc.getGuild().getAudioManager().openAudioConnection(vc);
YoshiBot.audioPlayerManager.loadItem(fileName, new AudioLoadResultHandlerImpl(ac));
YoshiBot.getInstance().audioPlayerManager.loadItem(fileName, new AudioLoadResultHandlerImpl(ac));
return true; return true;
} }


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

@ -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;
}
} }

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

@ -16,7 +16,7 @@ public class StopCommand extends YoshiCommand {
@Override @Override
public boolean execute() { public boolean execute() {
if(!super.execute()) return false; if(!super.execute()) return false;
YoshiBot.stop();
YoshiBot.getInstance().stop();
return true; return true;
} }


+ 1
- 1
app/src/main/java/de/yannicpunktdee/yoshibot/listeners/CommandLine.java View File

@ -22,7 +22,7 @@ public class CommandLine extends Thread implements Runnable {
while((line = reader.readLine()) != null) { while((line = reader.readLine()) != null) {
line = line.trim(); line = line.trim();
if(line.equalsIgnoreCase("exit")) { if(line.equalsIgnoreCase("exit")) {
YoshiBot.stop();
YoshiBot.getInstance().stop();
return; return;
} }
System.out.print("> "); System.out.print("> ");


+ 4
- 0
app/src/main/java/de/yannicpunktdee/yoshibot/main/Main.java View File

@ -1,7 +1,11 @@
package de.yannicpunktdee.yoshibot.main; package de.yannicpunktdee.yoshibot.main;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.UUID;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
/** /**


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

@ -10,7 +10,7 @@ import java.util.Properties;
public class Resources { public class Resources {
private static final String default_propertiesFilePath = "../rsc/Config.properties";
private static final String default_propertiesFilePath = "rsc/Config.properties";
private static String propertiesFilePath = default_propertiesFilePath; private static String propertiesFilePath = default_propertiesFilePath;
private static Properties propertiesFile; private static Properties propertiesFile;
@ -93,6 +93,14 @@ public class Resources {
if((new File(name)).exists()) return name; if((new File(name)).exists()) return name;
else return null; else return null;
} }
public static String getTempAudioFilePath(String name) {
name = audio_source_directory + (audio_source_directory.endsWith("/")? "" : "/") + "temp/" + name + ".opus";
if((new File(name)).exists()) return name;
else return null;
}
public static String buildTempAudioFilePath(String name){
return audio_source_directory + (audio_source_directory.endsWith("/")? "" : "/") + "temp/" + name + ".opus";
}
public static String getAudioSourceDirectory(){ public static String getAudioSourceDirectory(){
return audio_source_directory; return audio_source_directory;
} }


+ 1
- 0
rsc/Ordnerstruktur.txt View File

@ -2,6 +2,7 @@ rsc
|-- .gitkeep |-- .gitkeep
|-- Ordnerstruktur.txt |-- Ordnerstruktur.txt
|-- Config.properties |-- Config.properties
|-- tts.py
|-- audio |-- audio
|-- temp |-- temp
|-- temp_1.opus |-- temp_1.opus


Loading…
Cancel
Save