From 26827e79dbb3bda00727828404ccd648934e41f3 Mon Sep 17 00:00:00 2001 From: LordLuceus Date: Tue, 14 May 2024 17:19:35 +0200 Subject: [PATCH] fix: Check group names for special characters --- src/commands/dice/rollGroup.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/commands/dice/rollGroup.ts b/src/commands/dice/rollGroup.ts index 8bc516e..3b96238 100644 --- a/src/commands/dice/rollGroup.ts +++ b/src/commands/dice/rollGroup.ts @@ -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, @@ -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, @@ -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) { @@ -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); + } }