From 9e1888611a68be959b68ab33b08b062373d14a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Tue, 20 Dec 2022 22:08:05 +0100 Subject: [PATCH] Make random statuses update automatically --- .../wtf/beatrice/hidekobot/HidekoBot.java | 4 ++- .../hidekobot/runnables/StatusUpdateTask.java | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/main/java/wtf/beatrice/hidekobot/runnables/StatusUpdateTask.java diff --git a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java index 717a925..a4ad60d 100644 --- a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java +++ b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java @@ -18,6 +18,7 @@ import wtf.beatrice.hidekobot.listeners.SlashCommandCompletionListener; import wtf.beatrice.hidekobot.listeners.SlashCommandListener; import wtf.beatrice.hidekobot.runnables.ExpiredMessageTask; import wtf.beatrice.hidekobot.runnables.HeartBeatTask; +import wtf.beatrice.hidekobot.runnables.StatusUpdateTask; import wtf.beatrice.hidekobot.util.CommandUtil; import wtf.beatrice.hidekobot.util.Logger; @@ -158,7 +159,6 @@ public class HidekoBot // set the bot's status jda.getPresence().setStatus(OnlineStatus.ONLINE); - jda.getPresence().setActivity(Activity.playing("Hatsune Miku: Project DIVA")); // connect to database logger.log("Connecting to database..."); @@ -182,6 +182,8 @@ public class HidekoBot scheduler.scheduleAtFixedRate(expiredMessageTask, 5, 5, TimeUnit.SECONDS); //every 5 seconds HeartBeatTask heartBeatTask = new HeartBeatTask(); scheduler.scheduleAtFixedRate(heartBeatTask, 10, 30, TimeUnit.SECONDS); //every 30 seconds + StatusUpdateTask statusUpdateTask = new StatusUpdateTask(); + scheduler.scheduleAtFixedRate(statusUpdateTask, 0, 60 * 5, TimeUnit.SECONDS); // every 5 minutes // register shutdown interrupt signal listener for proper shutdown. Signal.handle(new Signal("INT"), signal -> shutdown()); diff --git a/src/main/java/wtf/beatrice/hidekobot/runnables/StatusUpdateTask.java b/src/main/java/wtf/beatrice/hidekobot/runnables/StatusUpdateTask.java new file mode 100644 index 0000000..1841995 --- /dev/null +++ b/src/main/java/wtf/beatrice/hidekobot/runnables/StatusUpdateTask.java @@ -0,0 +1,30 @@ +package wtf.beatrice.hidekobot.runnables; + +import net.dv8tion.jda.api.entities.Activity; +import wtf.beatrice.hidekobot.Cache; +import wtf.beatrice.hidekobot.HidekoBot; +import wtf.beatrice.hidekobot.util.RandomUtil; + +import java.util.Arrays; +import java.util.List; + +public class StatusUpdateTask implements Runnable +{ + + List statuses = Arrays.asList( + "Hatsune Miku: Project DIVA", + "Wii Sports", + "Excel", + "Mii Channel", + "Wii Speak", + "MineTest", + "Mario Kart Wii" + ); + + @Override + public void run() { + int randomPos = RandomUtil.getRandomNumber(0, statuses.size() - 1); + String status = statuses.get(randomPos) + " | " + Cache.getBotPrefix() + " help"; + HidekoBot.getAPI().getPresence().setActivity(Activity.playing(status)); + } +}