cleanup dev mode

This commit is contained in:
Lee 2024-06-30 04:13:54 +01:00
parent b7f2b6a3d7
commit 702aead53a
5 changed files with 41 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package cc.fascinated.bat;
import cc.fascinated.bat.config.Config;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.mongock.runner.springboot.EnableMongock;
@ -37,5 +38,7 @@ public class BatApplication {
// Start the app
SpringApplication.run(BatApplication.class, args);
log.info("APP IS RUNNING IN %s MODE!!!!!!!!!".formatted(Config.isProduction() ? "PRODUCTION" : "DEVELOPMENT"));
}
}

View File

@ -27,7 +27,7 @@ public class ProfileHolder {
profiles = new HashMap<>();
}
Profile profile = profiles.values().stream().filter(p -> p.getClass().equals(clazz)).findFirst().orElse(null);
Profile profile = profiles.values().stream().filter(clazz::isInstance).findFirst().orElse(null);
if (profile == null) {
try {
profile = clazz.newInstance();

View File

@ -0,0 +1,20 @@
package cc.fascinated.bat.config;
import lombok.Getter;
/**
* @author Fascinated (fascinated7)
*/
public class Config {
/**
* Is the app running in a production environment?
*/
@Getter
private static final boolean production;
static {
// Are we running on production?
String appEnv = System.getenv("APP_ENV");
production = appEnv != null && (appEnv.equals("production"));
}
}

View File

@ -3,6 +3,7 @@ package cc.fascinated.bat.service;
import cc.fascinated.bat.Consts;
import cc.fascinated.bat.command.*;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.config.Config;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import lombok.Getter;
@ -73,6 +74,19 @@ public class CommandService extends ListenerAdapter {
JDA jda = DiscordService.JDA;
long before = System.currentTimeMillis();
Guild adminGuild = jda.getGuildById(Consts.ADMIN_GUILD);
if (!Config.isProduction()) {
if (adminGuild == null) {
log.error("Unable to find the admin guild to register commands");
return;
}
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).complete());
adminGuild.updateCommands().addCommands(commands.values().stream()
.map(BatCommand::getCommandData).toList()).complete();
log.info("Registered {} slash commands in {}ms (DEV MODE)", commands.size(), System.currentTimeMillis() - before);
return;
}
// Unregister all commands that Discord has but we don't
jda.retrieveCommands().complete().forEach(command -> {
if (commands.containsKey(command.getName())
@ -102,8 +116,6 @@ public class CommandService extends ListenerAdapter {
}
}
}
Guild adminGuild = jda.getGuildById(Consts.ADMIN_GUILD);
if (adminGuild != null) {
adminGuild.updateCommands().addCommands(commands.values().stream()
.filter(command -> command.getCategory().isHidden() || command.isBotOwnerOnly())

View File

@ -2,6 +2,9 @@
discord:
token: "oh my goodnesssssssssss"
# Bat Configuration
environment: "development"
# Sentry Configuration
sentry:
dsn: "CHANGE_ME"