Prevent instantiating utility classes
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Bea 2023-01-16 07:07:42 +01:00
parent ccf69a2903
commit 980cf5eef3
18 changed files with 73 additions and 0 deletions

View File

@ -22,6 +22,10 @@ import java.util.concurrent.ScheduledExecutorService;
public class Cache public class Cache
{ {
private Cache() {
throw new IllegalStateException("Utility class");
}
// todo: make this compatible with the message listener's regex // todo: make this compatible with the message listener's regex
private static final String BOT_PREFIX = "hideko"; private static final String BOT_PREFIX = "hideko";

View File

@ -6,6 +6,10 @@ import java.util.LinkedList;
public class Alias public class Alias
{ {
private Alias() {
throw new IllegalStateException("Utility class");
}
public static String generateNiceAliases(MessageCommand command) public static String generateNiceAliases(MessageCommand command)
{ {
LinkedList<String> aliases = command.getCommandLabels(); LinkedList<String> aliases = command.getCommandLabels();

View File

@ -13,6 +13,10 @@ import java.util.List;
public class BotInfo public class BotInfo
{ {
private BotInfo() {
throw new IllegalStateException("Utility class");
}
public static MessageEmbed generateEmbed(List<String> commandLabels) public static MessageEmbed generateEmbed(List<String> commandLabels)
{ {
EmbedBuilder embedBuilder = new EmbedBuilder(); EmbedBuilder embedBuilder = new EmbedBuilder();

View File

@ -14,6 +14,9 @@ import java.util.List;
public class ClearChat public class ClearChat
{ {
private ClearChat() {
throw new IllegalStateException("Utility class");
}
public static String getLabel() { public static String getLabel() {
return "clear"; return "clear";

View File

@ -14,6 +14,9 @@ import java.util.List;
public class CoinFlip public class CoinFlip
{ {
private CoinFlip() {
throw new IllegalStateException("Utility class");
}
public static Button getReflipButton() { public static Button getReflipButton() {
return Button.primary("coinflip_reflip", "Flip again") return Button.primary("coinflip_reflip", "Flip again")

View File

@ -14,6 +14,11 @@ import java.util.UUID;
public class DiceRoll public class DiceRoll
{ {
private DiceRoll() {
throw new IllegalStateException("Utility class");
}
public static MessageResponse buildResponse(User author, String[] args) public static MessageResponse buildResponse(User author, String[] args)
{ {
LinkedHashMap<Dice, Integer> dicesToRoll = new LinkedHashMap<>(); LinkedHashMap<Dice, Integer> dicesToRoll = new LinkedHashMap<>();

View File

@ -10,6 +10,10 @@ import wtf.beatrice.hidekobot.HidekoBot;
public class Invite public class Invite
{ {
private Invite() {
throw new IllegalStateException("Utility class");
}
public static MessageEmbed generateEmbed() public static MessageEmbed generateEmbed()
{ {
EmbedBuilder embedBuilder = new EmbedBuilder(); EmbedBuilder embedBuilder = new EmbedBuilder();

View File

@ -10,6 +10,11 @@ import java.util.concurrent.TimeUnit;
public class LoveCalculator public class LoveCalculator
{ {
private LoveCalculator() {
throw new IllegalStateException("Utility class");
}
public static MessageEmbed buildEmbedAndCacheResult(User author, User user1, User user2) public static MessageEmbed buildEmbedAndCacheResult(User author, User user1, User user2)
{ {
String userId1 = user1.getId(); String userId1 = user1.getId();

View File

@ -14,6 +14,10 @@ import java.util.List;
public class MagicBall public class MagicBall
{ {
private MagicBall() {
throw new IllegalStateException("Utility class");
}
public static LinkedList<String> getLabels() public static LinkedList<String> getLabels()
{ {
return new LinkedList<>(Arrays.asList("8ball", "8b", "eightball", "magicball")); return new LinkedList<>(Arrays.asList("8ball", "8b", "eightball", "magicball"));

View File

@ -8,6 +8,11 @@ import wtf.beatrice.hidekobot.objects.MessageResponse;
public class ProfileImage public class ProfileImage
{ {
private ProfileImage() {
throw new IllegalStateException("Utility class");
}
public static int parseResolution(int resolution) public static int parseResolution(int resolution)
{ {
int[] acceptedSizes = Cache.getSupportedAvatarResolutions(); int[] acceptedSizes = Cache.getSupportedAvatarResolutions();

View File

@ -5,6 +5,10 @@ import net.dv8tion.jda.api.Permission;
public class Say public class Say
{ {
private Say() {
throw new IllegalStateException("Utility class");
}
public static Permission getPermission() { public static Permission getPermission() {
return Permission.MESSAGE_MANAGE; return Permission.MESSAGE_MANAGE;
} }

View File

@ -35,6 +35,11 @@ import java.util.concurrent.TimeUnit;
public class Trivia public class Trivia
{ {
private Trivia() {
throw new IllegalStateException("Utility class");
}
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Trivia.class); private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Trivia.class);
private static final String TRIVIA_API_LINK = "https://opentdb.com/api.php?amount=10&type=multiple&category="; private static final String TRIVIA_API_LINK = "https://opentdb.com/api.php?amount=10&type=multiple&category=";
private static final String TRIVIA_API_CATEGORIES_LINK = "https://opentdb.com/api_category.php"; private static final String TRIVIA_API_CATEGORIES_LINK = "https://opentdb.com/api_category.php";

View File

@ -25,6 +25,10 @@ import java.util.List;
public class UrbanDictionary public class UrbanDictionary
{ {
private UrbanDictionary() {
throw new IllegalStateException("Utility class");
}
public static LinkedList<String> getCommandLabels() public static LinkedList<String> getCommandLabels()
{ return new LinkedList<>(Arrays.asList("urban", "urbandictionary", "ud")); } { return new LinkedList<>(Arrays.asList("urban", "urbandictionary", "ud")); }

View File

@ -27,6 +27,10 @@ import java.util.concurrent.TimeUnit;
public class UserPunishment public class UserPunishment
{ {
private UserPunishment() {
throw new IllegalStateException("Utility class");
}
private static final Duration maxTimeoutDuration = Duration.of(28, ChronoUnit.DAYS); private static final Duration maxTimeoutDuration = Duration.of(28, ChronoUnit.DAYS);
private static final Duration minTimeoutDuration = Duration.of(30, ChronoUnit.SECONDS); private static final Duration minTimeoutDuration = Duration.of(30, ChronoUnit.SECONDS);

View File

@ -27,6 +27,10 @@ public class CommandUtil
private static final Logger LOGGER = LoggerFactory.getLogger(CommandUtil.class); private static final Logger LOGGER = LoggerFactory.getLogger(CommandUtil.class);
private CommandUtil() {
throw new IllegalStateException("Utility class");
}
/** /**
* Function to delete a message when a user clicks the "delete" button attached to that message. * Function to delete a message when a user clicks the "delete" button attached to that message.
* This will check in the database if that user ran the command originally. * This will check in the database if that user ran the command originally.

View File

@ -12,6 +12,9 @@ import java.util.Arrays;
public class FormatUtil public class FormatUtil
{ {
private FormatUtil() {
throw new IllegalStateException("Utility class");
}
// cosmetic string to print on startup. // cosmetic string to print on startup.
private static final String LOGO = """ private static final String LOGO = """

View File

@ -10,6 +10,10 @@ import java.util.Random;
public class RandomUtil public class RandomUtil
{ {
private RandomUtil() {
throw new IllegalStateException("Utility class");
}
// the Random instance that we should always use when looking for an RNG based thing. // the Random instance that we should always use when looking for an RNG based thing.
// the seed is updated periodically, if the random.org integration is enabled. // the seed is updated periodically, if the random.org integration is enabled.
private static Random randomInstance = new SecureRandom(); private static Random randomInstance = new SecureRandom();

View File

@ -10,6 +10,10 @@ import java.util.List;
public class SerializationUtil public class SerializationUtil
{ {
private SerializationUtil() {
throw new IllegalStateException("Utility class");
}
public static <T> String serializeBase64(List<T> dataList) { public static <T> String serializeBase64(List<T> dataList) {
try (ByteArrayOutputStream bo = new ByteArrayOutputStream(); try (ByteArrayOutputStream bo = new ByteArrayOutputStream();