From 114d74693e91b04a0cf85e9bf0150fe24006dea5 Mon Sep 17 00:00:00 2001 From: beanbeanjuice Date: Sat, 23 Sep 2023 07:49:30 -0700 Subject: [PATCH] Removed Whitespace in AI Triggers --- .../settings/{AiCommand.java => AICommand.java} | 2 +- .../utility/command/CommandHandler.java | 4 ++-- .../utility/listener/AIResponseListener.java | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) rename src/main/java/com/beanbeanjuice/command/settings/{AiCommand.java => AICommand.java} (98%) diff --git a/src/main/java/com/beanbeanjuice/command/settings/AiCommand.java b/src/main/java/com/beanbeanjuice/command/settings/AICommand.java similarity index 98% rename from src/main/java/com/beanbeanjuice/command/settings/AiCommand.java rename to src/main/java/com/beanbeanjuice/command/settings/AICommand.java index 4ac1932a..92e695b2 100644 --- a/src/main/java/com/beanbeanjuice/command/settings/AiCommand.java +++ b/src/main/java/com/beanbeanjuice/command/settings/AICommand.java @@ -18,7 +18,7 @@ * * @author beanbeanjuice */ -public class AiCommand implements ICommand { +public class AICommand implements ICommand { @Override public void handle(@NotNull SlashCommandInteractionEvent event) { diff --git a/src/main/java/com/beanbeanjuice/utility/command/CommandHandler.java b/src/main/java/com/beanbeanjuice/utility/command/CommandHandler.java index c3fffac9..98c46d7e 100644 --- a/src/main/java/com/beanbeanjuice/utility/command/CommandHandler.java +++ b/src/main/java/com/beanbeanjuice/utility/command/CommandHandler.java @@ -12,7 +12,7 @@ import com.beanbeanjuice.command.moderation.ClearChatCommand; import com.beanbeanjuice.command.moderation.CreateEmbedCommand; import com.beanbeanjuice.command.moderation.bind.BindCommand; -import com.beanbeanjuice.command.settings.AiCommand; +import com.beanbeanjuice.command.settings.AICommand; import com.beanbeanjuice.command.settings.ListCustomChannelsCommand; import com.beanbeanjuice.command.settings.birthday.BirthdayChannelCommand; import com.beanbeanjuice.command.settings.counting.CountingChannelCommand; @@ -158,7 +158,7 @@ public CommandHandler(@NotNull JDA jda) { commands.put("venting-channel", new VentingChannelCommand()); commands.put("welcome-channel", new WelcomeChannelCommand()); commands.put("goodbye-channel", new GoodbyeChannelCommand()); - commands.put("ai", new AiCommand()); + commands.put("ai", new AICommand()); commands.put("list-custom-channels", new ListCustomChannelsCommand()); // Social diff --git a/src/main/java/com/beanbeanjuice/utility/listener/AIResponseListener.java b/src/main/java/com/beanbeanjuice/utility/listener/AIResponseListener.java index 354e1b6e..6d392c65 100644 --- a/src/main/java/com/beanbeanjuice/utility/listener/AIResponseListener.java +++ b/src/main/java/com/beanbeanjuice/utility/listener/AIResponseListener.java @@ -52,8 +52,13 @@ private void createMaps() throws IOException { ArrayList triggers = new ArrayList<>(); ArrayList responses = new ArrayList<>(); + /* + Adds the trigger. + Deletes all whitespaces. + Deletes all characters that are not letters or numbers. + */ for (JsonNode trigger : type.get("triggers")) - triggers.add(trigger.asText()); + triggers.add(trigger.asText().replaceAll("[^a-zA-Z0-9]", "")); for (JsonNode response : type.get("responses")) responses.add(response.asText()); @@ -80,7 +85,11 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { String message = event.getMessage().getContentRaw().toLowerCase(); messageMap.forEach((commandTerms, commandResponses) -> { - if (commandTerms.contains(message.replaceAll("[^\\sa-zA-Z0-9]", ""))) { + /* + Replaces all the messages such that it only contains letters and numbers. + This includes removing whitespaces. + */ + if (commandTerms.contains(message.replaceAll("[^a-zA-Z0-9]", ""))) { event.getMessage().reply(parseMessage( commandResponses.get(Helper.getRandomNumber(0, commandResponses.size())), event.getAuthor()