(v4.2.0) Added 5 new question types
Added support for dropdown, radio select, checkbox select, file upload & text display question types.
This commit is contained in:
@@ -686,7 +686,21 @@ export const defaultQuestionsStructure = new api.ODCheckerArrayStructure("opendi
|
||||
],cliDisplayName:"Choice",cliDisplayDescription:"A choice for this checkbox select question."}),cliDisplayName:"Choices",cliDisplayPropertyName:"choice",cliDisplayDescription:"Manage all available choices of this checkbox select question."})}
|
||||
],cliDisplayName:"Checkbox Select Question",cliDisplayDescription:"Manage, customise and configure the checkbox select question to your preference."})},
|
||||
|
||||
],cliDisplayName:"Question",cliDisplayDescription:"Manage a question of one of the 6 types: short, paragraph, text-display, dropdown, radio-select, checkbox-select."}),cliDisplayName:"Questions",cliDisplayDescription:"A list of all questions in the bot. Here you can add, modify & remove existing questions or customise them to your preference."})
|
||||
//FILE UPLOAD QUESTION
|
||||
{name:"File Upload Question",priority:0,properties:[{key:"type",value:"file-upload"}],checker:new api.ODCheckerObjectStructure("opendiscord:file-upload-question",{cliDisplayKeyInParentArray:"name",cliDisplayAdditionalKeysInParentArray:["id","type"],children:[
|
||||
{key:"id",checker:new api.ODCheckerCustomStructure_UniqueId("opendiscord:question-id","openticket","question-ids",{regex:/^[A-Za-z0-9-éèçàêâôûî]+$/,minLength:3,maxLength:40,cliDisplayName:"Id",cliDisplayDescription:"The id of this question. Used in ticket options."})},
|
||||
{key:"name",checker:new api.ODCheckerStringStructure("opendiscord:question-name",{minLength:3,maxLength:45,cliDisplayName:"Name",cliDisplayDescription:"The name of this question."})},
|
||||
{key:"description",checker:new api.ODCheckerStringStructure("opendiscord:question-description",{maxLength:100,cliDisplayName:"Description",cliDisplayDescription:"The description of this question."})},
|
||||
{key:"required",checker:new api.ODCheckerBooleanStructure("opendiscord:question-required",{cliDisplayName:"Required",cliDisplayDescription:"Is this question required? If not, it can be left empty."})},
|
||||
|
||||
{key:"limits",checker:new api.ODCheckerEnabledObjectStructure("opendiscord:amount",{property:"enabled",enabledValue:true,checker:new api.ODCheckerObjectStructure("opendiscord:amount",{children:[
|
||||
{key:"enabled",checker:new api.ODCheckerBooleanStructure("opendiscord:amount-enabled",{cliDisplayName:"Enabled",cliDisplayDescription:"Enable/disable checking the min/max amount of uploaded files."})},
|
||||
{key:"min",checker:new api.ODCheckerNumberStructure("opendiscord:amount-min",{min:0,max:10,floatAllowed:false,cliDisplayName:"Min Amount",cliDisplayDescription:"The minimum amount of uploaded files required."})},
|
||||
{key:"max",checker:new api.ODCheckerNumberStructure("opendiscord:amount-max",{min:1,max:10,floatAllowed:false,cliInitDefaultValue:10,cliDisplayName:"Max Amount",cliDisplayDescription:"The maximum amount of uploaded files allowed."})},
|
||||
],cliDisplayName:"Upload Limits",cliDisplayDescription:"Verify the minimum or maximum amount of uploaded files."}),cliDisplayName:"Checkbox Limits",cliDisplayDescription:"Verify the minimum or maximum amount of uploaded files."})},
|
||||
],cliDisplayName:"Checkbox Select Question",cliDisplayDescription:"Manage, customise and configure the file upload question to your preference."})},
|
||||
|
||||
],cliDisplayName:"Question",cliDisplayDescription:"Manage a question of one of the 7 types: short, paragraph, text-display, dropdown, radio-select, checkbox-select, file-upload."}),cliDisplayName:"Questions",cliDisplayDescription:"A list of all questions in the bot. Here you can add, modify & remove existing questions or customise them to your preference."})
|
||||
|
||||
export const defaultTranscriptsStructure = new api.ODCheckerObjectStructure("opendiscord:transcripts",{children:[
|
||||
//GENERAL
|
||||
|
||||
@@ -286,6 +286,21 @@ export const defaultQuestionsFormatter = new fjs.TopLevelCommentFormatter(new fj
|
||||
new fjs.PropertyFormatter("selectedByDefault"),
|
||||
])),
|
||||
])},
|
||||
{key:"type",value:"file-upload",formatter:new fjs.ObjectFormatter(null,true,[
|
||||
new fjs.MultiCommentFormatter("A file upload modal question where users can upload one or more files."),
|
||||
new fjs.PropertyFormatter("id"),
|
||||
new fjs.PropertyFormatter("name"),
|
||||
new fjs.PropertyFormatter("description",new fjs.SingleCommentFormatter("Leave empty to disable")),
|
||||
new fjs.PropertyFormatter("type"),
|
||||
new fjs.PropertyFormatter("required"),
|
||||
new fjs.TextFormatter(""),
|
||||
new fjs.ObjectFormatter("limits",true,[
|
||||
new fjs.MultiCommentFormatter("Configure minimum/maximum amount of files to upload."),
|
||||
new fjs.PropertyFormatter("enabled"),
|
||||
new fjs.PropertyFormatter("min"),
|
||||
new fjs.PropertyFormatter("max"),
|
||||
]),
|
||||
])},
|
||||
])))
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,15 @@ export async function loadAllQuestions(){
|
||||
const questionConfig = opendiscord.configs.get("opendiscord:questions")
|
||||
if (!questionConfig) return
|
||||
|
||||
questionConfig.data.forEach((question) => {
|
||||
if (question.type == "short"){
|
||||
opendiscord.questions.add(loadShortQuestion(question))
|
||||
}else if (question.type == "paragraph"){
|
||||
opendiscord.questions.add(loadParagraphQuestion(question))
|
||||
}
|
||||
})
|
||||
for (const question of questionConfig.data){
|
||||
if (question.type === "short") opendiscord.questions.add(loadShortQuestion(question))
|
||||
else if (question.type === "paragraph") opendiscord.questions.add(loadParagraphQuestion(question))
|
||||
else if (question.type === "dropdown") opendiscord.questions.add(loadDropdownQuestion(question))
|
||||
else if (question.type === "radio-select") opendiscord.questions.add(loadRadioSelectQuestion(question))
|
||||
else if (question.type === "checkbox-select") opendiscord.questions.add(loadCheckboxSelectQuestion(question))
|
||||
else if (question.type === "file-upload") opendiscord.questions.add(loadFileUploadQuestion(question))
|
||||
else if (question.type === "text-display") opendiscord.questions.add(loadTextDisplayQuestion(question))
|
||||
}
|
||||
|
||||
//update questions on config reload
|
||||
questionConfig.onReload(async () => {
|
||||
@@ -18,22 +20,25 @@ export async function loadAllQuestions(){
|
||||
await opendiscord.questions.loopAll((data,id) => {opendiscord.questions.remove(id)})
|
||||
|
||||
//add new questions
|
||||
questionConfig.data.forEach((question) => {
|
||||
if (question.type == "short"){
|
||||
opendiscord.questions.add(loadShortQuestion(question))
|
||||
}else if (question.type == "paragraph"){
|
||||
opendiscord.questions.add(loadParagraphQuestion(question))
|
||||
}
|
||||
})
|
||||
for (const question of questionConfig.data){
|
||||
if (question.type === "short") opendiscord.questions.add(loadShortQuestion(question))
|
||||
else if (question.type === "paragraph") opendiscord.questions.add(loadParagraphQuestion(question))
|
||||
else if (question.type === "dropdown") opendiscord.questions.add(loadDropdownQuestion(question))
|
||||
else if (question.type === "radio-select") opendiscord.questions.add(loadRadioSelectQuestion(question))
|
||||
else if (question.type === "checkbox-select") opendiscord.questions.add(loadCheckboxSelectQuestion(question))
|
||||
else if (question.type === "file-upload") opendiscord.questions.add(loadFileUploadQuestion(question))
|
||||
else if (question.type === "text-display") opendiscord.questions.add(loadTextDisplayQuestion(question))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const loadShortQuestion = (option:api.ODQuestionsJsonConfig_ShortQuestion) => {
|
||||
return new api.ODShortQuestion(option.id,[
|
||||
new api.ODQuestionData("opendiscord:name",option.name),
|
||||
new api.ODQuestionData("opendiscord:description",option.description),
|
||||
new api.ODQuestionData("opendiscord:required",option.required),
|
||||
|
||||
new api.ODQuestionData("opendiscord:placeholder",option.placeholder),
|
||||
|
||||
new api.ODQuestionData("opendiscord:length-enabled",option.length.enabled),
|
||||
new api.ODQuestionData("opendiscord:length-min",option.length.min),
|
||||
new api.ODQuestionData("opendiscord:length-max",option.length.max),
|
||||
@@ -43,11 +48,64 @@ export const loadShortQuestion = (option:api.ODQuestionsJsonConfig_ShortQuestion
|
||||
export const loadParagraphQuestion = (option:api.ODQuestionsJsonConfig_ParagraphQuestion) => {
|
||||
return new api.ODParagraphQuestion(option.id,[
|
||||
new api.ODQuestionData("opendiscord:name",option.name),
|
||||
new api.ODQuestionData("opendiscord:description",option.description),
|
||||
new api.ODQuestionData("opendiscord:required",option.required),
|
||||
|
||||
new api.ODQuestionData("opendiscord:placeholder",option.placeholder),
|
||||
|
||||
new api.ODQuestionData("opendiscord:length-enabled",option.length.enabled),
|
||||
new api.ODQuestionData("opendiscord:length-min",option.length.min),
|
||||
new api.ODQuestionData("opendiscord:length-max",option.length.max),
|
||||
])
|
||||
}
|
||||
|
||||
export const loadDropdownQuestion = (option:api.ODQuestionsJsonConfig_DropdownQuestion) => {
|
||||
return new api.ODDropdownQuestion(option.id,[
|
||||
new api.ODQuestionData("opendiscord:name",option.name),
|
||||
new api.ODQuestionData("opendiscord:description",option.description),
|
||||
new api.ODQuestionData("opendiscord:required",option.required),
|
||||
|
||||
new api.ODQuestionData("opendiscord:placeholder",option.placeholder),
|
||||
new api.ODQuestionData("opendiscord:choices",option.choices)
|
||||
])
|
||||
}
|
||||
|
||||
export const loadRadioSelectQuestion = (option:api.ODQuestionsJsonConfig_RadioSelectQuestion) => {
|
||||
return new api.ODRadioSelectQuestion(option.id,[
|
||||
new api.ODQuestionData("opendiscord:name",option.name),
|
||||
new api.ODQuestionData("opendiscord:description",option.description),
|
||||
new api.ODQuestionData("opendiscord:required",option.required),
|
||||
|
||||
new api.ODQuestionData("opendiscord:choices",option.choices)
|
||||
])
|
||||
}
|
||||
|
||||
export const loadCheckboxSelectQuestion = (option:api.ODQuestionsJsonConfig_CheckboxSelectQuestion) => {
|
||||
return new api.ODCheckboxSelectQuestion(option.id,[
|
||||
new api.ODQuestionData("opendiscord:name",option.name),
|
||||
new api.ODQuestionData("opendiscord:description",option.description),
|
||||
new api.ODQuestionData("opendiscord:required",option.required),
|
||||
|
||||
new api.ODQuestionData("opendiscord:limits-enabled",option.limits.enabled),
|
||||
new api.ODQuestionData("opendiscord:limits-min",option.limits.min),
|
||||
new api.ODQuestionData("opendiscord:limits-max",option.limits.max),
|
||||
new api.ODQuestionData("opendiscord:choices",option.choices)
|
||||
])
|
||||
}
|
||||
|
||||
export const loadFileUploadQuestion = (option:api.ODQuestionsJsonConfig_FileUploadQuestion) => {
|
||||
return new api.ODFileUploadQuestion(option.id,[
|
||||
new api.ODQuestionData("opendiscord:name",option.name),
|
||||
new api.ODQuestionData("opendiscord:description",option.description),
|
||||
new api.ODQuestionData("opendiscord:required",option.required),
|
||||
|
||||
new api.ODQuestionData("opendiscord:limits-enabled",option.limits.enabled),
|
||||
new api.ODQuestionData("opendiscord:limits-min",option.limits.min),
|
||||
new api.ODQuestionData("opendiscord:limits-max",option.limits.max),
|
||||
])
|
||||
}
|
||||
|
||||
export const loadTextDisplayQuestion = (option:api.ODQuestionsJsonConfig_TextDisplayQuestion) => {
|
||||
return new api.ODTextDisplayQuestion(option.id,[
|
||||
new api.ODQuestionData("opendiscord:text-contents",option.textContents)
|
||||
])
|
||||
}
|
||||
Reference in New Issue
Block a user