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 10d2358..21029bb 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/UrbanDictionary.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/UrbanDictionary.java @@ -263,10 +263,10 @@ public class UrbanDictionary htmlContributor.indexOf("") + 4); contributorsNames.add(htmlContributorName - .replaceAll("<.*?>", "")); // remove all html tags; + .replaceAll("<.*?>", "")); // remove all html tags submissionDates.add(htmlSubmitDate - .replaceAll("<.*?>", "")); // remove all html tags; + .replaceAll("<.*?>", "")); // remove all html tags } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/AvatarCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/AvatarCommand.java index 083e93a..db28831 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/AvatarCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/AvatarCommand.java @@ -70,6 +70,7 @@ public class AvatarCommand implements MessageCommand resFound = true; break; } catch (NumberFormatException ignored) { + // ignored because we're running a check after this block } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/BannerCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/BannerCommand.java index f0f7858..dd0cd9b 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/BannerCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/BannerCommand.java @@ -70,6 +70,7 @@ public class BannerCommand implements MessageCommand resFound = true; break; } catch (NumberFormatException ignored) { + // ignored because we're running a check after this block } } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/ClearCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/ClearCommand.java index e634cb5..e5281d3 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/ClearCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/ClearCommand.java @@ -52,8 +52,6 @@ public class ClearCommand implements MessageCommand @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { - String senderId = event.getMessage().getAuthor().getId(); - // check if user is trying to run command in dms. String error = ClearChat.checkDMs(event.getChannel()); if (error != null) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/DiceRollCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/DiceRollCommand.java index cf1f672..2cc4976 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/DiceRollCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/DiceRollCommand.java @@ -33,13 +33,16 @@ public class DiceRollCommand implements MessageCommand @NotNull @Override - public String getDescription() { - return "Roll dice. You can roll multiple dice at the same time." + - "\nExamples:" + - "\n - `d8 10` to roll an 8-sided die 10 times." + - "\n - `d12 3 d5 10` to roll a 12-sided die 3 times, and then a 5-sided die 10 times." + - "\n - `30` to roll a standard 6-sided die 30 times." + - "\n - `d10` to roll a 10-sided die once."; + public String getDescription() + { + return """ + Roll dice. You can roll multiple dice at the same time. + Examples: + - `d8 10` to roll an 8-sided die 10 times. + - `d12 3 d5 10` to roll a 12-sided die 3 times, and then a 5-sided die 10 times. + - `30` to roll a standard 6-sided die 30 times. + - `d10` to roll a 10-sided die once. + """; } @Nullable diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/HelpCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/HelpCommand.java index f1b78b4..af4ca5e 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/HelpCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/HelpCommand.java @@ -11,10 +11,7 @@ import wtf.beatrice.hidekobot.commands.base.Alias; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; +import java.util.*; public class HelpCommand implements MessageCommand { @@ -82,10 +79,11 @@ public class HelpCommand implements MessageCommand "\nYou will find a list of commands organized in categories below.", false); - for(CommandCategory category : commandCategories.keySet()) + for(Map.Entry> entry : commandCategories.entrySet()) { StringBuilder commandsList = new StringBuilder(); - LinkedList commandsOfThisCategory = commandCategories.get(category); + CommandCategory category = entry.getKey(); + LinkedList commandsOfThisCategory = entry.getValue(); for(int pos = 0; pos < commandsOfThisCategory.size(); pos++) { diff --git a/src/main/java/wtf/beatrice/hidekobot/datasources/ConfigurationSource.java b/src/main/java/wtf/beatrice/hidekobot/datasources/ConfigurationSource.java index f4755b2..a2212f5 100644 --- a/src/main/java/wtf/beatrice/hidekobot/datasources/ConfigurationSource.java +++ b/src/main/java/wtf/beatrice/hidekobot/datasources/ConfigurationSource.java @@ -9,6 +9,7 @@ import wtf.beatrice.hidekobot.HidekoBot; import java.io.*; import java.util.LinkedHashMap; +import java.util.Map; public class ConfigurationSource { @@ -94,15 +95,18 @@ public class ConfigurationSource // create a new mixed map that will take existing values from the non-missing keys // and fill everything else with the default values LinkedHashMap filledEntries = new LinkedHashMap<>(); - for(String key : internalConfigContents.keySet()) + + for(Map.Entry entry : internalConfigContents.entrySet()) { + String key = entry.getKey(); + if(fsConfigContents.containsKey(key)) { // if the key already exists, copy the original value filledEntries.put(key, fsConfigContents.get(key)); } else { // else, copy the value from the example config file - filledEntries.put(key, internalConfigContents.get(key)); + filledEntries.put(key, entry.getValue()); } } diff --git a/src/main/java/wtf/beatrice/hidekobot/listeners/MessageCommandListener.java b/src/main/java/wtf/beatrice/hidekobot/listeners/MessageCommandListener.java index 4265141..e047046 100644 --- a/src/main/java/wtf/beatrice/hidekobot/listeners/MessageCommandListener.java +++ b/src/main/java/wtf/beatrice/hidekobot/listeners/MessageCommandListener.java @@ -11,7 +11,6 @@ import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import wtf.beatrice.hidekobot.objects.comparators.MessageCommandAliasesComparator; -import wtf.beatrice.hidekobot.util.Logger; import java.util.*; @@ -20,13 +19,13 @@ public class MessageCommandListener extends ListenerAdapter // map storing command labels and command object alphabetically. private final TreeMap, MessageCommand> registeredCommands = - new TreeMap, MessageCommand>(new MessageCommandAliasesComparator()); + new TreeMap<>(new MessageCommandAliasesComparator()); // map commands and their categories. // this is not strictly needed but it's better to have it so we avoid looping every time we need to check the cat. LinkedHashMap> commandCategories = new LinkedHashMap<>(); - private final String commandRegex = "(?i)^(hideko|hde)\\b"; + private static final String COMMAND_REGEX = "(?i)^(hideko|hde)\\b"; // (?i) -> case insensitive flag // ^ -> start of string (not in middle of a sentence) // \b -> the word has to end here @@ -39,12 +38,14 @@ public class MessageCommandListener extends ListenerAdapter public MessageCommand getRegisteredCommand(String label) { - for(LinkedList aliases : registeredCommands.keySet()) + for(Map.Entry, MessageCommand> entry : registeredCommands.entrySet()) { + LinkedList aliases = entry.getKey(); + for(String currentAlias : aliases) { if(label.equals(currentAlias)) - { return registeredCommands.get(aliases); } + { return entry.getValue(); } } } @@ -54,9 +55,6 @@ public class MessageCommandListener extends ListenerAdapter public LinkedList getRegisteredCommands() { return new LinkedList<>(registeredCommands.values()); } - - private final Logger logger = new Logger(MessageCommandListener.class); - @Override public void onMessageReceived(@NotNull MessageReceivedEvent event) { @@ -67,11 +65,11 @@ public class MessageCommandListener extends ListenerAdapter String eventMessage = event.getMessage().getContentRaw(); // check if the sent message matches the bot activation regex (prefix, name, ...) - if(!eventMessage.toLowerCase().matches("(?s)" + commandRegex + ".*")) + if(!eventMessage.toLowerCase().matches("(?s)" + COMMAND_REGEX + ".*")) return; // generate args from the string - String argsString = eventMessage.replaceAll(commandRegex + "\\s*", ""); + String argsString = eventMessage.replaceAll(COMMAND_REGEX + "\\s*", ""); // if no args were specified apart from the bot prefix @@ -115,16 +113,13 @@ public class MessageCommandListener extends ListenerAdapter { Member member = event.getMember(); GuildChannel channel = event.getGuildChannel(); //todo: what about forum post - if(member != null) + if(member != null && !member.hasPermission(channel, requiredPermissions)) { - if(!member.hasPermission(channel, requiredPermissions)) - { - event.getMessage() - .reply("You do not have permissions to run this command!") - .queue(); // todo prettier - // todo: queue message deletion in 15 seconds or so - return; - } + event.getMessage() + .reply("You do not have permissions to run this command!") + .queue(); // todo prettier + // todo: queue message deletion in 15 seconds or so + return; } } diff --git a/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java b/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java index b92b772..c4a0577 100644 --- a/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java +++ b/src/main/java/wtf/beatrice/hidekobot/util/FormatUtil.java @@ -70,7 +70,9 @@ public class FormatUtil if(hours == 0) { if(minutes == 0) - {} else { // i know this if has an empty body but i feel like this reads better + { + // empty code block because it makes the code easier to read + } else { uptimeStringBuilder.append(minutes).append("m "); } } else { diff --git a/src/main/java/wtf/beatrice/hidekobot/util/Logger.java b/src/main/java/wtf/beatrice/hidekobot/util/Logger.java index 77b3556..8709bcc 100644 --- a/src/main/java/wtf/beatrice/hidekobot/util/Logger.java +++ b/src/main/java/wtf/beatrice/hidekobot/util/Logger.java @@ -5,8 +5,8 @@ import java.time.format.DateTimeFormatter; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -@Deprecated -public class Logger +@Deprecated(since = "0.5.16", forRemoval = true) +public class Logger { // objects that we need to have for a properly formatted message @@ -17,7 +17,7 @@ public class Logger // when initializing a new logger, save variables in that instance - public Logger(Class logClass) + public Logger(Class logClass) { className = logClass.getSimpleName(); } diff --git a/src/main/java/wtf/beatrice/hidekobot/util/SerializationUtil.java b/src/main/java/wtf/beatrice/hidekobot/util/SerializationUtil.java index 5be4092..512bdb1 100644 --- a/src/main/java/wtf/beatrice/hidekobot/util/SerializationUtil.java +++ b/src/main/java/wtf/beatrice/hidekobot/util/SerializationUtil.java @@ -10,7 +10,7 @@ import java.util.List; public class SerializationUtil { - public static String serializeBase64(List dataList) { + public static String serializeBase64(List dataList) { try (ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo)) { @@ -23,7 +23,7 @@ public class SerializationUtil } } - public static LinkedList deserializeBase64(String dataStr) { + public static LinkedList deserializeBase64(String dataStr) { byte[] b = Base64.getDecoder().decode(dataStr); ByteArrayInputStream bi = new ByteArrayInputStream(b);