Finished adding 10 new config checker validators

This commit is contained in:
DJj123dj
2025-08-27 11:46:42 +02:00
parent f4f6f30fa2
commit 810db76e91
3 changed files with 35 additions and 6 deletions
+10
View File
@@ -241,9 +241,18 @@ export type ODCheckerTranslationRegisterMessageIds_Default = (
"opendiscord:string-starts-with"|
"opendiscord:string-ends-with"|
"opendiscord:string-contains"|
"opendiscord:string-inverted-contains"|
"opendiscord:string-choices"|
"opendiscord:string-lowercase"|
"opendiscord:string-uppercase"|
"opendiscord:string-special-characters"|
"opendiscord:string-no-spaces"|
"opendiscord:string-regex"|
"opendiscord:string-capital-word"|
"opendiscord:string-capital-sentence"|
"opendiscord:string-punctuation"|
"opendiscord:number-nan"|
"opendiscord:number-too-short"|
"opendiscord:number-too-long"|
"opendiscord:number-length-invalid"|
@@ -255,6 +264,7 @@ export type ODCheckerTranslationRegisterMessageIds_Default = (
"opendiscord:number-starts-with"|
"opendiscord:number-ends-with"|
"opendiscord:number-contains"|
"opendiscord:number-inverted-contains"|
"opendiscord:number-choices"|
"opendiscord:number-float"|
"opendiscord:number-negative"|
+15 -6
View File
@@ -624,9 +624,8 @@ export class ODCheckerStringStructure extends ODCheckerStructure {
}else{
//warnings
if ((this.options.capitalLetterWarning == "word" && !value.split(" ").every((word) => word.length == 0 || /^[^a-z].*/.test(word)))) checker.createMessage("opendiscord:string-capital-word","warning",`It's recommended that each word in this string starts with a capital letter!`,lt,null,[],this.id,(this.options.docs ?? null))
if ((this.options.capitalLetterWarning == "sentence" && !value.split(/ *[.?!] */).every((sentence) => sentence.length == 0 || /^[^a-z].*/.test(sentence)))) checker.createMessage("opendiscord:string-capital-word","warning",`It looks like some sentences in this string don't start with a capital letter!`,lt,null,[],this.id,(this.options.docs ?? null))
//TODO: punctuation!!!
if ((this.options.capitalLetterWarning == "sentence" && !value.split(/ *[.?!] */).every((sentence) => sentence.length == 0 || /^[^a-z].*/.test(sentence)))) checker.createMessage("opendiscord:string-capital-sentence","warning",`It looks like some sentences in this string don't start with a capital letter!`,lt,null,[],this.id,(this.options.docs ?? null))
if (this.options.punctuationWarning && value.length > 0 && (!value.endsWith(".") && !value.endsWith("?") && !value.endsWith("!") && !value.endsWith("'") && !value.endsWith('"') && !value.endsWith(",") && !value.endsWith(";") && !value.endsWith(":") && !value.endsWith("="))) checker.createMessage("opendiscord:string-punctuation","warning",`It looks like the sentence in this string doesn't end with a punctuation mark!`,lt,null,[],this.id,(this.options.docs ?? null))
return super.check(checker,value,locationTrace)
}
@@ -637,6 +636,8 @@ export class ODCheckerStringStructure extends ODCheckerStructure {
* This interface has the options for `ODCheckerNumberStructure`!
*/
export interface ODCheckerNumberStructureOptions extends ODCheckerStructureOptions {
/**Is `NaN` (not a number) allowed? (`false` by default) */
nanAllowed?:boolean
/**The minimum length of this number */
minLength?:number,
/**The maximum length of this number */
@@ -659,6 +660,8 @@ export interface ODCheckerNumberStructureOptions extends ODCheckerStructureOptio
endsWith?:string,
/**This number needs to contain ... */
contains?:string,
/**This number is not allowed to contain ... */
invertedContains?:string,
/**You need to choose between ... */
choices?:number[],
/**Are numbers with a decimal value allowed? */
@@ -693,6 +696,9 @@ export class ODCheckerNumberStructure extends ODCheckerStructure {
if (typeof value != "number"){
checker.createMessage("opendiscord:invalid-type","error","This property needs to be the type: number!",lt,null,["number"],this.id,(this.options.docs ?? null))
return false
}else if (!this.options.nanAllowed && isNaN(value)){
checker.createMessage("opendiscord:number-nan","error",`This number can't NaN (Not A Number)!`,lt,null,[],this.id,(this.options.docs ?? null))
return false
}else if (typeof this.options.minLength != "undefined" && value.toString().length < this.options.minLength){
checker.createMessage("opendiscord:number-too-short","error",`This number can't be shorter than ${this.options.minLength} characters!`,lt,null,[this.options.minLength.toString()],this.id,(this.options.docs ?? null))
return false
@@ -724,19 +730,22 @@ export class ODCheckerNumberStructure extends ODCheckerStructure {
}else if (typeof this.options.contains != "undefined" && !value.toString().includes(this.options.contains)){
checker.createMessage("opendiscord:number-contains","error",`This number needs to contain "${this.options.contains}"!`,lt,null,[`"${this.options.contains}"`],this.id,(this.options.docs ?? null))
return false
}else if (typeof this.options.invertedContains != "undefined" && value.toString().includes(this.options.invertedContains)){
checker.createMessage("opendiscord:number-inverted-contains","error",`This number is not allowed to contain "${this.options.invertedContains}"!`,lt,null,[`"${this.options.invertedContains}"`],this.id,(this.options.docs ?? null))
return false
}else if (typeof this.options.choices != "undefined" && !this.options.choices.includes(value)){
checker.createMessage("opendiscord:number-choices","error",`This number can only be one of the following values: "${this.options.choices.join(`", "`)}"!`,lt,null,[`"${this.options.choices.join(`", "`)}"`],this.id,(this.options.docs ?? null))
return false
}else if (typeof this.options.floatAllowed != "undefined" && !this.options.floatAllowed && (value % 1) !== 0){
checker.createMessage("opendiscord:number-float","error","This number can't be a decimal!",lt,null,[],this.id,(this.options.docs ?? null))
return false
}else if (typeof this.options.negativeAllowed != "undefined" && value < 0){
}else if (typeof this.options.negativeAllowed != "undefined" && !this.options.negativeAllowed && value < 0){
checker.createMessage("opendiscord:number-negative","error","This number can't be negative!",lt,null,[],this.id,(this.options.docs ?? null))
return false
}else if (typeof this.options.positiveAllowed != "undefined" && value > 0){
}else if (typeof this.options.positiveAllowed != "undefined" && !this.options.positiveAllowed && value > 0){
checker.createMessage("opendiscord:number-positive","error","This number can't be positive!",lt,null,[],this.id,(this.options.docs ?? null))
return false
}else if (typeof this.options.zeroAllowed != "undefined" && value === 0){
}else if (typeof this.options.zeroAllowed != "undefined" && !this.options.zeroAllowed && value === 0){
checker.createMessage("opendiscord:number-zero","error","This number can't be zero!",lt,null,[],this.id,(this.options.docs ?? null))
return false
}else return super.check(checker,value,locationTrace)
+10
View File
@@ -78,9 +78,18 @@ export const registerDefaultCheckerMessageTranslations = (tm:api.ODCheckerTransl
tm.quickTranslate(lm,"checker.messages.stringStartsWith","message","opendiscord:string-starts-with") // This string needs to start with {0}!
tm.quickTranslate(lm,"checker.messages.stringEndsWith","message","opendiscord:string-ends-with") // This string needs to end with {0}!
tm.quickTranslate(lm,"checker.messages.stringContains","message","opendiscord:string-contains") // This string needs to contain {0}!
tm.quickTranslate(lm,"//TODO TRANSLATION!!!","message","opendiscord:string-inverted-contains") // This string is not allowed to contain {0}!
tm.quickTranslate(lm,"checker.messages.stringChoices","message","opendiscord:string-choices") // This string can only be one of the following values: {0}!
tm.quickTranslate(lm,"//TODO TRANSLATION!!!","message","opendiscord:string-lowercase") // This string must be written in lowercase only!
tm.quickTranslate(lm,"//TODO TRANSLATION!!!","message","opendiscord:string-uppercase") // This string must be written in uppercase only!
tm.quickTranslate(lm,"//TODO TRANSLATION!!!","message","opendiscord:string-special-characters") // This string is not allowed to contain any special characters! (a-z, 0-9 & space only)
tm.quickTranslate(lm,"//TODO TRANSLATION!!!","message","opendiscord:string-no-spaces") // This string is not allowed to contain spaces!
tm.quickTranslate(lm,"checker.messages.stringRegex","message","opendiscord:string-regex") // This string is invalid!
tm.quickTranslate(lm,"//TODO TRANSLATION!!!","message","opendiscord:string-capital-word") // It's recommended that each word in this string starts with a capital letter!
tm.quickTranslate(lm,"//TODO TRANSLATION!!!","message","opendiscord:string-capital-sentence") // It looks like some sentences in this string don't start with a capital letter!
tm.quickTranslate(lm,"//TODO TRANSLATION!!!","message","opendiscord:string-punctuation") // It looks like the sentence in this string doesn't end with a punctuation mark!
tm.quickTranslate(lm,"//TODO TRANSLATION!!!","message","opendiscord:number-nan") // This number can't NaN (Not A Number)!
tm.quickTranslate(lm,"checker.messages.numberTooShort","message","opendiscord:number-too-short") // This number can't be shorter than {0} characters!
tm.quickTranslate(lm,"checker.messages.numberTooLong","message","opendiscord:number-too-long") // This number can't be longer than {0} characters!
tm.quickTranslate(lm,"checker.messages.numberLengthInvalid","message","opendiscord:number-length-invalid") // This number needs to be {0} characters long!
@@ -92,6 +101,7 @@ export const registerDefaultCheckerMessageTranslations = (tm:api.ODCheckerTransl
tm.quickTranslate(lm,"checker.messages.numberStartsWith","message","opendiscord:number-starts-with") // This number needs to start with {0}!
tm.quickTranslate(lm,"checker.messages.numberEndsWith","message","opendiscord:number-ends-with") // This number needs to end with {0}!
tm.quickTranslate(lm,"checker.messages.numberContains","message","opendiscord:number-contains") // This number needs to contain {0}!
tm.quickTranslate(lm,"//TODO TRANSLATION!!!","message","opendiscord:number-inverted-contains") // This number is not allowed to contain {0}!
tm.quickTranslate(lm,"checker.messages.numberChoices","message","opendiscord:number-choices") // This number can only be one of the following values: {0}!
tm.quickTranslate(lm,"checker.messages.numberFloat","message","opendiscord:number-float") // This number can't be a decimal!
tm.quickTranslate(lm,"checker.messages.numberNegative","message","opendiscord:number-negative") // This number can't be negative!