Channel configuration UI: form validation.

This commit is contained in:
John Livingston
2023-09-25 12:51:15 +02:00
parent e2c85af001
commit 06b9417650
4 changed files with 85 additions and 7 deletions

View File

@ -64,7 +64,7 @@ function _readInteger (data: any, f: string, min: number, max: number): number {
return v
}
function _readSimpleInput (data: any, f: string, strict?: boolean): string {
function _readSimpleInput (data: any, f: string, strict?: boolean, noSpace?: boolean): string {
if (!(f in data)) {
return ''
}
@ -78,6 +78,9 @@ function _readSimpleInput (data: any, f: string, strict?: boolean): string {
// Replacing all invalid characters, no need to throw an error..
s = s.replace(/[^\p{L}\p{N}\p{Z}_-]$/gu, '')
}
if (noSpace) {
s = s.replace(/\s+/g, '')
}
return s
}
@ -185,7 +188,7 @@ function _readCommands (botData: any): ChannelConfigurationOptions['bot']['comma
const result: ChannelConfigurationOptions['bot']['commands'] = []
for (const cs of botData.commands) {
const message = _readSimpleInput(cs, 'message')
const command = _readSimpleInput(cs, 'command')
const command = _readSimpleInput(cs, 'command', false, true)
result.push({
message,