From aef26b1cc335603def29961419316880b8160e28 Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Tue, 27 May 2025 21:58:43 +0200 Subject: [PATCH] Adds invalid character sequences to group names --- source/Discord/Commands/Groups.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/source/Discord/Commands/Groups.ts b/source/Discord/Commands/Groups.ts index f9cb3df..bc03974 100644 --- a/source/Discord/Commands/Groups.ts +++ b/source/Discord/Commands/Groups.ts @@ -27,13 +27,19 @@ import {IconCache} from "../../Icons/IconCache"; import {PlaydateRepository} from "../../Repositories/PlaydateRepository"; import playdate from "../../Database/tables/Playdate"; import Commands from "./Commands"; +import Groups from "../../Database/tables/Groups"; export class GroupCommand implements Command, ChatInteractionCommand, AutocompleteCommand { private static GOODBYE_MESSAGES: string[] = [ 'Sad to see you go.', 'May your next adventure be fruitful.', 'I hope, I served you well.', - 'I wish you, good luck on your next adventures.', + 'I wish you and your group good luck on your next adventures.', + ] + + private static INVALID_CHARACTER_SEQUENCES: string[] = [ + "http://", + "https://" ] definition(): SlashCommandBuilder { @@ -121,6 +127,11 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple "Add yourself to the group or ask your admin to do so." ); } + + const validName = this.validateGroupName(name); + if (name !== true) { + throw new UserError(`Your group name contains one or more invalid character sequences: ${validName}`) + } const group: GroupModel = { id: -1, @@ -139,6 +150,18 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple interaction.reply({content: `:white_check_mark: Created group \`${name}\``, flags: MessageFlags.Ephemeral }) } + + private validateGroupName(name: string): true|string{ + const lowercaseName = name.toLowerCase(); + for (let invalidcharactersequence of GroupCommand.INVALID_CHARACTER_SEQUENCES) { + if (!lowercaseName.includes(invalidcharactersequence)) { + continue + } + + return invalidcharactersequence + } + return true; + } private list(interaction: ChatInputCommandInteraction) { const repo = Container.get(GroupRepository.name);