|
|
@ -12,13 +12,24 @@ import de.yannicpunktdee.yoshibot.command.YoshiCommandContext; |
|
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommandDistributor; |
|
|
|
import de.yannicpunktdee.yoshibot.listeners.CommandLine; |
|
|
|
import de.yannicpunktdee.yoshibot.listeners.CommandListener; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.Logger; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.Resources; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.SauceProvider; |
|
|
|
import lombok.SneakyThrows; |
|
|
|
import net.dv8tion.jda.api.JDA; |
|
|
|
import net.dv8tion.jda.api.JDABuilder; |
|
|
|
import net.dv8tion.jda.api.OnlineStatus; |
|
|
|
import net.dv8tion.jda.api.entities.Activity; |
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.File; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Random; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
/** |
|
|
|
* Repräsentiert einen Yoshi-Bot. Der Bot initialisiert alle Ressourcen und schaltet sich in der startYoshiBot-Methode |
|
|
|
* online und beginnt dann zu lauschen. Parallel lauscht ein Thread auf Konsoleneingaben für administrative Zwecke, die |
|
|
@ -79,7 +90,7 @@ public class YoshiBot { |
|
|
|
|
|
|
|
jda = jdaBuilder.build(); |
|
|
|
|
|
|
|
jdaBuilder.setStatus(OnlineStatus.ONLINE).setActivity(Activity.playing("Haare waschen.")); |
|
|
|
jdaBuilder.setStatus(OnlineStatus.ONLINE); |
|
|
|
|
|
|
|
System.out.println("YoshiBot online."); |
|
|
|
|
|
|
@ -87,6 +98,8 @@ public class YoshiBot { |
|
|
|
commandLineThread.start(); |
|
|
|
|
|
|
|
SauceProvider provider = new SauceProvider(300); |
|
|
|
|
|
|
|
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(YoshiBot::setRandomActivity, 0, 10, TimeUnit.HOURS); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void stop() { |
|
|
@ -113,4 +126,15 @@ public class YoshiBot { |
|
|
|
return YoshiBot.instance; |
|
|
|
} |
|
|
|
|
|
|
|
@SneakyThrows |
|
|
|
private static void setRandomActivity() { |
|
|
|
YoshiBot yoshiBot = YoshiBot.getInstance(); |
|
|
|
yoshiBot.jda.awaitReady(); |
|
|
|
List<String> text = Files.readAllLines(new File(Resources.getActivityPath()).toPath()); |
|
|
|
Random rand = new Random(); |
|
|
|
String activity = text.get(rand.nextInt(text.size())); |
|
|
|
yoshiBot.jda.getPresence().setActivity(Activity.playing(activity)); |
|
|
|
Logger.log("Setze Aktivität auf " + activity, Logger.Type.INFO); |
|
|
|
} |
|
|
|
|
|
|
|
} |