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 {
@ -122,6 +128,11 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
); );
} }
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,
name: name, name: name,
@ -140,6 +151,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);
const groups = repo.findGroupsByMember(<GuildMember>interaction.member); const groups = repo.findGroupsByMember(<GuildMember>interaction.member);