Adds invalid character sequences to group names

This commit is contained in:
Michel Fedde 2025-05-27 21:58:43 +02:00
parent 68007c2d35
commit aef26b1cc3

View file

@ -27,13 +27,19 @@ import {IconCache} from "../../Icons/IconCache";
import {PlaydateRepository} from "../../Repositories/PlaydateRepository"; import {PlaydateRepository} from "../../Repositories/PlaydateRepository";
import playdate from "../../Database/tables/Playdate"; import playdate from "../../Database/tables/Playdate";
import Commands from "./Commands"; import Commands from "./Commands";
import Groups from "../../Database/tables/Groups";
export class GroupCommand implements Command, ChatInteractionCommand, AutocompleteCommand { export class GroupCommand implements Command, ChatInteractionCommand, AutocompleteCommand {
private static GOODBYE_MESSAGES: string[] = [ private static GOODBYE_MESSAGES: string[] = [
'Sad to see you go.', 'Sad to see you go.',
'May your next adventure be fruitful.', 'May your next adventure be fruitful.',
'I hope, I served you well.', '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 { 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." "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 = { const group: GroupModel = {
id: -1, 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 }) 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) { private list(interaction: ChatInputCommandInteraction) {
const repo = Container.get<GroupRepository>(GroupRepository.name); const repo = Container.get<GroupRepository>(GroupRepository.name);