|
|
@ -13,6 +13,7 @@ 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; |
|
|
@ -60,7 +61,7 @@ public final class YoshiBot { |
|
|
|
* LavaPlayer AudioPlayerManager. |
|
|
|
*/ |
|
|
|
public AudioPlayerManager audioPlayerManager; |
|
|
|
|
|
|
|
|
|
|
|
@Getter |
|
|
|
private Guild guild; |
|
|
|
|
|
|
@ -80,11 +81,9 @@ public final class YoshiBot { |
|
|
|
|
|
|
|
/** |
|
|
|
* Startet den Bot und schaltet ihn online. Beginnt auf Konsoleneingaben für administrative Zwecke zu lauschen. |
|
|
|
* |
|
|
|
* @throws LoginException Falls das Token ungültig ist. |
|
|
|
*/ |
|
|
|
**/ |
|
|
|
@SneakyThrows |
|
|
|
public void start() throws LoginException { |
|
|
|
public void start() { |
|
|
|
System.out.println("Starte YoshiBot."); |
|
|
|
|
|
|
|
jdaBuilder = JDABuilder.createDefault(Resources.getJda_builder_string()); |
|
|
@ -120,8 +119,10 @@ public final class YoshiBot { |
|
|
|
|
|
|
|
new SauceProvider(300); |
|
|
|
|
|
|
|
//RedditProvider.init(); |
|
|
|
|
|
|
|
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(YoshiBot::setRandomActivity, 0, 10, TimeUnit.HOURS); |
|
|
|
|
|
|
|
|
|
|
|
joinVoiceChannelWithMostMembers(); |
|
|
|
} |
|
|
|
|
|
|
@ -158,47 +159,47 @@ 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) { |
|
|
|
|
|
|
|
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; |
|
|
|
if (guild.getAudioManager().getConnectedChannel() != null && |
|
|
|
vc.getIdLong() == guild.getAudioManager().getConnectedChannel().getIdLong()) return; |
|
|
|
guild.getAudioManager().openAudioConnection(vc); |
|
|
|
} |
|
|
|
|
|
|
|
public void joinVoiceChannelWithMostMembers(){ |
|
|
|
|
|
|
|
public void joinVoiceChannelWithMostMembers() { |
|
|
|
VoiceChannel maxVoiceChannel = null; |
|
|
|
int maxMembers = 0; |
|
|
|
for(VoiceChannel vc : guild.getVoiceChannels()){ |
|
|
|
for (VoiceChannel vc : guild.getVoiceChannels()) { |
|
|
|
int membersInChannel = 0; |
|
|
|
for(Member m : vc.getMembers()) |
|
|
|
if(!m.getUser().isBot()) membersInChannel++; |
|
|
|
if(membersInChannel > maxMembers){ |
|
|
|
for (Member m : vc.getMembers()) |
|
|
|
if (!m.getUser().isBot()) membersInChannel++; |
|
|
|
if (membersInChannel > maxMembers) { |
|
|
|
maxVoiceChannel = vc; |
|
|
|
maxMembers = membersInChannel; |
|
|
|
maxMembers = membersInChannel; |
|
|
|
} |
|
|
|
} |
|
|
|
if(maxMembers < 1) joinVoiceChannel(null); |
|
|
|
else if(maxMembers > 0 && maxVoiceChannel != null) |
|
|
|
if (maxMembers < 1) joinVoiceChannel(null); |
|
|
|
else if (maxMembers > 0 && maxVoiceChannel != null) |
|
|
|
joinVoiceChannel(maxVoiceChannel); |
|
|
|
} |
|
|
|
|
|
|
|
public boolean playSound(File file, VoiceChannel vc){ |
|
|
|
|
|
|
|
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 +210,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 +225,7 @@ public final class YoshiBot { |
|
|
|
e.printStackTrace(); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return playSound(new File(path), vc); |
|
|
|
} |
|
|
|
|
|
|
|