Coerce arrays of strings to arrays automatically
parent
d03903ce80
commit
f7b8a312f9
|
@ -171,7 +171,7 @@ for (const [key, value] of Object.entries(config)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate config and assign defaults (if missing)
|
// Validate config and assign defaults (if missing)
|
||||||
const ajv = new Ajv({ useDefaults: true });
|
const ajv = new Ajv({ useDefaults: true, coerceTypes: "array" });
|
||||||
const validate = ajv.compile(schema);
|
const validate = ajv.compile(schema);
|
||||||
const configIsValid = validate(config);
|
const configIsValid = validate(config);
|
||||||
|
|
||||||
|
|
|
@ -3,24 +3,14 @@
|
||||||
"title": "ModmailConfig",
|
"title": "ModmailConfig",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"stringOrArrayOfStrings": {
|
"stringArray": {
|
||||||
"oneOf": [
|
|
||||||
{
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
"multilineString": {
|
||||||
"type": "null"
|
"$ref": "#/definitions/stringArray"
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"stringOrMultilineString": {
|
|
||||||
"$ref": "#/definitions/stringOrArrayOfStrings"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -28,7 +18,7 @@
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"mainGuildId": {
|
"mainGuildId": {
|
||||||
"$ref": "#/definitions/stringOrArrayOfStrings"
|
"$ref": "#/definitions/stringArray"
|
||||||
},
|
},
|
||||||
"mailGuildId": {
|
"mailGuildId": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
@ -54,11 +44,11 @@
|
||||||
"default": "Message me for help!"
|
"default": "Message me for help!"
|
||||||
},
|
},
|
||||||
"responseMessage": {
|
"responseMessage": {
|
||||||
"$ref": "#/definitions/stringOrMultilineString",
|
"$ref": "#/definitions/multilineString",
|
||||||
"default": "Thank you for your message! Our mod team will reply to you here as soon as possible."
|
"default": "Thank you for your message! Our mod team will reply to you here as soon as possible."
|
||||||
},
|
},
|
||||||
"closeMessage": {
|
"closeMessage": {
|
||||||
"$ref": "#/definitions/stringOrMultilineString"
|
"$ref": "#/definitions/multilineString"
|
||||||
},
|
},
|
||||||
"allowUserClose": {
|
"allowUserClose": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
@ -77,11 +67,11 @@
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
"botMentionResponse": {
|
"botMentionResponse": {
|
||||||
"$ref": "#/definitions/stringOrMultilineString"
|
"$ref": "#/definitions/multilineString"
|
||||||
},
|
},
|
||||||
|
|
||||||
"inboxServerPermission": {
|
"inboxServerPermission": {
|
||||||
"$ref": "#/definitions/stringOrArrayOfStrings"
|
"$ref": "#/definitions/stringArray"
|
||||||
},
|
},
|
||||||
"alwaysReply": {
|
"alwaysReply": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
@ -141,7 +131,7 @@
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
"greetingMessage": {
|
"greetingMessage": {
|
||||||
"$ref": "#/definitions/stringOrMultilineString"
|
"$ref": "#/definitions/multilineString"
|
||||||
},
|
},
|
||||||
"greetingAttachment": {
|
"greetingAttachment": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
@ -149,7 +139,7 @@
|
||||||
"guildGreetings": {
|
"guildGreetings": {
|
||||||
"patternProperties": {
|
"patternProperties": {
|
||||||
"^\\d+$": {
|
"^\\d+$": {
|
||||||
"$ref": "#/definitions/stringOrMultilineString"
|
"$ref": "#/definitions/multilineString"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"default": {}
|
"default": {}
|
||||||
|
@ -160,7 +150,7 @@
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"accountAgeDeniedMessage": {
|
"accountAgeDeniedMessage": {
|
||||||
"$ref": "#/definitions/stringOrMultilineString",
|
"$ref": "#/definitions/multilineString",
|
||||||
"default": "Your Discord account is not old enough to contact modmail."
|
"default": "Your Discord account is not old enough to contact modmail."
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -169,7 +159,7 @@
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"timeOnServerDeniedMessage": {
|
"timeOnServerDeniedMessage": {
|
||||||
"$ref": "#/definitions/stringOrMultilineString",
|
"$ref": "#/definitions/multilineString",
|
||||||
"default": "You haven't been a member of the server for long enough to contact modmail."
|
"default": "You haven't been a member of the server for long enough to contact modmail."
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue