Refactor Config class
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-11-21 20:20:11 +01:00
parent e396ce6417
commit f74ae43673
18 changed files with 72 additions and 70 deletions

View File

@@ -3,7 +3,7 @@ package wtf.beatrice.hidekobot.commands.completer;
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.Command;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Configuration;
import wtf.beatrice.hidekobot.Cache;
import java.util.ArrayList;
import java.util.List;
@@ -18,7 +18,7 @@ public class AvatarCompleter
List<Command.Choice> options = new ArrayList<>();
for(int res : Configuration.getSupportedAvatarResolutions())
for(int res : Cache.getSupportedAvatarResolutions())
{
String resString = String.valueOf(res);
String userInput = event.getFocusedOption().getValue();

View File

@@ -5,7 +5,7 @@ import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Configuration;
import wtf.beatrice.hidekobot.Cache;
public class AvatarCommand
{
@@ -18,7 +18,7 @@ public class AvatarCommand
User user;
int resolution;
int[] acceptedSizes = Configuration.getSupportedAvatarResolutions();
int[] acceptedSizes = Cache.getSupportedAvatarResolutions();
OptionMapping userArg = event.getOption("user");
@@ -54,7 +54,7 @@ public class AvatarCommand
// embed processing
{
embedBuilder.setColor(Configuration.getBotColor());
embedBuilder.setColor(Cache.getBotColor());
embedBuilder.setTitle("Profile picture");
embedBuilder.addField("User", "<@" + user.getId() + ">", false);

View File

@@ -4,7 +4,7 @@ import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.Command;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Configuration;
import wtf.beatrice.hidekobot.Cache;
import wtf.beatrice.hidekobot.HidekoBot;
import wtf.beatrice.hidekobot.utils.FormatUtil;
@@ -20,14 +20,14 @@ public class BotInfoCommand
// defer reply because this might take a moment
event.deferReply().queue();
List<Command> registeredCommands = Configuration.getRegisteredCommands();
List<Command> registeredCommands = Cache.getRegisteredCommands();
EmbedBuilder embedBuilder = new EmbedBuilder();
// embed processing
{
embedBuilder.setColor(Configuration.getBotColor());
embedBuilder.setTitle(Configuration.getBotName());
embedBuilder.setColor(Cache.getBotColor());
embedBuilder.setTitle(Cache.getBotName());
// thumbnail
String botAvatarUrl = HidekoBot.getAPI().getSelfUser().getAvatarUrl();
@@ -53,7 +53,7 @@ public class BotInfoCommand
embedBuilder.addField("Commands", commandsListBuilder.toString(), false);
// version field
embedBuilder.addField("Version", "v" + Configuration.getBotVersion(), true);
embedBuilder.addField("Version", "v" + Cache.getBotVersion(), true);
// jvm version field
String jvmVersion = ManagementFactory.getRuntimeMXBean().getVmVersion();
@@ -68,7 +68,7 @@ public class BotInfoCommand
embedBuilder.addField("RAM Usage", ramMBFormatter.format(usedRamMB) + " MB", true);
// developer field
String developerMention = "<@" + Configuration.getBotMaintainerId() + ">";
String developerMention = "<@" + Cache.getBotMaintainerId() + ">";
embedBuilder.addField("Maintainer", developerMention, true);
// uptime field

View File

@@ -12,7 +12,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Configuration;
import wtf.beatrice.hidekobot.Cache;
import java.util.ArrayList;
import java.util.List;
@@ -165,8 +165,8 @@ public class ClearChatCommand
.setActionRow(dismissButton)
.complete();
Configuration.getDatabaseManager().queueDisabling(message);
Configuration.getDatabaseManager().trackRanCommandReply(message, event.getUser());
Cache.getDatabaseManager().queueDisabling(message);
Cache.getDatabaseManager().trackRanCommandReply(message, event.getUser());
}
}).start();
@@ -176,7 +176,7 @@ public class ClearChatCommand
public void dismissMessage(ButtonInteractionEvent event)
{
if(!(Configuration.getDatabaseManager().isUserTrackedFor(event.getUser().getId(), event.getMessageId())))
if(!(Cache.getDatabaseManager().isUserTrackedFor(event.getUser().getId(), event.getMessageId())))
{
event.reply("❌ You did not run this command!").setEphemeral(true).queue();
} else

View File

@@ -8,7 +8,7 @@ import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Configuration;
import wtf.beatrice.hidekobot.Cache;
import wtf.beatrice.hidekobot.utils.RandomUtil;
import java.util.List;
@@ -38,7 +38,7 @@ public class CoinFlipCommand
public void buttonReFlip(ButtonInteractionEvent event)
{
// check if the user interacting is the same one who ran the command
if(!(Configuration.getDatabaseManager().isUserTrackedFor(event.getUser().getId(), event.getMessageId())))
if(!(Cache.getDatabaseManager().isUserTrackedFor(event.getUser().getId(), event.getMessageId())))
{
event.reply("❌ You did not run this command!").setEphemeral(true).queue();
return;
@@ -63,8 +63,8 @@ public class CoinFlipCommand
{
String replyMessageId = replyMessage.getId();
Configuration.getDatabaseManager().queueDisabling(replyMessage);
Configuration.getDatabaseManager().trackRanCommandReply(replyMessage, user);
Cache.getDatabaseManager().queueDisabling(replyMessage);
Cache.getDatabaseManager().trackRanCommandReply(replyMessage, user);
}
private String genRandom()

View File

@@ -2,7 +2,7 @@ package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Configuration;
import wtf.beatrice.hidekobot.Cache;
import wtf.beatrice.hidekobot.HidekoBot;
import java.util.concurrent.Executors;
@@ -13,7 +13,7 @@ public class DieCommand
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
{
if(Configuration.getBotOwnerId() != event.getMember().getIdLong())
if(Cache.getBotOwnerId() != event.getMember().getIdLong())
{
event.reply("Sorry, only the bot owner can run this command!").setEphemeral(true).queue();
} else {

View File

@@ -3,7 +3,7 @@ package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Configuration;
import wtf.beatrice.hidekobot.Cache;
public class HelpCommand
{
@@ -17,7 +17,7 @@ public class HelpCommand
// embed processing
{
embedBuilder.setColor(Configuration.getBotColor());
embedBuilder.setColor(Cache.getBotColor());
embedBuilder.setTitle("Help");
}

View File

@@ -9,7 +9,7 @@ import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Configuration;
import wtf.beatrice.hidekobot.Cache;
import wtf.beatrice.hidekobot.HidekoBot;
public class InviteCommand
@@ -29,17 +29,17 @@ public class InviteCommand
//embed processing
{
embedBuilder.setColor(Configuration.getBotColor());
embedBuilder.setColor(Cache.getBotColor());
String avatarUrl = HidekoBot.getAPI().getSelfUser().getAvatarUrl();
if(avatarUrl != null) embedBuilder.setThumbnail(avatarUrl);
embedBuilder.setTitle("Invite");
embedBuilder.appendDescription("Click on the button below to invite " +
Configuration.getBotName() +
Cache.getBotName() +
" to your server!");
}
String inviteUrl = Configuration.getInviteUrl();
Button inviteButton = Button.link(inviteUrl, "Invite " + Configuration.getBotName())
String inviteUrl = Cache.getInviteUrl();
Button inviteButton = Button.link(inviteUrl, "Invite " + Cache.getBotName())
.withEmoji(Emoji.fromUnicode("\uD83C\uDF1F"));
WebhookMessageEditAction<Message> reply =