diff --git a/src/main/java/main/commands/commands/dev/config/ViewConfigCommand.java b/src/main/java/main/commands/commands/dev/config/ViewConfigCommand.java index 2334c9e1..58ad1a79 100644 --- a/src/main/java/main/commands/commands/dev/config/ViewConfigCommand.java +++ b/src/main/java/main/commands/commands/dev/config/ViewConfigCommand.java @@ -1,13 +1,17 @@ package main.commands.commands.dev.config; +import lombok.SneakyThrows; import main.commands.CommandContext; import main.commands.IDevCommand; import main.constants.ENV; import main.constants.JSONConfigFile; import main.main.Config; import main.utils.GeneralUtils; +import main.utils.database.mongodb.cache.GuildsDBCache; import main.utils.database.sqlite3.ServerDB; +import main.utils.json.guildconfig.GuildConfig; import net.dv8tion.jda.api.entities.Message; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,7 +23,7 @@ public class ViewConfigCommand implements IDevCommand { final Logger logger = LoggerFactory.getLogger(ViewConfigCommand.class); - @Override + @Override @SneakyThrows public void handle(CommandContext ctx) throws ScriptException { if (!permissionCheck(ctx)) return; @@ -32,21 +36,41 @@ public void handle(CommandContext ctx) throws ScriptException { } else { String fileName = args.get(0); - if (Arrays.stream(JSONConfigFile.values()).anyMatch( - (it) -> it.toString().equalsIgnoreCase(fileName) - )) { + if (GeneralUtils.stringIsID(fileName)) { + JSONObject guildInfo = GuildsDBCache.getInstance().getGuildInfo(Long.parseLong(fileName)); - String info = GeneralUtils.getFileContent(Config.get(ENV.JSON_DIR) + "/" + fileName); + if (guildInfo == null) { + msg.reply("Invalid guild ID").queue(); + return; + } try { msg.reply("```json\n" + - info + "\n```").queue(); + guildInfo.toString(4) + "\n```").queue(); } catch (IllegalArgumentException e) { - File file = new File(Config.get(ENV.JSON_DIR) +"/"+ fileName.toLowerCase()); - ctx.getMessage().reply(file).queue(); + File file = new File(fileName + ".json"); + file.createNewFile(); + ctx.getMessage().reply(file).queue(success -> file.delete()); } - } else msg.reply("Invalid config file!").queue(); + } else { + + if (Arrays.stream(JSONConfigFile.values()).anyMatch( + (it) -> it.toString().equalsIgnoreCase(fileName) + )) { + + String info = GeneralUtils.getFileContent(Config.get(ENV.JSON_DIR) + "/" + fileName); + + try { + msg.reply("```json\n" + + info + "\n```").queue(); + } catch (IllegalArgumentException e) { + File file = new File(Config.get(ENV.JSON_DIR) + "/" + fileName.toLowerCase()); + ctx.getMessage().reply(file).queue(); + } + + } else msg.reply("Invalid config file!").queue(); + } } }