Skip to content

Commit

Permalink
Add data viewing for guilds
Browse files Browse the repository at this point in the history
  • Loading branch information
bombies committed Dec 29, 2021
1 parent 9cb4645 commit 1d739f4
Showing 1 changed file with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -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();
}
}
}

Expand Down

0 comments on commit 1d739f4

Please sign in to comment.