From 980cf5eef32e878f074f7bf6777024fcd08a5122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Mon, 16 Jan 2023 07:07:42 +0100 Subject: [PATCH] Prevent instantiating utility classes --- src/main/java/wtf/beatrice/hidekobot/Cache.java | 4 ++++ .../java/wtf/beatrice/hidekobot/commands/base/Alias.java | 4 ++++ .../java/wtf/beatrice/hidekobot/commands/base/BotInfo.java | 4 ++++ .../java/wtf/beatrice/hidekobot/commands/base/ClearChat.java | 3 +++ .../java/wtf/beatrice/hidekobot/commands/base/CoinFlip.java | 3 +++ .../java/wtf/beatrice/hidekobot/commands/base/DiceRoll.java | 5 +++++ .../java/wtf/beatrice/hidekobot/commands/base/Invite.java | 4 ++++ .../wtf/beatrice/hidekobot/commands/base/LoveCalculator.java | 5 +++++ .../java/wtf/beatrice/hidekobot/commands/base/MagicBall.java | 4 ++++ .../wtf/beatrice/hidekobot/commands/base/ProfileImage.java | 5 +++++ src/main/java/wtf/beatrice/hidekobot/commands/base/Say.java | 4 ++++ .../java/wtf/beatrice/hidekobot/commands/base/Trivia.java | 5 +++++ .../beatrice/hidekobot/commands/base/UrbanDictionary.java | 4 ++++ .../wtf/beatrice/hidekobot/commands/base/UserPunishment.java | 4 ++++ src/main/java/wtf/beatrice/hidekobot/util/CommandUtil.java | 4 ++++ src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java | 3 +++ src/main/java/wtf/beatrice/hidekobot/util/RandomUtil.java | 4 ++++ .../java/wtf/beatrice/hidekobot/util/SerializationUtil.java | 4 ++++ 18 files changed, 73 insertions(+) diff --git a/src/main/java/wtf/beatrice/hidekobot/Cache.java b/src/main/java/wtf/beatrice/hidekobot/Cache.java index e53aeb5..8fa2175 100644 --- a/src/main/java/wtf/beatrice/hidekobot/Cache.java +++ b/src/main/java/wtf/beatrice/hidekobot/Cache.java @@ -22,6 +22,10 @@ import java.util.concurrent.ScheduledExecutorService; public class Cache { + private Cache() { + throw new IllegalStateException("Utility class"); + } + // todo: make this compatible with the message listener's regex private static final String BOT_PREFIX = "hideko"; diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/Alias.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/Alias.java index 4a5d521..c8f3014 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/Alias.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/Alias.java @@ -6,6 +6,10 @@ import java.util.LinkedList; public class Alias { + private Alias() { + throw new IllegalStateException("Utility class"); + } + public static String generateNiceAliases(MessageCommand command) { LinkedList aliases = command.getCommandLabels(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/BotInfo.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/BotInfo.java index d9eb74a..c9442d3 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/BotInfo.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/BotInfo.java @@ -13,6 +13,10 @@ import java.util.List; public class BotInfo { + private BotInfo() { + throw new IllegalStateException("Utility class"); + } + public static MessageEmbed generateEmbed(List commandLabels) { EmbedBuilder embedBuilder = new EmbedBuilder(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/ClearChat.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/ClearChat.java index 17ea6f6..92a7a6d 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/ClearChat.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/ClearChat.java @@ -14,6 +14,9 @@ import java.util.List; public class ClearChat { + private ClearChat() { + throw new IllegalStateException("Utility class"); + } public static String getLabel() { return "clear"; diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/CoinFlip.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/CoinFlip.java index 445803e..46ef21f 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/CoinFlip.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/CoinFlip.java @@ -14,6 +14,9 @@ import java.util.List; public class CoinFlip { + private CoinFlip() { + throw new IllegalStateException("Utility class"); + } public static Button getReflipButton() { return Button.primary("coinflip_reflip", "Flip again") diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/DiceRoll.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/DiceRoll.java index 9c295a7..827b9ba 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/DiceRoll.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/DiceRoll.java @@ -14,6 +14,11 @@ import java.util.UUID; public class DiceRoll { + + private DiceRoll() { + throw new IllegalStateException("Utility class"); + } + public static MessageResponse buildResponse(User author, String[] args) { LinkedHashMap dicesToRoll = new LinkedHashMap<>(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/Invite.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/Invite.java index 67a0cee..e754214 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/Invite.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/Invite.java @@ -10,6 +10,10 @@ import wtf.beatrice.hidekobot.HidekoBot; public class Invite { + private Invite() { + throw new IllegalStateException("Utility class"); + } + public static MessageEmbed generateEmbed() { EmbedBuilder embedBuilder = new EmbedBuilder(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/LoveCalculator.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/LoveCalculator.java index de47518..871c160 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/LoveCalculator.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/LoveCalculator.java @@ -10,6 +10,11 @@ import java.util.concurrent.TimeUnit; public class LoveCalculator { + + private LoveCalculator() { + throw new IllegalStateException("Utility class"); + } + public static MessageEmbed buildEmbedAndCacheResult(User author, User user1, User user2) { String userId1 = user1.getId(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/MagicBall.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/MagicBall.java index e03e1ab..e28abb5 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/MagicBall.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/MagicBall.java @@ -14,6 +14,10 @@ import java.util.List; public class MagicBall { + private MagicBall() { + throw new IllegalStateException("Utility class"); + } + public static LinkedList getLabels() { return new LinkedList<>(Arrays.asList("8ball", "8b", "eightball", "magicball")); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/ProfileImage.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/ProfileImage.java index 7cfb1ba..ef90b01 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/ProfileImage.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/ProfileImage.java @@ -8,6 +8,11 @@ import wtf.beatrice.hidekobot.objects.MessageResponse; public class ProfileImage { + + private ProfileImage() { + throw new IllegalStateException("Utility class"); + } + public static int parseResolution(int resolution) { int[] acceptedSizes = Cache.getSupportedAvatarResolutions(); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/Say.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/Say.java index 33c5670..339cea7 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/Say.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/Say.java @@ -5,6 +5,10 @@ import net.dv8tion.jda.api.Permission; public class Say { + private Say() { + throw new IllegalStateException("Utility class"); + } + public static Permission getPermission() { return Permission.MESSAGE_MANAGE; } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/Trivia.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/Trivia.java index ae783d7..cb66aea 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/Trivia.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/Trivia.java @@ -35,6 +35,11 @@ import java.util.concurrent.TimeUnit; public class Trivia { + + private Trivia() { + throw new IllegalStateException("Utility 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_CATEGORIES_LINK = "https://opentdb.com/api_category.php"; diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/UrbanDictionary.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/UrbanDictionary.java index 21029bb..41e08c7 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/UrbanDictionary.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/UrbanDictionary.java @@ -25,6 +25,10 @@ import java.util.List; public class UrbanDictionary { + private UrbanDictionary() { + throw new IllegalStateException("Utility class"); + } + public static LinkedList getCommandLabels() { return new LinkedList<>(Arrays.asList("urban", "urbandictionary", "ud")); } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/UserPunishment.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/UserPunishment.java index 1b14373..89ac1d5 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/UserPunishment.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/UserPunishment.java @@ -27,6 +27,10 @@ import java.util.concurrent.TimeUnit; public class UserPunishment { + private UserPunishment() { + throw new IllegalStateException("Utility class"); + } + private static final Duration maxTimeoutDuration = Duration.of(28, ChronoUnit.DAYS); private static final Duration minTimeoutDuration = Duration.of(30, ChronoUnit.SECONDS); diff --git a/src/main/java/wtf/beatrice/hidekobot/util/CommandUtil.java b/src/main/java/wtf/beatrice/hidekobot/util/CommandUtil.java index af683c7..ace8534 100644 --- a/src/main/java/wtf/beatrice/hidekobot/util/CommandUtil.java +++ b/src/main/java/wtf/beatrice/hidekobot/util/CommandUtil.java @@ -27,6 +27,10 @@ public class CommandUtil 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. * This will check in the database if that user ran the command originally. diff --git a/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java b/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java index c4a0577..2056dab 100644 --- a/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java +++ b/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java @@ -12,6 +12,9 @@ import java.util.Arrays; public class FormatUtil { + private FormatUtil() { + throw new IllegalStateException("Utility class"); + } // cosmetic string to print on startup. private static final String LOGO = """ diff --git a/src/main/java/wtf/beatrice/hidekobot/util/RandomUtil.java b/src/main/java/wtf/beatrice/hidekobot/util/RandomUtil.java index 5213fda..e3369a1 100644 --- a/src/main/java/wtf/beatrice/hidekobot/util/RandomUtil.java +++ b/src/main/java/wtf/beatrice/hidekobot/util/RandomUtil.java @@ -10,6 +10,10 @@ import java.util.Random; 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 seed is updated periodically, if the random.org integration is enabled. private static Random randomInstance = new SecureRandom(); diff --git a/src/main/java/wtf/beatrice/hidekobot/util/SerializationUtil.java b/src/main/java/wtf/beatrice/hidekobot/util/SerializationUtil.java index 512bdb1..9324485 100644 --- a/src/main/java/wtf/beatrice/hidekobot/util/SerializationUtil.java +++ b/src/main/java/wtf/beatrice/hidekobot/util/SerializationUtil.java @@ -10,6 +10,10 @@ import java.util.List; public class SerializationUtil { + private SerializationUtil() { + throw new IllegalStateException("Utility class"); + } + public static String serializeBase64(List dataList) { try (ByteArrayOutputStream bo = new ByteArrayOutputStream();