Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Whitespace in AI Triggers #597

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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