Skip to content

Commit

Permalink
fix: Check group names for special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
LordLuceus committed May 14, 2024
1 parent cf2bdbd commit 26827e7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/commands/dice/rollGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ export class RollGroupCommand extends Subcommand {
});

if (!savedGroup) {
if (RollGroupCommand.hasSpecialCharacters(group)) {
return interaction.reply({
content: "A group name cannot contain any special characters.",
ephemeral: true,
});
}

await prisma.rollGroup.create({
data: {
name: group,
Expand Down Expand Up @@ -463,6 +470,13 @@ export class RollGroupCommand extends Subcommand {
});
}

if (RollGroupCommand.hasSpecialCharacters(name)) {
return interaction.reply({
content: "A group name cannot contain any special characters.",
ephemeral: true,
});
}

await prisma.rollGroup.create({
data: {
name,
Expand All @@ -472,7 +486,7 @@ export class RollGroupCommand extends Subcommand {
});

return interaction.reply({
content: `Created group \`${name}\`. Use the \`/add\` command to add roll shortcuts to the group.`,
content: `Created group \`${name}\`. Use the \`/group add\` command to add roll shortcuts to the group.`,
ephemeral: true,
});
} catch (err: any) {
Expand Down Expand Up @@ -646,4 +660,9 @@ export class RollGroupCommand extends Subcommand {

return savedGuild;
}

private static hasSpecialCharacters(name: string): boolean {
const regex = /[^a-zA-Z0-9-_ ]/g;
return regex.test(name);
}
}

0 comments on commit 26827e7

Please sign in to comment.