From 0f2c6843001a19d7a516ffa20f65153a444d6494 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 25 Jun 2024 12:16:20 +0100 Subject: [PATCH] add rotating presences --- ...edCommand.java => NumberOneFeedCommand.java} | 4 ++-- .../fascinated/bat/service/CommandService.java | 4 ++-- .../fascinated/bat/service/DiscordService.java | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) rename src/main/java/cc/fascinated/bat/features/scoresaber/command/numberone/{NunberOneFeedCommand.java => NumberOneFeedCommand.java} (93%) diff --git a/src/main/java/cc/fascinated/bat/features/scoresaber/command/numberone/NunberOneFeedCommand.java b/src/main/java/cc/fascinated/bat/features/scoresaber/command/numberone/NumberOneFeedCommand.java similarity index 93% rename from src/main/java/cc/fascinated/bat/features/scoresaber/command/numberone/NunberOneFeedCommand.java rename to src/main/java/cc/fascinated/bat/features/scoresaber/command/numberone/NumberOneFeedCommand.java index 89fa82f..e6624e4 100644 --- a/src/main/java/cc/fascinated/bat/features/scoresaber/command/numberone/NunberOneFeedCommand.java +++ b/src/main/java/cc/fascinated/bat/features/scoresaber/command/numberone/NumberOneFeedCommand.java @@ -15,8 +15,8 @@ import org.springframework.stereotype.Component; * @author Fascinated (fascinated7) */ @Component("scoresaber-number-one-feed") -public class NunberOneFeedCommand extends BatCommand { - public NunberOneFeedCommand(@NonNull ApplicationContext context) { +public class NumberOneFeedCommand extends BatCommand { + public NumberOneFeedCommand(@NonNull ApplicationContext context) { super("scoresaber-number-one-feed"); super.setCategory(Category.BEAT_SABER); diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index 2802b00..3955212 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -3,7 +3,7 @@ package cc.fascinated.bat.service; import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.BatSubCommand; import cc.fascinated.bat.common.EmbedUtils; -import cc.fascinated.bat.features.scoresaber.command.numberone.NunberOneFeedCommand; +import cc.fascinated.bat.features.scoresaber.command.numberone.NumberOneFeedCommand; import cc.fascinated.bat.features.scoresaber.command.scoresaber.ScoreSaberCommand; import cc.fascinated.bat.features.scoresaber.command.userfeed.UserFeedCommand; import cc.fascinated.bat.model.BatGuild; @@ -52,7 +52,7 @@ public class CommandService extends ListenerAdapter { // Guild commands registerCommand(context.getBean(UserFeedCommand.class)); - registerCommand(context.getBean(NunberOneFeedCommand.class)); + registerCommand(context.getBean(NumberOneFeedCommand.class)); // Global commands registerCommand(context.getBean(ScoreSaberCommand.class)); diff --git a/src/main/java/cc/fascinated/bat/service/DiscordService.java b/src/main/java/cc/fascinated/bat/service/DiscordService.java index 4d728f7..a19137a 100644 --- a/src/main/java/cc/fascinated/bat/service/DiscordService.java +++ b/src/main/java/cc/fascinated/bat/service/DiscordService.java @@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.EnumSet; +import java.util.List; /** * @author Fascinated (fascinated7) @@ -22,6 +23,13 @@ public class DiscordService { */ public static JDA JDA; + private final List messages = List.of( + "over {guilds} guilds", + "over {users} users", + "over ScoreSaber scores", + "your messages" + ); + @Autowired public DiscordService( @Value("${discord.token}") String token @@ -31,9 +39,7 @@ public class DiscordService { GatewayIntent.MESSAGE_CONTENT )).build() .awaitReady(); - - // Update activity every 5 minutes - TimerUtils.scheduleRepeating(this::updateActivity, 0, 1000 * 60 * 5); + TimerUtils.scheduleRepeating(this::updateActivity, 0, 1000 * 60 * 2); } /** @@ -41,6 +47,9 @@ public class DiscordService { */ public void updateActivity() { int guildCount = JDA.getGuilds().size(); - JDA.getPresence().setActivity(Activity.playing("with %s guilds".formatted(guildCount))); + JDA.getPresence().setActivity(Activity.watching(messages.get(guildCount % messages.size()) + .replace("{guilds}", String.valueOf(guildCount)) + .replace("{users}", String.valueOf(JDA.getUsers().size())) + )); } }