Skip to content

Commit

Permalink
Merge pull request #597 from beanbeanjuice/596-remove-ai-whitespaces
Browse files Browse the repository at this point in the history
Removed Whitespace in AI Triggers
  • Loading branch information
beanbeanjuice authored Oct 30, 2023
2 parents 3559f11 + 114d746 commit 702dacf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author beanbeanjuice
*/
public class AiCommand implements ICommand {
public class AICommand implements ICommand {

@Override
public void handle(@NotNull SlashCommandInteractionEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ private void createMaps() throws IOException {
ArrayList<String> triggers = new ArrayList<>();
ArrayList<String> 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());
Expand All @@ -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()
Expand Down

0 comments on commit 702dacf

Please sign in to comment.