forked from Fascinated/Bat
cleanup dev mode
This commit is contained in:
parent
b7f2b6a3d7
commit
702aead53a
@ -1,5 +1,6 @@
|
|||||||
package cc.fascinated.bat;
|
package cc.fascinated.bat;
|
||||||
|
|
||||||
|
import cc.fascinated.bat.config.Config;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import io.mongock.runner.springboot.EnableMongock;
|
import io.mongock.runner.springboot.EnableMongock;
|
||||||
@ -37,5 +38,7 @@ public class BatApplication {
|
|||||||
|
|
||||||
// Start the app
|
// Start the app
|
||||||
SpringApplication.run(BatApplication.class, args);
|
SpringApplication.run(BatApplication.class, args);
|
||||||
|
|
||||||
|
log.info("APP IS RUNNING IN %s MODE!!!!!!!!!".formatted(Config.isProduction() ? "PRODUCTION" : "DEVELOPMENT"));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,7 +27,7 @@ public class ProfileHolder {
|
|||||||
profiles = new HashMap<>();
|
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) {
|
if (profile == null) {
|
||||||
try {
|
try {
|
||||||
profile = clazz.newInstance();
|
profile = clazz.newInstance();
|
||||||
|
20
src/main/java/cc/fascinated/bat/config/Config.java
Normal file
20
src/main/java/cc/fascinated/bat/config/Config.java
Normal 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"));
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ package cc.fascinated.bat.service;
|
|||||||
import cc.fascinated.bat.Consts;
|
import cc.fascinated.bat.Consts;
|
||||||
import cc.fascinated.bat.command.*;
|
import cc.fascinated.bat.command.*;
|
||||||
import cc.fascinated.bat.common.EmbedUtils;
|
import cc.fascinated.bat.common.EmbedUtils;
|
||||||
|
import cc.fascinated.bat.config.Config;
|
||||||
import cc.fascinated.bat.model.BatGuild;
|
import cc.fascinated.bat.model.BatGuild;
|
||||||
import cc.fascinated.bat.model.BatUser;
|
import cc.fascinated.bat.model.BatUser;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -73,6 +74,19 @@ public class CommandService extends ListenerAdapter {
|
|||||||
JDA jda = DiscordService.JDA;
|
JDA jda = DiscordService.JDA;
|
||||||
long before = System.currentTimeMillis();
|
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
|
// Unregister all commands that Discord has but we don't
|
||||||
jda.retrieveCommands().complete().forEach(command -> {
|
jda.retrieveCommands().complete().forEach(command -> {
|
||||||
if (commands.containsKey(command.getName())
|
if (commands.containsKey(command.getName())
|
||||||
@ -102,8 +116,6 @@ public class CommandService extends ListenerAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Guild adminGuild = jda.getGuildById(Consts.ADMIN_GUILD);
|
|
||||||
if (adminGuild != null) {
|
if (adminGuild != null) {
|
||||||
adminGuild.updateCommands().addCommands(commands.values().stream()
|
adminGuild.updateCommands().addCommands(commands.values().stream()
|
||||||
.filter(command -> command.getCategory().isHidden() || command.isBotOwnerOnly())
|
.filter(command -> command.getCategory().isHidden() || command.isBotOwnerOnly())
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
discord:
|
discord:
|
||||||
token: "oh my goodnesssssssssss"
|
token: "oh my goodnesssssssssss"
|
||||||
|
|
||||||
|
# Bat Configuration
|
||||||
|
environment: "development"
|
||||||
|
|
||||||
# Sentry Configuration
|
# Sentry Configuration
|
||||||
sentry:
|
sentry:
|
||||||
dsn: "CHANGE_ME"
|
dsn: "CHANGE_ME"
|
||||||
|
Loading…
Reference in New Issue
Block a user