Adds invalid character sequences to group names
This commit is contained in:
parent
68007c2d35
commit
aef26b1cc3
1 changed files with 24 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
@ -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 = {
|
||||
id: -1,
|
||||
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 })
|
||||
}
|
||||
|
||||
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>(GroupRepository.name);
|
||||
const groups = repo.findGroupsByMember(<GuildMember>interaction.member);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue