Skip to content

Commit

Permalink
Ignore syntactically wrong patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Dec 7, 2023
1 parent a17ca86 commit cbb489f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.neoforged.camelot.commands.utility;

import com.google.re2j.Pattern;
import com.google.re2j.PatternSyntaxException;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
Expand Down Expand Up @@ -60,8 +61,9 @@ protected void execute(SlashCommandEvent event) {
final String regex = event.getOption("regex", "", OptionMapping::getAsString);
try {
Pattern.compile(regex);
} catch (Exception ex) {
} catch (PatternSyntaxException ex) {
event.reply("Regex is invalid!").setEphemeral(true).queue();
return;
}

Database.pings().useExtension(PingsDAO.class, db -> db.insert(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.neoforged.camelot.db.transactionals;

import com.google.re2j.Pattern;
import com.google.re2j.PatternSyntaxException;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.neoforged.camelot.db.api.RegisterExecutionCallbacks;
Expand Down Expand Up @@ -82,9 +83,13 @@ default Long2ObjectMap<List<Ping>> getAllPings() {
return getHandle().createQuery("select guild, id, user, regex, message from pings")
.reduceResultSet(new Long2ObjectOpenHashMap<List<Ping>>(), (previous, rs, ctx) -> {
final long guild = rs.getLong(1);
previous.computeIfAbsent(guild, k -> new ArrayList<>()).add(new Ping(
rs.getInt(2), rs.getLong(3), Pattern.compile(rs.getString(4)), rs.getString(5)
));
try {
previous.computeIfAbsent(guild, k -> new ArrayList<>()).add(new Ping(
rs.getInt(2), rs.getLong(3), Pattern.compile(rs.getString(4)), rs.getString(5)
));
} catch (PatternSyntaxException _) {

}
return previous;
});
}
Expand Down

0 comments on commit cbb489f

Please sign in to comment.