Skip to content
This repository was archived by the owner on Jun 9, 2024. It is now read-only.

Commit d174f34

Browse files
committed
feature: Regex-validate application command names (closes #545)
1 parent 1a27110 commit d174f34

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/main/java/com/mewna/catnip/rest/handler/RestInteraction.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@
4949

5050
import javax.annotation.Nonnull;
5151
import javax.annotation.Nullable;
52-
import java.util.Collection;
53-
import java.util.EnumSet;
54-
import java.util.List;
55-
import java.util.Map;
52+
import java.util.*;
5653
import java.util.stream.Collectors;
5754

5855
/**
@@ -405,6 +402,11 @@ private JsonObject createSendBody(@Nullable final InteractionResponseType type,
405402
private JsonObject createCommandBody(@Nonnull final ApplicationCommandType type, @Nonnull final String name,
406403
@Nonnull final String description, @Nonnull final Collection<ApplicationCommandOption> options) {
407404
final var builder = JsonObject.builder();
405+
if(type == ApplicationCommandType.CHAT_INPUT) {
406+
if(!name.matches("^[\\w-]{1,32}$") || !name.toLowerCase(Locale.ROOT).equals(name)) {
407+
throw new IllegalArgumentException("Name must match ^[\\w-]{1,32}$ and must be lowercase!");
408+
}
409+
}
408410
builder.value("name", name);
409411
builder.value("description", description);
410412
builder.value("type", type.id());

0 commit comments

Comments
 (0)