|
@ -5,6 +5,7 @@ import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; |
|
|
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; |
|
|
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; |
|
|
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers; |
|
|
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers; |
|
|
import com.sedmelluq.discord.lavaplayer.source.local.LocalAudioSourceManager; |
|
|
import com.sedmelluq.discord.lavaplayer.source.local.LocalAudioSourceManager; |
|
|
|
|
|
import de.yannicpunktdee.yoshibot.audio.AudioLoadResultHandlerImpl; |
|
|
import de.yannicpunktdee.yoshibot.audio.AudioPlayerListener; |
|
|
import de.yannicpunktdee.yoshibot.audio.AudioPlayerListener; |
|
|
import de.yannicpunktdee.yoshibot.audio.AudioSendHandlerImpl; |
|
|
import de.yannicpunktdee.yoshibot.audio.AudioSendHandlerImpl; |
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommandContext; |
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommandContext; |
|
@ -21,13 +22,19 @@ import net.dv8tion.jda.api.JDABuilder; |
|
|
import net.dv8tion.jda.api.OnlineStatus; |
|
|
import net.dv8tion.jda.api.OnlineStatus; |
|
|
import net.dv8tion.jda.api.entities.Activity; |
|
|
import net.dv8tion.jda.api.entities.Activity; |
|
|
import net.dv8tion.jda.api.entities.Guild; |
|
|
import net.dv8tion.jda.api.entities.Guild; |
|
|
|
|
|
import net.dv8tion.jda.api.entities.TextChannel; |
|
|
import net.dv8tion.jda.api.entities.VoiceChannel; |
|
|
import net.dv8tion.jda.api.entities.VoiceChannel; |
|
|
|
|
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; |
|
|
|
|
|
|
|
|
import javax.security.auth.login.LoginException; |
|
|
import javax.security.auth.login.LoginException; |
|
|
|
|
|
import java.io.BufferedReader; |
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.InputStreamReader; |
|
|
import java.nio.file.Files; |
|
|
import java.nio.file.Files; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Random; |
|
|
import java.util.Random; |
|
|
|
|
|
import java.util.UUID; |
|
|
import java.util.concurrent.Executors; |
|
|
import java.util.concurrent.Executors; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
@ -66,6 +73,9 @@ public final class YoshiBot { |
|
|
|
|
|
|
|
|
@Getter |
|
|
@Getter |
|
|
private boolean active; |
|
|
private boolean active; |
|
|
|
|
|
|
|
|
|
|
|
@Getter |
|
|
|
|
|
private VoiceChannel voiceChannel = null; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Initialisiert alle dynamisch hinzugefügten und statischen Ressourcen. Startet aber nicht den Bot selbst. |
|
|
* Initialisiert alle dynamisch hinzugefügten und statischen Ressourcen. Startet aber nicht den Bot selbst. |
|
@ -157,17 +167,22 @@ public final class YoshiBot { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void joinVoiceChannel(VoiceChannel vc){ |
|
|
private void joinVoiceChannel(VoiceChannel vc){ |
|
|
|
|
|
if(vc == null) return; |
|
|
if(vc.equals(guild.getAudioManager().getConnectedChannel())) return; |
|
|
if(vc.equals(guild.getAudioManager().getConnectedChannel())) return; |
|
|
leaveAudioChannel(); |
|
|
leaveAudioChannel(); |
|
|
guild.getAudioManager().openAudioConnection(vc); |
|
|
guild.getAudioManager().openAudioConnection(vc); |
|
|
|
|
|
voiceChannel = vc; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void leaveAudioChannel(){ |
|
|
private void leaveAudioChannel(){ |
|
|
if(guild.getAudioManager().getConnectedChannel() == null) return; |
|
|
if(guild.getAudioManager().getConnectedChannel() == null) return; |
|
|
guild.getAudioManager().closeAudioConnection(); |
|
|
guild.getAudioManager().closeAudioConnection(); |
|
|
|
|
|
voiceChannel = null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void autoConnectToChannel(){ |
|
|
public void autoConnectToChannel(){ |
|
|
|
|
|
if(!instance.active) return; |
|
|
|
|
|
|
|
|
VoiceChannel maxMembersVoiceChannel = null; |
|
|
VoiceChannel maxMembersVoiceChannel = null; |
|
|
int maxMembers = 0; |
|
|
int maxMembers = 0; |
|
|
for(VoiceChannel vc : guild.getVoiceChannels()){ |
|
|
for(VoiceChannel vc : guild.getVoiceChannels()){ |
|
@ -185,5 +200,51 @@ public final class YoshiBot { |
|
|
if(active) autoConnectToChannel(); |
|
|
if(active) autoConnectToChannel(); |
|
|
else leaveAudioChannel(); |
|
|
else leaveAudioChannel(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean playSound(File file, VoiceChannel vc){ |
|
|
|
|
|
if(active) return true; |
|
|
|
|
|
|
|
|
|
|
|
if (!file.isFile()) return false; |
|
|
|
|
|
|
|
|
|
|
|
joinVoiceChannel((vc == null)? voiceChannel : vc); |
|
|
|
|
|
|
|
|
|
|
|
audioPlayerManager.loadItem(file.getAbsolutePath(), new AudioLoadResultHandlerImpl()); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean sayTTS(String text, VoiceChannel vc) { |
|
|
|
|
|
if(!active) return true; |
|
|
|
|
|
|
|
|
|
|
|
String path = Resources.getPathToTempAudioFile(UUID.randomUUID().toString()); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
ProcessBuilder pb = new ProcessBuilder( |
|
|
|
|
|
"python3", |
|
|
|
|
|
Resources.getTtsPath(), |
|
|
|
|
|
"--text", |
|
|
|
|
|
text, |
|
|
|
|
|
"--lang", |
|
|
|
|
|
"de", |
|
|
|
|
|
"--out", |
|
|
|
|
|
path); |
|
|
|
|
|
|
|
|
|
|
|
Process p = pb.start(); |
|
|
|
|
|
BufferedReader errorReader = new BufferedReader(new InputStreamReader(p.getErrorStream())); |
|
|
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
|
|
|
String line; |
|
|
|
|
|
while ((line = errorReader.readLine()) != null) { |
|
|
|
|
|
builder.append(line).append("\n"); |
|
|
|
|
|
} |
|
|
|
|
|
if (builder.toString().length() > 0) { |
|
|
|
|
|
Logger.logError(builder.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return playSound(new File(path), vc); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |