add rotating presences
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 44s

This commit is contained in:
Lee 2024-06-25 12:16:20 +01:00
parent e9422793cb
commit 0f2c684300
3 changed files with 17 additions and 8 deletions

@ -15,8 +15,8 @@ import org.springframework.stereotype.Component;
* @author Fascinated (fascinated7) * @author Fascinated (fascinated7)
*/ */
@Component("scoresaber-number-one-feed") @Component("scoresaber-number-one-feed")
public class NunberOneFeedCommand extends BatCommand { public class NumberOneFeedCommand extends BatCommand {
public NunberOneFeedCommand(@NonNull ApplicationContext context) { public NumberOneFeedCommand(@NonNull ApplicationContext context) {
super("scoresaber-number-one-feed"); super("scoresaber-number-one-feed");
super.setCategory(Category.BEAT_SABER); super.setCategory(Category.BEAT_SABER);

@ -3,7 +3,7 @@ package cc.fascinated.bat.service;
import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.command.BatSubCommand; import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.common.EmbedUtils; 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.scoresaber.ScoreSaberCommand;
import cc.fascinated.bat.features.scoresaber.command.userfeed.UserFeedCommand; import cc.fascinated.bat.features.scoresaber.command.userfeed.UserFeedCommand;
import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatGuild;
@ -52,7 +52,7 @@ public class CommandService extends ListenerAdapter {
// Guild commands // Guild commands
registerCommand(context.getBean(UserFeedCommand.class)); registerCommand(context.getBean(UserFeedCommand.class));
registerCommand(context.getBean(NunberOneFeedCommand.class)); registerCommand(context.getBean(NumberOneFeedCommand.class));
// Global commands // Global commands
registerCommand(context.getBean(ScoreSaberCommand.class)); registerCommand(context.getBean(ScoreSaberCommand.class));

@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List;
/** /**
* @author Fascinated (fascinated7) * @author Fascinated (fascinated7)
@ -22,6 +23,13 @@ public class DiscordService {
*/ */
public static JDA JDA; public static JDA JDA;
private final List<String> messages = List.of(
"over {guilds} guilds",
"over {users} users",
"over ScoreSaber scores",
"your messages"
);
@Autowired @Autowired
public DiscordService( public DiscordService(
@Value("${discord.token}") String token @Value("${discord.token}") String token
@ -31,9 +39,7 @@ public class DiscordService {
GatewayIntent.MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT
)).build() )).build()
.awaitReady(); .awaitReady();
TimerUtils.scheduleRepeating(this::updateActivity, 0, 1000 * 60 * 2);
// Update activity every 5 minutes
TimerUtils.scheduleRepeating(this::updateActivity, 0, 1000 * 60 * 5);
} }
/** /**
@ -41,6 +47,9 @@ public class DiscordService {
*/ */
public void updateActivity() { public void updateActivity() {
int guildCount = JDA.getGuilds().size(); 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()))
));
} }
} }