|
|
@ -13,7 +13,6 @@ import de.yannicpunktdee.yoshibot.command.YoshiCommandDistributor; |
|
|
|
import de.yannicpunktdee.yoshibot.listeners.CommandLine; |
|
|
|
import de.yannicpunktdee.yoshibot.listeners.DiscordEventListener; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.Logger; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.RedditProvider; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.Resources; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.SauceProvider; |
|
|
|
import lombok.Getter; |
|
|
@ -25,6 +24,7 @@ import net.dv8tion.jda.api.entities.Activity; |
|
|
|
import net.dv8tion.jda.api.entities.Guild; |
|
|
|
import net.dv8tion.jda.api.entities.Member; |
|
|
|
import net.dv8tion.jda.api.entities.VoiceChannel; |
|
|
|
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException; |
|
|
|
|
|
|
|
import javax.security.auth.login.LoginException; |
|
|
|
import java.io.BufferedReader; |
|
|
@ -61,7 +61,7 @@ public final class YoshiBot { |
|
|
|
* LavaPlayer AudioPlayerManager. |
|
|
|
*/ |
|
|
|
public AudioPlayerManager audioPlayerManager; |
|
|
|
|
|
|
|
|
|
|
|
@Getter |
|
|
|
private Guild guild; |
|
|
|
|
|
|
@ -118,11 +118,11 @@ public final class YoshiBot { |
|
|
|
commandLineThread.start(); |
|
|
|
|
|
|
|
SauceProvider.init(300); |
|
|
|
|
|
|
|
|
|
|
|
//RedditProvider.init(); |
|
|
|
|
|
|
|
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(YoshiBot::setRandomActivity, 0, 10, TimeUnit.HOURS); |
|
|
|
|
|
|
|
|
|
|
|
joinVoiceChannelWithMostMembers(); |
|
|
|
} |
|
|
|
|
|
|
@ -159,17 +159,21 @@ public final class YoshiBot { |
|
|
|
yoshiBot.jda.getPresence().setActivity(Activity.playing(activity)); |
|
|
|
Logger.logInfo("Setze Aktivität auf " + activity); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public synchronized void joinVoiceChannel(VoiceChannel vc) { |
|
|
|
if (vc == null) { |
|
|
|
guild.getAudioManager().closeAudioConnection(); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (guild.getAudioManager().getConnectedChannel() != null && |
|
|
|
vc.getIdLong() == guild.getAudioManager().getConnectedChannel().getIdLong()) return; |
|
|
|
guild.getAudioManager().openAudioConnection(vc); |
|
|
|
if(guild.getAudioManager().getConnectedChannel() != null && |
|
|
|
vc.getIdLong() == guild.getAudioManager().getConnectedChannel().getIdLong()) return; |
|
|
|
try{ |
|
|
|
guild.getAudioManager().openAudioConnection(vc); |
|
|
|
}catch(InsufficientPermissionException e){ |
|
|
|
Logger.logWarning("Durfte dem VoiceChannel " + vc.getName() + " nicht beitreten."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void joinVoiceChannelWithMostMembers() { |
|
|
|
VoiceChannel maxVoiceChannel = null; |
|
|
|
int maxMembers = 0; |
|
|
@ -185,20 +189,20 @@ public final class YoshiBot { |
|
|
|
if (maxMembers < 1) joinVoiceChannel(null); |
|
|
|
else joinVoiceChannel(maxVoiceChannel); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean playSound(File file, VoiceChannel vc) { |
|
|
|
if (!file.isFile()) return false; |
|
|
|
|
|
|
|
|
|
|
|
joinVoiceChannel(vc); |
|
|
|
|
|
|
|
|
|
|
|
audioPlayerManager.loadItem(file.getAbsolutePath(), new AudioLoadResultHandlerImpl()); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean sayTTS(String text, VoiceChannel vc) { |
|
|
|
String path = Resources.getTempPath() + UUID.randomUUID() + ".opus"; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
ProcessBuilder pb = new ProcessBuilder( |
|
|
|
"python3", |
|
|
@ -209,7 +213,7 @@ public final class YoshiBot { |
|
|
|
"de", |
|
|
|
"--out", |
|
|
|
path); |
|
|
|
|
|
|
|
|
|
|
|
Process p = pb.start(); |
|
|
|
BufferedReader errorReader = new BufferedReader(new InputStreamReader(p.getErrorStream())); |
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
@ -224,7 +228,7 @@ public final class YoshiBot { |
|
|
|
e.printStackTrace(); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return playSound(new File(path), vc); |
|
|
|
} |
|
|
|
|
|
|
|