Open Ticket v4 Beta

This commit is contained in:
DJj123dj
2024-08-21 13:24:56 +02:00
parent 9326d0fae8
commit 0c2aca7039
154 changed files with 33881 additions and 0 deletions
+591
View File
@@ -0,0 +1,591 @@
import {openticket, api, utilities} from "../../index"
const generalConfig = openticket.configs.get("openticket:general")
export const loadAllConfigCheckers = async () => {
openticket.checkers.add(new api.ODChecker("openticket:general",openticket.checkers.storage,0,openticket.configs.get("openticket:general"),defaultGeneralStructure))
openticket.checkers.add(new api.ODChecker("openticket:options",openticket.checkers.storage,1,openticket.configs.get("openticket:options"),defaultOptionsStructure))
openticket.checkers.add(new api.ODChecker("openticket:panels",openticket.checkers.storage,0,openticket.configs.get("openticket:panels"),defaultPanelsStructure))
openticket.checkers.add(new api.ODChecker("openticket:questions",openticket.checkers.storage,2,openticket.configs.get("openticket:questions"),defaultQuestionsStructure))
openticket.checkers.add(new api.ODChecker("openticket:transcripts",openticket.checkers.storage,0,openticket.configs.get("openticket:transcripts"),defaultTranscriptsStructure))
}
export const loadAllConfigCheckerFunctions = async () => {
openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:unused-options",defaultUnusedOptionsFunction))
openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:dropdown-options",defaultDropdownOptionsFunction))
}
export const loadAllConfigCheckerTranslations = async () => {
if ((generalConfig && generalConfig.data.system && generalConfig.data.system.useTranslatedConfigChecker) ? generalConfig.data.system.useTranslatedConfigChecker : false){
registerDefaultCheckerSystemTranslations() //translate checker system text
registerDefaultCheckerMessageTranslations() //translate checker messages
registerDefaultCheckerCustomTranslations() //translate custom checker messages
}
}
//GLOBAL FUNCTIONS
export const registerDefaultCheckerSystemTranslations = () => {
const tm = openticket.checkers.translation
const lm = openticket.languages
//SYSTEM
//tm.quickTranslate(lm,"checker.system.headerOpenTicket","other","openticket:header-openticket") //OPEN TICKET (ignore)
tm.quickTranslate(lm,"checker.system.typeError","other","openticket:type-error") // [ERROR] (ignore)
tm.quickTranslate(lm,"checker.system.typeWarning","other","openticket:type-warning") // [WARNING] (ignore)
tm.quickTranslate(lm,"checker.system.typeInfo","other","openticket:type-info") // [INFO] (ignore)
tm.quickTranslate(lm,"checker.system.headerConfigChecker","other","openticket:header-configchecker") // CONFIG CHECKER
tm.quickTranslate(lm,"checker.system.headerDescription","other","openticket:header-description") // check for errors in you config files!
tm.quickTranslate(lm,"checker.system.footerError","other","openticket:footer-error") // the bot won't start until all {0}'s are fixed!
tm.quickTranslate(lm,"checker.system.footerWarning","other","openticket:footer-warning") // it's recommended to fix all {0}'s before starting!
tm.quickTranslate(lm,"checker.system.footerSupport","other","openticket:footer-support") // SUPPORT: {0} - DOCS: {1}
tm.quickTranslate(lm,"checker.system.compactInformation","other","openticket:compact-information") // use {0} for more information!
tm.quickTranslate(lm,"checker.system.dataPath","other","openticket:data-path") // path
tm.quickTranslate(lm,"checker.system.dataDocs","other","openticket:data-docs") // docs
tm.quickTranslate(lm,"checker.system.dataMessages","other","openticket:data-message") // message
}
export const registerDefaultCheckerMessageTranslations = () => {
const tm = openticket.checkers.translation
const lm = openticket.languages
//STRUCTURES
tm.quickTranslate(lm,"checker.messages.invalidType","message","openticket:invalid-type") // This property needs to be the type: {0}!
tm.quickTranslate(lm,"checker.messages.propertyMissing","message","openticket:property-missing") // The property {0} is missing from this object!
tm.quickTranslate(lm,"checker.messages.propertyOptional","message","openticket:property-optional") // The property {0} is optional in this object!
tm.quickTranslate(lm,"checker.messages.objectDisabled","message","openticket:object-disabled") // This object is disabled, enable it using {0}!
tm.quickTranslate(lm,"checker.messages.nullInvalid","message","openticket:null-invalid") // This property can't be null!
tm.quickTranslate(lm,"checker.messages.switchInvalidType","message","openticket:switch-invalid-type") // This needs to be one of the following types: {0}!
tm.quickTranslate(lm,"checker.messages.objectSwitchInvalid","message","openticket:object-switch-invalid-type") // This object needs to be one of the following types: {0}!
tm.quickTranslate(lm,"checker.messages.stringTooShort","message","openticket:string-too-short") // This string can't be shorter than {0} characters!
tm.quickTranslate(lm,"checker.messages.stringTooLong","message","openticket:string-too-long") // This string can't be longer than {0} characters!
tm.quickTranslate(lm,"checker.messages.stringLengthInvalid","message","openticket:string-length-invalid") // This string needs to be {0} characters long!
tm.quickTranslate(lm,"checker.messages.stringStartsWith","message","openticket:string-starts-with") // This string needs to start with {0}!
tm.quickTranslate(lm,"checker.messages.stringEndsWith","message","openticket:string-ends-with") // This string needs to end with {0}!
tm.quickTranslate(lm,"checker.messages.stringContains","message","openticket:string-contains") // This string needs to contain {0}!
tm.quickTranslate(lm,"checker.messages.stringChoices","message","openticket:string-choices") // This string can only be one of the following values: {0}!
tm.quickTranslate(lm,"checker.messages.stringRegex","message","openticket:string-regex") // This string is invalid!
tm.quickTranslate(lm,"checker.messages.numberTooShort","message","openticket:number-too-short") // This number can't be shorter than {0} characters!
tm.quickTranslate(lm,"checker.messages.numberTooLong","message","openticket:number-too-long") // This number can't be longer than {0} characters!
tm.quickTranslate(lm,"checker.messages.numberLengthInvalid","message","openticket:number-length-invalid") // This number needs to be {0} characters long!
tm.quickTranslate(lm,"checker.messages.numberTooSmall","message","openticket:number-too-small") // This number needs to be at least {0}!
tm.quickTranslate(lm,"checker.messages.numberTooLarge","message","openticket:number-too-large") // This number needs to be at most {0}!
tm.quickTranslate(lm,"checker.messages.numberNotEqual","message","openticket:number-not-equal") // This number needs to be {0}!
tm.quickTranslate(lm,"checker.messages.numberStep","message","openticket:number-step") // This number needs to be a multiple of {0}!
tm.quickTranslate(lm,"checker.messages.numberStepOffset","message","openticket:number-step-offset") // This number needs to be a multiple of {0} starting with {1}!
tm.quickTranslate(lm,"checker.messages.numberStartsWith","message","openticket:number-starts-with") // This number needs to start with {0}!
tm.quickTranslate(lm,"checker.messages.numberEndsWith","message","openticket:number-ends-with") // This number needs to end with {0}!
tm.quickTranslate(lm,"checker.messages.numberContains","message","openticket:number-contains") // This number needs to contain {0}!
tm.quickTranslate(lm,"checker.messages.numberChoices","message","openticket:number-choices") // This number can only be one of the following values: {0}!
tm.quickTranslate(lm,"checker.messages.numberFloat","message","openticket:number-float") // This number can't be a decimal!
tm.quickTranslate(lm,"checker.messages.numberNegative","message","openticket:number-negative") // This number can't be negative!
tm.quickTranslate(lm,"checker.messages.numberPositive","message","openticket:number-positive") // This number can't be positive!
tm.quickTranslate(lm,"checker.messages.numberZero","message","openticket:number-zero") // This number can't be zero!
tm.quickTranslate(lm,"checker.messages.booleanTrue","message","openticket:boolean-true") // This boolean can't be true!
tm.quickTranslate(lm,"checker.messages.booleanFalse","message","openticket:boolean-false") // This boolean can't be false!
tm.quickTranslate(lm,"checker.messages.arrayEmptyDisabled","message","openticket:array-empty-disabled") // This array isn't allowed to be empty!
tm.quickTranslate(lm,"checker.messages.arrayEmptyRequired","message","openticket:array-empty-required") // This array is required to be empty!
tm.quickTranslate(lm,"checker.messages.arrayTooShort","message","openticket:array-too-short") // This array needs to have a length of at least {0}!
tm.quickTranslate(lm,"checker.messages.arrayTooLong","message","openticket:array-too-long") // This array needs to have a length of at most {0}!
tm.quickTranslate(lm,"checker.messages.arrayLengthInvalid","message","openticket:array-length-invalid") // This array needs to have a length of {0}!
tm.quickTranslate(lm,"checker.messages.arrayInvalidTypes","message","openticket:array-invalid-types") // This array can only contain the following types: {0}!
tm.quickTranslate(lm,"checker.messages.arrayDouble","message","openticket:array-double") // This array doesn't allow the same value twice!
tm.quickTranslate(lm,"checker.messages.discordInvalidId","message","openticket:discord-invalid-id") // This is an invalid discord {0} id!
tm.quickTranslate(lm,"checker.messages.discordInvalidIdOptions","message","openticket:discord-invalid-id-options") // This is an invalid discord {0} id! You can also use one of these: {1}!
tm.quickTranslate(lm,"checker.messages.discordInvalidToken","message","openticket:discord-invalid-token") // This is an invalid discord token (syntactically)!
tm.quickTranslate(lm,"checker.messages.colorInvalid","message","openticket:color-invalid") // This is an invalid hex color!
tm.quickTranslate(lm,"checker.messages.emojiTooShort","message","openticket:emoji-too-short") // This string needs to have at least {0} emoji's!
tm.quickTranslate(lm,"checker.messages.emojiTooLong","message","openticket:emoji-too-long") // This string needs to have at most {0} emoji's!
tm.quickTranslate(lm,"checker.messages.emojiCustom","message","openticket:emoji-custom") // This emoji can't be a custom discord emoji!
tm.quickTranslate(lm,"checker.messages.emojiInvalid","message","openticket:emoji-invalid") // This is an invalid emoji!
tm.quickTranslate(lm,"checker.messages.urlInvalid","message","openticket:url-invalid") // This url is invalid!
tm.quickTranslate(lm,"checker.messages.urlInvalidHttp","message","openticket:url-invalid-http") // This url can only use the https:// protocol!
tm.quickTranslate(lm,"checker.messages.urlInvalidProtocol","message","openticket:url-invalid-protocol") // This url can only use the http:// & https:// protocols!
tm.quickTranslate(lm,"checker.messages.urlInvalidHostname","message","openticket:url-invalid-hostname") // This url has a disallowed hostname!
tm.quickTranslate(lm,"checker.messages.urlInvalidExtension","message","openticket:url-invalid-extension") // This url has an invalid extension! Choose between: {0}!
tm.quickTranslate(lm,"checker.messages.urlInvalidPath","message","openticket:url-invalid-path") // This url has an invalid path!
tm.quickTranslate(lm,"checker.messages.idNotUnique","message","openticket:id-not-unique") // This id isn't unique, use another id instead!
tm.quickTranslate(lm,"checker.messages.idNonExistent","message","openticket:id-non-existent") // The id {0} doesn't exist!
}
export const registerDefaultCheckerCustomTranslations = () => {
const tm = openticket.checkers.translation
const lm = openticket.languages
//CUSTOM
tm.quickTranslate(lm,"checker.messages.invalidLanguage","message","openticket:invalid-language") // This is an invalid language!
tm.quickTranslate(lm,"checker.messages.invalidButton","message","openticket:invalid-button") // This button needs to have at least an {0} or {1}!
tm.quickTranslate(lm,"checker.messages.unusedOption","message","openticket:unused-option") // The option {0} isn't used anywhere!
tm.quickTranslate(lm,"checker.messages.unusedQuestion","message","openticket:unused-question") // The question {0} isn't used anywhere!
tm.quickTranslate(lm,"checker.messages.dropdownOption","message","openticket:dropdown-option") // A panel with dropdown enabled can only contain options of the 'ticket' type!
}
//UTILITY FUNCTIONS
const createMsgStructure = (id:api.ODValidId) => {
return new api.ODCheckerObjectStructure(id,{children:[
{key:"dm",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:msg-dm",{})},
{key:"logs",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:msg-logs",{})},
]})
}
const createTicketEmbedStructure = (id:api.ODValidId) => {
return new api.ODCheckerEnabledObjectStructure(id,{property:"enabled",enabledValue:true,checker:new api.ODCheckerObjectStructure(id,{children:[
{key:"title",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-embed-text",{maxLength:256})},
{key:"description",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-embed-description",{maxLength:4096})},
{key:"customColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:ticket-embed-color",true,true)},
{key:"image",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UrlString("openticket:ticket-embed-image",true,{allowHttp:false,allowedExtensions:[".png",".jpg",".jpeg",".webp",".gif"]})},
{key:"thumbnail",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UrlString("openticket:ticket-embed-thumbnail",true,{allowHttp:false,allowedExtensions:[".png",".jpg",".jpeg",".webp",".gif"]})},
{key:"fields",optional:false,priority:0,checker:new api.ODCheckerArrayStructure("openticket:ticket-embed-fields",{allowedTypes:["object"],propertyChecker:new api.ODCheckerObjectStructure("openticket:ticket-embed-fields",{children:[
{key:"name",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-embed-field-name",{minLength:1,maxLength:256})},
{key:"value",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-embed-field-value",{minLength:1,maxLength:1024})},
{key:"inline",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-embed-field-inline",{})}
]})})},
{key:"timestamp",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-embed-timestamp",{})}
]})})
}
const createTicketPingStructure = (id:api.ODValidId) => {
return new api.ODCheckerObjectStructure(id,{children:[
{key:"@here",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-ping-here",{})},
{key:"@everyone",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-ping-everyone",{})},
{key:"custom",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordIdArray("openticket:ticket-ping-custom","role",[],{allowDoubles:false})},
]})
}
const createPanelEmbedStructure = (id:api.ODValidId) => {
return new api.ODCheckerEnabledObjectStructure(id,{property:"enabled",enabledValue:true,checker:new api.ODCheckerObjectStructure(id,{children:[
{key:"title",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:panel-embed-text",{maxLength:256})},
{key:"description",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:panel-embed-description",{maxLength:4096})},
{key:"customColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:panel-embed-color",true,true)},
{key:"url",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UrlString("openticket:panel-embed-url",true,{allowHttp:false})},
{key:"image",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UrlString("openticket:panel-embed-image",true,{allowHttp:false,allowedExtensions:[".png",".jpg",".jpeg",".webp",".gif"]})},
{key:"thumbnail",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UrlString("openticket:panel-embed-thumbnail",true,{allowHttp:false,allowedExtensions:[".png",".jpg",".jpeg",".webp",".gif"]})},
{key:"footer",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:panel-embed-footer",{maxLength:2048})},
{key:"fields",optional:false,priority:0,checker:new api.ODCheckerArrayStructure("openticket:panel-embed-fields",{allowedTypes:["object"],propertyChecker:new api.ODCheckerObjectStructure("openticket:panel-embed-fields",{children:[
{key:"name",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:panel-embed-field-name",{minLength:1,maxLength:256})},
{key:"value",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:panel-embed-field-value",{minLength:1,maxLength:1024})},
{key:"inline",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:panel-embed-field-inline",{})}
]})})},
{key:"timestamp",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:panel-embed-timestamp",{})}
]})})
}
//STRUCTURES
export const defaultGeneralStructure = new api.ODCheckerObjectStructure("openticket:general",{children:[
//BASIC
{key:"token",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordToken("openticket:token")},
{key:"tokenFromENV",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:token-env",{})},
{key:"mainColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:main-color",true,false)},
{key:"language",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:language",{
custom:(checker,value,locationTrace,locationId,locationDocs) => {
const lt = checker.locationTraceDeref(locationTrace)
if (typeof value != "string") return false
else if (!openticket.defaults.getDefault("languageList").includes(value)){
checker.createMessage("openticket:invalid-language","error","This is an invalid language!",lt,null,[],locationId,locationDocs)
return false
}else return true
},
})},
{key:"prefix",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:prefix",{minLength:1})},
{key:"serverId",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:server-id","server",false,[])},
{key:"globalAdmins",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordIdArray("openticket:global-admins","role",[],{allowDoubles:false})},
{key:"slashCommands",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:slash-commands",{})},
{key:"textCommands",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:text-commands",{})},
//STATUS
{key:"status",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:status",{
property:"enabled",
enabledValue:true,
checker:new api.ODCheckerObjectStructure("openticket:status",{children:[
{key:"type",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:status-type",{choices:["listening","watching","playing","custom"]})},
{key:"text",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:status-text",{minLength:1,maxLength:128})},
{key:"status",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:status-type",{choices:["online","invisible","idle","dnd"]})},
]})
})},
//SYSTEM
{key:"system",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:system",{children:[
{key:"removeParticipantsOnClose",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:remove-participants-on-close",{})},
{key:"replyOnTicketCreation",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:reply-on-ticket-creation",{})},
{key:"replyOnReactionRole",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:reply-on-reaction-role",{})},
{key:"useTranslatedConfigChecker",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:use-translated-config-checker",{})},
{key:"preferSlashOverText",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:prefer-slash-over-text",{})},
{key:"sendErrorOnUnknownCommand",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:send-error-on-unknown-command",{})},
{key:"questionFieldsInCodeBlock",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:question-fields-in-code-block",{})},
{key:"disableVerifyBars",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:disable-verify-bars",{})},
{key:"useRedErrorEmbeds",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:use-red-error-embeds",{})},
{key:"emojiStyle",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:emoji-style",{choices:["before","after","double","disabled"]})},
{key:"enableTicketClaimButtons",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:enable-ticket-claim-buttons",{})},
{key:"enableTicketCloseButtons",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:enable-ticket-close-buttons",{})},
{key:"enableTicketPinButtons",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:enable-ticket-pin-buttons",{})},
{key:"enableTicketDeleteButtons",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:enable-ticket-delete-buttons",{})},
{key:"enableTicketActionWithReason",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:enable-ticket-action-with-reason",{})},
{key:"enableDeleteWithoutTranscript",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:enable-delete-without-transcript",{})},
{key:"logs",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:system-logs",{
property:"enabled",
enabledValue:true,
checker:new api.ODCheckerObjectStructure("openticket:system-logs",{children:[
{key:"channel",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:log-channel","channel",false,[])},
]})
})},
{key:"limits",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:limits",{property:"enabled",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:limits",{children:[
{key:"globalMaximum",optional:false,priority:0,checker:new api.ODCheckerNumberStructure("openticket:limits-global",{zeroAllowed:false,negativeAllowed:false,floatAllowed:false,min:1})},
{key:"userMaximum",optional:false,priority:0,checker:new api.ODCheckerNumberStructure("openticket:limits-user",{zeroAllowed:false,negativeAllowed:false,floatAllowed:false,min:1})}
]})})},
{key:"permissions",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:system-permissions",{children:[
{key:"help",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-help","role",false,["admin","everyone","none"])},
{key:"panel",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-panel","role",false,["admin","everyone","none"])},
{key:"ticket",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-ticket","role",false,["admin","everyone","none"])},
{key:"close",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-close","role",false,["admin","everyone","none"])},
{key:"delete",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-delete","role",false,["admin","everyone","none"])},
{key:"reopen",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-reopen","role",false,["admin","everyone","none"])},
{key:"claim",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-claim","role",false,["admin","everyone","none"])},
{key:"unclaim",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-unclaim","role",false,["admin","everyone","none"])},
{key:"pin",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-pin","role",false,["admin","everyone","none"])},
{key:"unpin",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-unpin","role",false,["admin","everyone","none"])},
{key:"move",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-move","role",false,["admin","everyone","none"])},
{key:"rename",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-rename","role",false,["admin","everyone","none"])},
{key:"add",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-add","role",false,["admin","everyone","none"])},
{key:"remove",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-remove","role",false,["admin","everyone","none"])},
{key:"blacklist",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-blacklist","role",false,["admin","everyone","none"])},
{key:"stats",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-stats","role",false,["admin","everyone","none"])},
{key:"clear",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-clear","role",false,["admin","everyone","none"])},
{key:"autoclose",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-autoclose","role",false,["admin","everyone","none"])},
{key:"autodelete",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:permissions-autodelete","role",false,["admin","everyone","none"])}
]})},
{key:"messages",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:system-permissions",{children:[
{key:"creation",optional:false,priority:0,checker:createMsgStructure("openticket:msg-creation")},
{key:"closing",optional:false,priority:0,checker:createMsgStructure("openticket:msg-closing")},
{key:"deleting",optional:false,priority:0,checker:createMsgStructure("openticket:msg-deleting")},
{key:"reopening",optional:false,priority:0,checker:createMsgStructure("openticket:msg-reopening")},
{key:"claiming",optional:false,priority:0,checker:createMsgStructure("openticket:msg-claiming")},
{key:"pinning",optional:false,priority:0,checker:createMsgStructure("openticket:msg-pinning")},
{key:"adding",optional:false,priority:0,checker:createMsgStructure("openticket:msg-adding")},
{key:"removing",optional:false,priority:0,checker:createMsgStructure("openticket:msg-removing")},
{key:"renaming",optional:false,priority:0,checker:createMsgStructure("openticket:msg-renaming")},
{key:"moving",optional:false,priority:0,checker:createMsgStructure("openticket:msg-moving")},
{key:"blacklisting",optional:false,priority:0,checker:createMsgStructure("openticket:msg-blacklisting")},
{key:"roleAdding",optional:false,priority:0,checker:createMsgStructure("openticket:msg-role-adding")},
{key:"roleRemoving",optional:false,priority:0,checker:createMsgStructure("openticket:msg-role-removing")}
]})},
]})}
]})
export const defaultOptionsStructure = new api.ODCheckerArrayStructure("openticket:options",{allowedTypes:["object"],propertyChecker:new api.ODCheckerObjectSwitchStructure("openticket:options",{objects:[
//TICKET
{name:"ticket",priority:0,properties:[{key:"type",value:"ticket"}],checker:new api.ODCheckerObjectStructure("openticket:ticket",{children:[
{key:"id",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UniqueId("openticket:ticket-id","openticket","option-ids",{regex:/^[A-Za-z0-9-éèçàêâôûî]+$/,minLength:3,maxLength:40})},
{key:"name",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-name",{minLength:3,maxLength:50})},
{key:"description",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-description",{maxLength:256})},
//TICKET BUTTON
{key:"button",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:ticket-button",{children:[
{key:"emoji",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_EmojiString("openticket:ticket-button-emoji",0,1,true)},
{key:"label",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-button-label",{maxLength:50})},
{key:"color",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-button-color",{choices:["gray","red","green","blue"]})},
],custom:(checker,value,locationTrace,locationId,locationDocs) => {
const lt = checker.locationTraceDeref(locationTrace)
//check if emoji & label exists
if (typeof value != "object") return false
else if (value && value["emoji"].length < 1 && value["label"].length < 1){
//label & emoji are both empty
checker.createMessage("openticket:invalid-button","error",`This button needs to have at least an "emoji" or "label"!`,lt,null,[`"emoji"`,`"label"`],locationId,locationDocs)
return false
}else return true
}})},
//TICKET ADMINS
{key:"ticketAdmins",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordIdArray("openticket:ticket-ticket-admins","role",[],{allowDoubles:false})},
{key:"readonlyAdmins",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordIdArray("openticket:ticket-readonly-admins","role",[],{allowDoubles:false})},
{key:"allowCreationByBlacklistedUsers",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-allow-blacklisted-users",{})},
{key:"questions",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UniqueIdArray("openticket:option-questions","openticket","question-ids","question-ids-used",{allowDoubles:false,maxLength:5})},
//TICKET CHANNEL
{key:"channel",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:ticket-channel",{children:[
{key:"prefix",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-channel-prefix",{maxLength:25,regex:/^[^\s]*$/})},
{key:"suffix",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-channel-suffix",{choices:["user-name","user-id","random-number","random-hex","counter-dynamic","counter-fixed"]})},
{key:"category",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:ticket-channel-category","category",true,[])},
{key:"closedCategory",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:ticket-channel-closed-category","category",true,[])},
{key:"backupCategory",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:ticket-channel-backup-category","category",true,[])},
{key:"claimedCategory",optional:false,priority:0,checker:new api.ODCheckerArrayStructure("openticket:ticket-channel-claimed-category",{allowDoubles:false,allowedTypes:["object"],propertyChecker:new api.ODCheckerObjectStructure("openticket:ticket-channel-claimed-category",{children:[
{key:"user",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:ticket-channel-claimed-user","user",false,[])},
{key:"category",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:ticket-channel-claimed-category","category",false,[])}
]})})},
{key:"description",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-channel-description",{})},
]})},
//DM MESSAGE
{key:"dmMessage",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:ticket-dm-message",{property:"enabled",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:ticket-dm-message",{children:[
{key:"text",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-message-text",{maxLength:4096})},
{key:"embed",optional:false,priority:0,checker:createTicketEmbedStructure("openticket:ticket-message-embed")}
]})})},
//TICKET MESSAGE
{key:"ticketMessage",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:ticket-message",{property:"enabled",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:ticket-message",{children:[
{key:"text",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-message-text",{maxLength:4096})},
{key:"embed",optional:false,priority:0,checker:createTicketEmbedStructure("openticket:ticket-message-embed")},
{key:"ping",optional:false,priority:0,checker:createTicketPingStructure("openticket:ticket-message-ping")}
]})})},
//AUTOCLOSE
{key:"autoclose",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:ticket-autoclose",{children:[
{key:"enableInactiveHours",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-autoclose-enable-hours",{})},
{key:"inactiveHours",optional:false,priority:0,checker:new api.ODCheckerNumberStructure("openticket:ticket-autoclose-hours",{zeroAllowed:false,negativeAllowed:false,floatAllowed:true,min:1,max:8544})},
{key:"enableUserLeave",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-autoclose-enable-leave",{})},
{key:"disableOnClaim",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-autoclose-disable-claim",{})},
]})},
//AUTODELETE
{key:"autodelete",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:ticket-autodelete",{children:[
{key:"enableInactiveDays",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-autodelete-enable-days",{})},
{key:"inactiveDays",optional:false,priority:0,checker:new api.ODCheckerNumberStructure("openticket:ticket-autodelete-days",{zeroAllowed:false,negativeAllowed:false,floatAllowed:true,min:1,max:356})},
{key:"enableUserLeave",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-autodelete-enable-leave",{})},
{key:"disableOnClaim",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:ticket-autodelete-disable-claim",{})},
]})},
//COOLDOWN
{key:"cooldown",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:ticket-cooldown",{property:"enabled",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:ticket-cooldown",{children:[
{key:"cooldownMinutes",optional:false,priority:0,checker:new api.ODCheckerNumberStructure("openticket:ticket-cooldown-minutes",{zeroAllowed:false,negativeAllowed:false,floatAllowed:false,min:1,max:512640})},
]})})},
//LIMITS
{key:"limits",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:ticket-limits",{property:"enabled",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:ticket-limits",{children:[
{key:"globalMaximum",optional:false,priority:0,checker:new api.ODCheckerNumberStructure("openticket:ticket-limits-global",{zeroAllowed:false,negativeAllowed:false,floatAllowed:false,min:1})},
{key:"userMaximum",optional:false,priority:0,checker:new api.ODCheckerNumberStructure("openticket:ticket-limits-user",{zeroAllowed:false,negativeAllowed:false,floatAllowed:false,min:1})}
]})})},
]})},
//WEBSITE
{name:"website",priority:0,properties:[{key:"type",value:"website"}],checker:new api.ODCheckerObjectStructure("openticket:options-website",{children:[
{key:"id",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UniqueId("openticket:website-id","openticket","option-ids",{regex:/^[A-Za-z0-9-éèçàêâôûî]+$/,minLength:3,maxLength:40})},
{key:"name",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:website-name",{minLength:3,maxLength:50})},
{key:"description",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:website-description",{maxLength:256})},
//WEBSITE BUTTON
{key:"button",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:ticket-button",{children:[
{key:"emoji",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_EmojiString("openticket:ticket-button-emoji",0,1,true)},
{key:"label",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-button-label",{maxLength:50})},
],custom:(checker,value,locationTrace,locationId,locationDocs) => {
const lt = checker.locationTraceDeref(locationTrace)
//check if emoji & label exists
if (typeof value != "object") return false
else if (value && value["emoji"].length < 1 && value["label"].length < 1){
//label & emoji are both empty
checker.createMessage("openticket:invalid-button","error",`This button needs to have at least an "emoji" or "label"!`,lt,null,[`"emoji"`,`"label"`],locationId,locationDocs)
return false
}else return true
}})},
//WEBSITE URL
{key:"url",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UrlString("openticket:website-url",false,{allowHttp:false})},
]})},
//REACTION ROLES
{name:"role",priority:0,properties:[{key:"type",value:"role"}],checker:new api.ODCheckerObjectStructure("openticket:options-role",{children:[
{key:"id",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UniqueId("openticket:role-id","openticket","option-ids",{regex:/^[A-Za-z0-9-éèçàêâôûî]+$/,minLength:3,maxLength:40})},
{key:"name",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:role-name",{minLength:3,maxLength:50})},
{key:"description",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:role-description",{maxLength:256})},
//ROLE BUTTON
{key:"button",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:ticket-button",{children:[
{key:"emoji",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_EmojiString("openticket:ticket-button-emoji",0,1,true)},
{key:"label",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-button-label",{maxLength:50})},
{key:"color",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:ticket-button-color",{choices:["gray","red","green","blue"]})},
],custom:(checker,value,locationTrace,locationId,locationDocs) => {
const lt = checker.locationTraceDeref(locationTrace)
//check if emoji & label exists
if (typeof value != "object") return false
else if (value && value["emoji"].length < 1 && value["label"].length < 1){
//label & emoji are both empty
checker.createMessage("openticket:invalid-button","error",`This button needs to have at least an "emoji" or "label"!`,lt,null,[`"emoji"`,`"label"`],locationId,locationDocs)
return false
}else return true
}})},
//ROLE SETTINGS
{key:"roles",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordIdArray("openticket:role-roles","role",[],{allowDoubles:false,minLength:1})},
{key:"mode",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:role-mode",{choices:["add","remove","add&remove"]})},
{key:"removeRolesOnAdd",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordIdArray("openticket:role-remove-roles","role",[],{allowDoubles:false})},
{key:"addOnMemberJoin",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:role-add-on-join",{})},
]})},
]})})
export const defaultPanelsStructure = new api.ODCheckerArrayStructure("openticket:panels",{allowedTypes:["object"],propertyChecker:new api.ODCheckerObjectStructure("openticket:panels",{children:[
{key:"id",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UniqueId("openticket:panel-id","openticket","panel-ids",{regex:/^[A-Za-z0-9-éèçàêâôûî]+$/,minLength:3,maxLength:40})},
{key:"name",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:panel-name",{minLength:3,maxLength:50})},
{key:"dropdown",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:panel-dropdown",{})},
{key:"options",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UniqueIdArray("openticket:panel-options","openticket","option-ids","option-ids-used",{allowDoubles:false,maxLength:25})},
//EMBED & TEXT
{key:"text",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:panel-text",{maxLength:4096})},
{key:"embed",optional:false,priority:0,checker:createPanelEmbedStructure("openticket:panel-embed")},
//SETTINGS
{key:"settings",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:panel-settings",{children:[
{key:"dropdownPlaceholder",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:panel-settings-placeholder",{maxLength:100})},
{key:"enableMaxTicketsWarningInText",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:panel-settings-maxtickets-text",{})},
{key:"enableMaxTicketsWarningInEmbed",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:panel-settings-maxtickets-embed",{})},
{key:"describeOptionsLayout",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:panel-settings-describe-layout",{choices:["simple","normal","detailed"]})},
{key:"describeOptionsCustomTitle",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:panel-settings-describe-title",{maxLength:512})},
{key:"describeOptionsInText",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:panel-settings-describe-text",{})},
{key:"describeOptionsInEmbedFields",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:panel-settings-describe-fields",{})},
{key:"describeOptionsInEmbedDescription",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:panel-settings-describe-embed",{})},
]})},
]})})
export const defaultQuestionsStructure = new api.ODCheckerArrayStructure("openticket:questions",{allowedTypes:["object"],propertyChecker:new api.ODCheckerObjectStructure("openticket:questions",{children:[
{key:"id",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UniqueId("openticket:question-id","openticket","question-ids",{regex:/^[A-Za-z0-9-éèçàêâôûî]+$/,minLength:3,maxLength:40})},
{key:"name",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:question-name",{minLength:3,maxLength:50})},
{key:"type",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:question-type",{choices:["short","paragraph"]})},
{key:"required",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:question-required",{})},
{key:"placeholder",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:question-placeholder",{maxLength:100})},
{key:"length",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:question-length",{property:"enabled",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:question-length",{children:[
{key:"min",optional:false,priority:0,checker:new api.ODCheckerNumberStructure("openticket:question-length-min",{min:0,max:1024,negativeAllowed:false,floatAllowed:false})},
{key:"max",optional:false,priority:0,checker:new api.ODCheckerNumberStructure("openticket:question-length-max",{min:1,max:1024,negativeAllowed:false,floatAllowed:false})},
]})})},
]})})
export const defaultTranscriptsStructure = new api.ODCheckerObjectStructure("openticket:transcripts",{children:[
//GENERAL
{key:"general",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:transcripts-general",{property:"enabled",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:transcripts-general",{children:[
{key:"enableChannel",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-enable-channel",{})},
{key:"enableCreatorDM",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-enable-creator-dm",{})},
{key:"enableParticipantDM",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-enable-participant-dm",{})},
{key:"enableActiveAdminDM",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-enable-active-admin-dm",{})},
{key:"enableEveryAdminDM",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-enable-every-admin-dm",{})},
{key:"channel",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordId("openticket:transcripts-channel","channel",true,[])},
{key:"mode",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:transcripts-mode",{choices:["html","text"]})},
]})})},
//EMBED SETTINGS
{key:"embedSettings",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:transcripts-embed-settings",{children:[
{key:"customColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:transcripts-embed-color",false,true)},
{key:"listAllParticipants",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-embed-list-participants",{})},
{key:"includeTicketStats",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-embed-include-ticket-stats",{})},
]})},
//TEXT STYLE
{key:"textTranscriptStyle",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:transcripts-text",{children:[
{key:"layout",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:transcripts-text-layout",{choices:["simple","normal","detailed"]})},
{key:"includeStats",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-text-include-stats",{})},
{key:"includeIds",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-text-include-ids",{})},
{key:"includeEmbeds",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-text-include-embeds",{})},
{key:"includeFiles",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-text-include-files",{})},
{key:"includeBotMessages",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:transcripts-text-include-bots",{})},
{key:"fileMode",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:transcripts-text-file-mode",{choices:["custom","name","id"]})},
{key:"customFileName",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:transcripts-file-name",{maxLength:512,regex:/^[^\.#%&{}\\<>*?/!'":@`|=]*$/})},
]})},
//HTML STYLE
{key:"htmlTranscriptStyle",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:transcripts-html",{children:[
//HTML BACKGROUND
{key:"background",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:transcripts-html-background",{property:"enableCustomBackground",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:transcripts-html-background",{children:[
{key:"backgroundColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:transcripts-html-background-color",false,true)},
{key:"backgroundImage",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UrlString("openticket:transcripts-html-background-image",true,{allowHttp:false,allowedExtensions:[".png",".jpg",".jpeg",".webp",".gif"]})},
]})})},
//HTML HEADER
{key:"header",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:transcripts-html-header",{property:"enableCustomHeader",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:transcripts-html-header",{children:[
{key:"backgroundColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:transcripts-html-header-bgcolor",false,false)},
{key:"decoColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:transcripts-html-header-decocolor",false,false)},
{key:"textColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:transcripts-html-header-textcolor",false,false)},
]})})},
//HTML STATS
{key:"stats",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:transcripts-html-stats",{property:"enableCustomStats",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:transcripts-html-stats",{children:[
{key:"backgroundColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:transcripts-html-stats-bgcolor",false,false)},
{key:"keyTextColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:transcripts-html-stats-keycolor",false,false)},
{key:"valueTextColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:transcripts-html-stats-valuecolor",false,false)},
{key:"hideBackgroundColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:transcripts-html-stats-hidebgcolor",false,false)},
{key:"hideTextColor",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_HexColor("openticket:transcripts-html-stats-hidecolor",false,false)},
]})})},
//HTML FAVICON
{key:"favicon",optional:false,priority:0,checker:new api.ODCheckerEnabledObjectStructure("openticket:transcripts-html-favicon",{property:"enableCustomFavicon",enabledValue:true,checker:new api.ODCheckerObjectStructure("openticket:transcripts-html-favicon",{children:[
{key:"imageUrl",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UrlString("openticket:transcripts-html-favicon-image",true,{allowHttp:false,allowedExtensions:[".png",".jpg",".jpeg",".webp"]})},
]})})},
]})},
]})
export const defaultUnusedOptionsFunction = (manager:api.ODCheckerManager, functions:api.ODCheckerFunctionManager): api.ODCheckerResult => {
const optionList: string[] = manager.storage.get("openticket","option-ids")
const usedOptionList: string[] = manager.storage.get("openticket","option-ids-used")
if (!optionList || ! usedOptionList) return {valid:true,messages:[]}
const optionChecker = manager.get("openticket:options")
if (!optionChecker) return {valid:true,messages:[]}
const final: api.ODCheckerMessage[] = []
optionList.forEach((id) => {
if (!usedOptionList.includes(id)){
//id isn't used anywhere => create warning
final.push(functions.createMessage("openticket:options","openticket:unused-option",optionChecker.config.file,"warning",`The option "${id}" isn't used anywhere!`,[],null,[`"${id}"`],new api.ODId("openticket:unused-options"),null))
}
})
return {valid:true,messages:final}
}
export const defaultUnusedQuestionsFunction = (manager:api.ODCheckerManager, functions:api.ODCheckerFunctionManager): api.ODCheckerResult => {
const questionList: string[] = manager.storage.get("openticket","question-ids")
const usedQuestionList: string[] = manager.storage.get("openticket","question-ids-used")
if (!questionList || ! usedQuestionList) return {valid:true,messages:[]}
const questionChecker = manager.get("openticket:questions")
if (!questionChecker) return {valid:true,messages:[]}
const final: api.ODCheckerMessage[] = []
questionList.forEach((id) => {
if (!usedQuestionList.includes(id)){
//id isn't used anywhere => create warning
final.push(functions.createMessage("openticket:questions","openticket:unused-question",questionChecker.config.file,"warning",`The question "${id}" isn't used anywhere!`,[],null,[`"${id}"`],new api.ODId("openticket:unused-questions"),null))
}
})
return {valid:true,messages:final}
}
export const defaultDropdownOptionsFunction = (manager:api.ODCheckerManager, functions:api.ODCheckerFunctionManager): api.ODCheckerResult => {
const panelList: string[] = manager.storage.get("openticket","panel-ids")
if (!panelList) return {valid:true,messages:[]}
const panelConfig = openticket.configs.get("openticket:panels")
if (!panelConfig) return {valid:true,messages:[]}
const optionConfig = openticket.configs.get("openticket:options")
if (!optionConfig) return {valid:true,messages:[]}
const final: api.ODCheckerMessage[] = []
panelList.forEach((id,index) => {
const panel = panelConfig.data.find((panel) => panel.id == id)
if (!panel || !panel.dropdown) return false
if (panel.options.some((optId) => {
const option = optionConfig.data.find((option) => option.id == optId)
if (!option) return false
if (option.type != "ticket") return true
else return false
})){
//give error when non-ticket options exist in dropdown panel!
final.push(functions.createMessage("openticket:panels","openticket:dropdown-option",panelConfig.file,"error","A panel with dropdown enabled can only contain options of the 'ticket' type!",[index,"options"],null,[],new api.ODId("openticket:dropdown-options"),null))
}
})
return {valid:(final.length < 1),messages:final}
}
+481
View File
@@ -0,0 +1,481 @@
import {openticket, api, utilities} from "../../index"
import * as discord from "discord.js"
const generalConfig = openticket.configs.get("openticket:general")
const globalDatabase = openticket.databases.get("openticket:global")
const userDatabase = openticket.databases.get("openticket:users")
const ticketDatabase = openticket.databases.get("openticket:tickets")
const statsDatabase = openticket.databases.get("openticket:stats")
const optionDatabase = openticket.databases.get("openticket:options")
const mainServer = openticket.client.mainServer
export const loadAllCode = async () => {
if (!generalConfig || !mainServer || !globalDatabase || !userDatabase || !ticketDatabase || !statsDatabase || !optionDatabase) return
loadCommandErrorHandlingCode()
loadStartListeningInteractionsCode()
loadDatabaseCleanersCode()
loadPanelAutoUpdateCode()
loadDatabaseSaversCode()
loadAutoCode()
}
export const loadCommandErrorHandlingCode = async () => {
//COMMAND ERROR HANDLING
openticket.code.add(new api.ODCode("openticket:command-error-handling",14,() => {
//invalid/missing options
openticket.client.textCommands.onError(async (error) => {
if (error.type == "invalid_option"){
error.msg.channel.send((await openticket.builders.messages.getSafe("openticket:error-option-invalid").build("text",{guild:error.msg.guild,channel:error.msg.channel,user:error.msg.author,error})).message)
}else if (error.type == "missing_option"){
error.msg.channel.send((await openticket.builders.messages.getSafe("openticket:error-option-missing").build("text",{guild:error.msg.guild,channel:error.msg.channel,user:error.msg.author,error})).message)
}else if (error.type == "unknown_command" && generalConfig.data.system.sendErrorOnUnknownCommand){
error.msg.channel.send((await openticket.builders.messages.getSafe("openticket:error-unknown-command").build("text",{guild:error.msg.guild,channel:error.msg.channel,user:error.msg.author,error})).message)
}
})
//responder timeout
openticket.responders.commands.setTimeoutErrorCallback(async (instance,source) => {
instance.reply(await openticket.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
},null)
openticket.responders.buttons.setTimeoutErrorCallback(async (instance,source) => {
instance.reply(await openticket.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
},null)
openticket.responders.dropdowns.setTimeoutErrorCallback(async (instance,source) => {
instance.reply(await openticket.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
},null)
openticket.responders.modals.setTimeoutErrorCallback(async (instance,source) => {
if (!instance.channel){
instance.reply({id:new api.ODId("looks-like-we-got-an-error-here"), ephemeral:true, message:{
content:":x: **Something went wrong while replying to this modal!**"
}})
return
}
instance.reply(await openticket.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
},null)
}))
}
export const loadStartListeningInteractionsCode = async () => {
//START LISTENING TO INTERACTIONS
openticket.code.add(new api.ODCode("openticket:start-listening-interactions",13,() => {
openticket.client.slashCommands.startListeningToInteractions()
openticket.client.textCommands.startListeningToInteractions()
}))
}
export const loadDatabaseCleanersCode = async () => {
if (!mainServer) return
//PANEL DATABASE CLEANER
openticket.code.add(new api.ODCode("openticket:panel-database-cleaner",12,async () => {
const validPanels: string[] = []
//check global database for valid panel embeds
for (const panel of (globalDatabase.getCategory("openticket:panel-update") ?? [])){
if (!validPanels.includes(panel.key)){
try{
const splittedId = panel.key.split("_")
const message = await openticket.client.fetchGuildChannelMessage(mainServer,splittedId[0],splittedId[1])
if (message) validPanels.push(panel.key)
}catch{}
}
}
//remove all unused panels
for (const panel of (globalDatabase.getCategory("openticket:panel-update") ?? [])){
if (!validPanels.includes(panel.key)){
globalDatabase.delete("openticket:panel-update",panel.key)
}
}
//delete panel from database on delete
openticket.client.client.on("messageDelete",(msg) => {
if (globalDatabase.exists("openticket:panel-update",msg.channel.id+"_"+msg.id)){
globalDatabase.delete("openticket:panel-update",msg.channel.id+"_"+msg.id)
}
})
}))
//SUFFIX DATABASE CLEANER
openticket.code.add(new api.ODCode("openticket:suffix-database-cleaner",11,async () => {
const validSuffixCounters: string[] = []
const validSuffixHistories: string[] = []
//check global database for valid option suffix counters
for (const counter of (globalDatabase.getCategory("openticket:option-suffix-counter") ?? [])){
if (!validSuffixCounters.includes(counter.key)){
if (openticket.options.exists(counter.key)) validSuffixCounters.push(counter.key)
}
}
//check global database for valid option suffix histories
for (const history of (globalDatabase.getCategory("openticket:option-suffix-history") ?? [])){
if (!validSuffixHistories.includes(history.key)){
if (openticket.options.exists(history.key)) validSuffixHistories.push(history.key)
}
}
//remove all unused suffix counters
for (const counter of (globalDatabase.getCategory("openticket:option-suffix-counter") ?? [])){
if (!validSuffixCounters.includes(counter.key)){
globalDatabase.delete("openticket:option-suffix-counter",counter.key)
}
}
//remove all unused suffix histories
for (const history of (globalDatabase.getCategory("openticket:option-suffix-history") ?? [])){
if (!validSuffixHistories.includes(history.key)){
globalDatabase.delete("openticket:option-suffix-history",history.key)
}
}
}))
//OPTION DATABASE CLEANER
openticket.code.add(new api.ODCode("openticket:option-database-cleaner",10,() => {
//delete all unused options
openticket.options.getAll().forEach((option) => {
if (optionDatabase.exists("openticket:used-option",option.id.value) && !openticket.tickets.getAll().some((ticket) => ticket.option.id.value == option.id.value)){
optionDatabase.delete("openticket:used-option",option.id.value)
}
})
}))
//USER DATABASE CLEANER (full async/parallel because it takes a lot of time)
openticket.code.add(new api.ODCode("openticket:user-database-cleaner",9,() => {
utilities.runAsync(async () => {
const validUsers: string[] = []
//check user database for valid users
for (const user of userDatabase.getAll()){
if (!validUsers.includes(user.key)){
try{
const member = await mainServer.members.fetch(user.key)
if (member) validUsers.push(member.id)
}catch{}
}
}
//check stats database for valid users
for (const stat of statsDatabase.getAll()){
if (stat.category.startsWith("openticket:user_")){
if (!validUsers.includes(stat.key)){
try{
const member = await mainServer.members.fetch(stat.key)
if (member) validUsers.push(member.id)
}catch{}
}
}
}
//remove all unused users
for (const user of userDatabase.getAll()){
if (!validUsers.includes(user.key)){
userDatabase.delete(user.category,user.key)
}
}
//remove all unused stats
for (const stat of statsDatabase.getAll()){
if (stat.category.startsWith("openticket:user_")){
if (!validUsers.includes(stat.key)){
statsDatabase.delete(stat.category,stat.key)
}
}
}
})
//delete user from database on leave
openticket.client.client.on("guildMemberRemove",(member) => {
if (member.guild.id != mainServer.id) return
//remove unused user
for (const user of userDatabase.getAll()){
if (user.key == member.id){
userDatabase.delete(user.category,user.key)
}
}
//remove unused stats
for (const stat of statsDatabase.getAll()){
if (stat.category.startsWith("openticket:user_")){
if (stat.key == member.id){
statsDatabase.delete(stat.category,stat.key)
}
}
}
})
}))
//TICKET DATABASE CLEANER
openticket.code.add(new api.ODCode("openticket:ticket-database-cleaner",8,async () => {
const validTickets: string[] = []
//check ticket database for valid tickets
for (const ticket of ticketDatabase.getAll()){
if (!validTickets.includes(ticket.key)){
try{
const channel = await openticket.client.fetchGuildTextChannel(mainServer,ticket.key)
if (channel) validTickets.push(channel.id)
}catch{}
}
}
//check stats database for valid tickets
for (const stat of statsDatabase.getAll()){
if (stat.category.startsWith("openticket:ticket_")){
if (!validTickets.includes(stat.key)){
try{
const channel = await openticket.client.fetchGuildTextChannel(mainServer,stat.key)
if (channel) validTickets.push(channel.id)
}catch{}
}
}
}
//remove all unused tickets
for (const ticket of ticketDatabase.getAll()){
if (!validTickets.includes(ticket.key)){
ticketDatabase.delete(ticket.category,ticket.key)
openticket.tickets.remove(ticket.key)
}
}
//remove all unused stats
for (const stat of statsDatabase.getAll()){
if (stat.category.startsWith("openticket:ticket_")){
if (!validTickets.includes(stat.key)){
statsDatabase.delete(stat.category,stat.key)
}
}
}
//delete ticket from database on delete
openticket.client.client.on("channelDelete",(channel) => {
if (channel.isDMBased() || channel.guild.id != mainServer.id) return
//remove unused ticket
for (const ticket of ticketDatabase.getAll()){
if (ticket.key == channel.id){
ticketDatabase.delete(ticket.category,ticket.key)
openticket.tickets.remove(ticket.key)
}
}
//remove unused stats
for (const stat of statsDatabase.getAll()){
if (stat.category.startsWith("openticket:ticket_")){
if (stat.key == channel.id){
statsDatabase.delete(stat.category,stat.key)
}
}
}
})
}))
}
export const loadPanelAutoUpdateCode = async () => {
//PANEL AUTO UPDATE
openticket.code.add(new api.ODCode("openticket:panel-auto-update",7,async () => {
const globalDatabase = openticket.databases.get("openticket:global")
const panelIds = globalDatabase.getCategory("openticket:panel-update") ?? []
if (!mainServer) return
for (const panelId of panelIds){
const panel = openticket.panels.get(panelId.value)
//panel doesn't exist anymore in config and needs to be removed
if (!panel){
globalDatabase.delete("openticket:panel-update",panelId.key)
return
}
try{
const splittedId = panelId.key.split("_")
const channel = await openticket.client.fetchGuildTextChannel(mainServer,splittedId[0])
if (!channel) return
const message = await openticket.client.fetchGuildChannelMessage(mainServer,channel,splittedId[1])
if (!message) return
message.edit((await openticket.builders.messages.getSafe("openticket:panel").build("auto-update",{guild:mainServer,channel,user:openticket.client.client.user,panel})).message)
openticket.log("Panel in server got auto-updated!","info",[
{key:"channelid",value:splittedId[0]},
{key:"messageid",value:splittedId[1]},
{key:"panel",value:panelId.value}
])
}catch{}
}
}))
}
export const loadDatabaseSaversCode = async () => {
//TICKET SAVER
openticket.code.add(new api.ODCode("openticket:ticket-saver",6,() => {
const mainVersion = openticket.versions.get("openticket:version")
openticket.tickets.onAdd((ticket) => {
ticketDatabase.set("openticket:ticket",ticket.id.value,ticket.toJson(mainVersion))
//add option to database if non-existent
if (!optionDatabase.exists("openticket:used-option",ticket.option.id.value)){
optionDatabase.set("openticket:used-option",ticket.option.id.value,ticket.option.toJson(mainVersion))
}
})
openticket.tickets.onChange((ticket) => {
ticketDatabase.set("openticket:ticket",ticket.id.value,ticket.toJson(mainVersion))
//add option to database if non-existent
if (!optionDatabase.exists("openticket:used-option",ticket.option.id.value)){
optionDatabase.set("openticket:used-option",ticket.option.id.value,ticket.option.toJson(mainVersion))
}
//delete all unused options on ticket move
openticket.options.getAll().forEach((option) => {
if (optionDatabase.exists("openticket:used-option",option.id.value) && !openticket.tickets.getAll().some((ticket) => ticket.option.id.value == option.id.value)){
optionDatabase.delete("openticket:used-option",option.id.value)
}
})
})
openticket.tickets.onRemove((ticket) => {
ticketDatabase.delete("openticket:ticket",ticket.id.value)
//remove option from database if unused
if (!openticket.tickets.getAll().some((ticket) => ticket.option.id.value == ticket.option.id.value)){
optionDatabase.delete("openticket:used-option",ticket.option.id.value)
}
})
}))
//BLACKLIST SAVER
openticket.code.add(new api.ODCode("openticket:blacklist-saver",5,() => {
openticket.blacklist.onAdd((blacklist) => {
userDatabase.set("openticket:blacklist",blacklist.id.value,blacklist.reason)
})
openticket.blacklist.onChange((blacklist) => {
userDatabase.set("openticket:blacklist",blacklist.id.value,blacklist.reason)
})
openticket.blacklist.onRemove((blacklist) => {
userDatabase.delete("openticket:blacklist",blacklist.id.value)
})
}))
//AUTO ROLE ON JOIN
openticket.code.add(new api.ODCode("openticket:auto-role-on-join",4,() => {
openticket.client.client.on("guildMemberAdd",async (member) => {
for (const option of openticket.options.getAll()){
if (option instanceof api.ODRoleOption && option.get("openticket:add-on-join").value){
//add these roles on user join
await openticket.actions.get("openticket:reaction-role").run("panel-button",{guild:member.guild,user:member.user,option,overwriteMode:"add"})
}
}
})
}))
}
const loadAutoCode = () => {
//AUTOCLOSE TIMEOUT
openticket.code.add(new api.ODCode("openticket:autoclose-timeout",3,() => {
setInterval(async () => {
let count = 0
for (const ticket of openticket.tickets.getAll()){
const channel = await openticket.tickets.getTicketChannel(ticket)
if (!channel) return
const lastMessage = (await channel.messages.fetch({limit:5})).first()
if (lastMessage && !ticket.get("openticket:closed").value){
//ticket has last message
const disableOnClaim = ticket.option.get("openticket:autoclose-disable-claim").value && ticket.get("openticket:claimed").value
const enabled = (disableOnClaim) ? false : ticket.get("openticket:autoclose-enabled").value
const hours = ticket.get("openticket:autoclose-hours").value
const time = hours*60*60*1000 //hours in milliseconds
if (enabled && (new Date().getTime() - lastMessage.createdTimestamp) >= time){
//autoclose ticket
await openticket.actions.get("openticket:close-ticket").run("autoclose",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autoclose",sendMessage:false})
await channel.send((await openticket.builders.messages.getSafe("openticket:autoclose-message").build("timeout",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message)
count++
openticket.stats.get("openticket:global").setStat("openticket:tickets-autoclosed",1,"increase")
}
}
}
openticket.log("Finished autoclose timeout cycle!","system",[
{key:"interval",value:openticket.defaults.getDefault("autocloseCheckInterval").toString(),hidden:true},
{key:"closed",value:count.toString()}
])
},openticket.defaults.getDefault("autocloseCheckInterval"))
}))
//AUTOCLOSE LEAVE
openticket.code.add(new api.ODCode("openticket:autoclose-leave",2,() => {
openticket.client.client.on("guildMemberRemove",async (member) => {
for (const ticket of openticket.tickets.getAll()){
if (ticket.get("openticket:opened-by").value == member.id){
const channel = await openticket.tickets.getTicketChannel(ticket)
if (!channel) return
//ticket has been created by this user
const disableOnClaim = ticket.option.get("openticket:autoclose-disable-claim").value && ticket.get("openticket:claimed").value
const enabled = (disableOnClaim || !ticket.get("openticket:autoclose-enabled").value) ? false : ticket.option.get("openticket:autoclose-enable-leave")
if (enabled){
//autoclose ticket
await openticket.actions.get("openticket:close-ticket").run("autoclose",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autoclose",sendMessage:false})
await channel.send((await openticket.builders.messages.getSafe("openticket:autoclose-message").build("leave",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message)
openticket.stats.get("openticket:global").setStat("openticket:tickets-autoclosed",1,"increase")
}
}
}
})
}))
//AUTODELETE TIMEOUT
openticket.code.add(new api.ODCode("openticket:autodelete-timeout",1,() => {
setInterval(async () => {
let count = 0
for (const ticket of openticket.tickets.getAll()){
const channel = await openticket.tickets.getTicketChannel(ticket)
if (!channel) return
const lastMessage = (await channel.messages.fetch({limit:5})).first()
if (lastMessage){
//ticket has last message
const disableOnClaim = ticket.option.get("openticket:autodelete-disable-claim").value && ticket.get("openticket:claimed").value
const enabled = (disableOnClaim) ? false : ticket.get("openticket:autodelete-enabled").value
const days = ticket.get("openticket:autodelete-days").value
const time = days*24*60*60*1000 //days in milliseconds
if (enabled && (new Date().getTime() - lastMessage.createdTimestamp) >= time){
//autodelete ticket
await channel.send((await openticket.builders.messages.getSafe("openticket:autodelete-message").build("timeout",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message)
await openticket.actions.get("openticket:delete-ticket").run("autodelete",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autodelete",sendMessage:false,withoutTranscript:false})
count++
openticket.stats.get("openticket:global").setStat("openticket:tickets-autodeleted",1,"increase")
}
}
}
openticket.log("Finished autodelete timeout cycle!","system",[
{key:"interval",value:openticket.defaults.getDefault("autodeleteCheckInterval").toString(),hidden:true},
{key:"deleted",value:count.toString()}
])
},openticket.defaults.getDefault("autodeleteCheckInterval"))
}))
//AUTODELETE LEAVE
openticket.code.add(new api.ODCode("openticket:autodelete-leave",0,() => {
openticket.client.client.on("guildMemberRemove",async (member) => {
for (const ticket of openticket.tickets.getAll()){
if (ticket.get("openticket:opened-by").value == member.id){
const channel = await openticket.tickets.getTicketChannel(ticket)
if (!channel) return
//ticket has been created by this user
const disableOnClaim = ticket.option.get("openticket:autodelete-disable-claim").value && ticket.get("openticket:claimed").value
const enabled = (disableOnClaim || !ticket.get("openticket:autodelete-enabled").value) ? false : ticket.option.get("openticket:autodelete-enable-leave")
if (enabled){
//autodelete ticket
await channel.send((await openticket.builders.messages.getSafe("openticket:autodelete-message").build("leave",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message)
await openticket.actions.get("openticket:delete-ticket").run("autodelete",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autodelete",sendMessage:false,withoutTranscript:false})
openticket.stats.get("openticket:global").setStat("openticket:tickets-autodeleted",1,"increase")
}
}
}
})
}))
}
File diff suppressed because it is too large Load Diff
+12
View File
@@ -0,0 +1,12 @@
import {openticket, api, utilities} from "../../index"
export const loadAllConfigs = async () => {
const devconfigFlag = openticket.flags.get("openticket:dev-config")
const isDevconfig = devconfigFlag ? devconfigFlag.value : false
openticket.configs.add(new api.ODJsonConfig("openticket:general","general.json",(isDevconfig) ? "./devconfig/" : "./config/"))
openticket.configs.add(new api.ODJsonConfig("openticket:options","options.json",(isDevconfig) ? "./devconfig/" : "./config/"))
openticket.configs.add(new api.ODJsonConfig("openticket:panels","panels.json",(isDevconfig) ? "./devconfig/" : "./config/"))
openticket.configs.add(new api.ODJsonConfig("openticket:questions","questions.json",(isDevconfig) ? "./devconfig/" : "./config/"))
openticket.configs.add(new api.ODJsonConfig("openticket:transcripts","transcripts.json",(isDevconfig) ? "./devconfig/" : "./config/"))
}
+17
View File
@@ -0,0 +1,17 @@
import {openticket, api, utilities} from "../../index"
export const loadAllCooldowns = async () => {
openticket.options.getAll().forEach((option) => {
if (!(option instanceof api.ODTicketOption)) return
loadTicketOptionCooldown(option)
})
}
export const loadTicketOptionCooldown = (option:api.ODTicketOption) => {
if (option.get("openticket:cooldown-enabled").value){
//option has cooldown
const minutes = option.get("openticket:cooldown-minutes").value
const milliseconds = minutes*60000
openticket.cooldowns.add(new api.ODTimeoutCooldown("openticket:option-cooldown_"+option.id.value,milliseconds))
}
}
+53
View File
@@ -0,0 +1,53 @@
import {openticket, api, utilities} from "../../index"
import * as fjs from "formatted-json-stringify"
const devdatabaseFlag = openticket.flags.get("openticket:dev-database")
const isDevdatabase = devdatabaseFlag ? devdatabaseFlag.value : false
export const loadAllDatabases = async () => {
openticket.databases.add(defaultGlobalDatabase)
openticket.databases.add(defaultStatsDatabase)
openticket.databases.add(defaultTicketsDatabase)
openticket.databases.add(defaultUsersDatabase)
openticket.databases.add(defaultOptionsDatabase)
}
const defaultInlineFormatter = new fjs.ArrayFormatter(null,true,new fjs.ObjectFormatter(null,false,[
new fjs.PropertyFormatter("category"),
new fjs.PropertyFormatter("key"),
new fjs.DefaultFormatter("value",false)
]))
const defaultTicketFormatter = new fjs.ArrayFormatter(null,true,new fjs.ObjectFormatter(null,true,[
new fjs.PropertyFormatter("category"),
new fjs.PropertyFormatter("key"),
new fjs.ObjectFormatter("value",true,[
new fjs.PropertyFormatter("id"),
new fjs.PropertyFormatter("option"),
new fjs.PropertyFormatter("version"),
new fjs.ArrayFormatter("data",true,new fjs.ObjectFormatter(null,false,[
new fjs.PropertyFormatter("id"),
new fjs.DefaultFormatter("value",false)
]))
])
]))
const defaultOptionFormatter = new fjs.ArrayFormatter(null,true,new fjs.ObjectFormatter(null,true,[
new fjs.PropertyFormatter("category"),
new fjs.PropertyFormatter("key"),
new fjs.ObjectFormatter("value",true,[
new fjs.PropertyFormatter("id"),
new fjs.PropertyFormatter("type"),
new fjs.PropertyFormatter("version"),
new fjs.ArrayFormatter("data",true,new fjs.ObjectFormatter(null,false,[
new fjs.PropertyFormatter("id"),
new fjs.DefaultFormatter("value",false)
]))
])
]))
export const defaultGlobalDatabase = new api.ODFormattedJsonDatabase("openticket:global","global.json",defaultInlineFormatter,(isDevdatabase) ? "./devdatabase/" : "./database/")
export const defaultStatsDatabase = new api.ODFormattedJsonDatabase("openticket:stats","stats.json",defaultInlineFormatter,(isDevdatabase) ? "./devdatabase/" : "./database/")
export const defaultTicketsDatabase = new api.ODFormattedJsonDatabase("openticket:tickets","tickets.json",defaultTicketFormatter,(isDevdatabase) ? "./devdatabase/" : "./database/")
export const defaultUsersDatabase = new api.ODFormattedJsonDatabase("openticket:users","users.json",defaultInlineFormatter,(isDevdatabase) ? "./devdatabase/" : "./database/")
export const defaultOptionsDatabase = new api.ODFormattedJsonDatabase("openticket:options","options.json",defaultOptionFormatter,(isDevdatabase) ? "./devdatabase/" : "./database/")
+236
View File
@@ -0,0 +1,236 @@
import {openticket, api, utilities} from "../../index"
export const loadAllEvents = () => {
const eventList: (keyof api.ODEventIds_Default)[] = [
//error handling
"onErrorHandling",
"afterErrorHandling",
//plugins
"afterPluginsLoaded",
"onPluginClassLoad",
"afterPluginClassesLoaded",
"onPluginEventLoad",
"afterPluginEventsLoaded",
//flags
"onFlagLoad",
"afterFlagsLoaded",
"onFlagInit",
"afterFlagsInitiated",
//configs
"onConfigLoad",
"afterConfigsLoaded",
//databases
"onDatabaseLoad",
"afterDatabasesLoaded",
//languages
"onLanguageLoad",
"afterLanguagesLoaded",
"onLanguageSelect",
"afterLanguagesSelected",
//sessions
"onSessionLoad",
"afterSessionsLoaded",
//config checkers
"onCheckerLoad",
"afterCheckersLoaded",
"onCheckerFunctionLoad",
"afterCheckerFunctionsLoaded",
"onCheckerExecute",
"afterCheckersExecuted",
"onCheckerTranslationLoad",
"afterCheckerTranslationsLoaded",
"onCheckerRender",
"afterCheckersRendered",
"onCheckerQuit",
//client configuration
"onClientLoad",
"afterClientLoaded",
"onClientInit",
"afterClientInitiated",
"onClientReady",
"afterClientReady",
"onClientActivityLoad",
"afterClientActivityLoaded",
"onClientActivityInit",
"afterClientActivityInitiated",
//client slash commands
"onSlashCommandLoad",
"afterSlashCommandsLoaded",
"onSlashCommandRegister",
"afterSlashCommandsRegistered",
//client text commands
"onTextCommandLoad",
"afterTextCommandsLoaded",
//questions
"onQuestionLoad",
"afterQuestionsLoaded",
//options
"onOptionLoad",
"afterOptionsLoaded",
//panels
"onPanelLoad",
"afterPanelsLoaded",
"onPanelSpawn",
"afterPanelSpawned",
//tickets
"onTicketLoad",
"afterTicketsLoaded",
//ticket creation
"onTicketChannelCreation",
"afterTicketChannelCreated",
"onTicketChannelDeletion",
"afterTicketChannelDeleted",
"onTicketPermissionsCreated",
"afterTicketPermissionsCreated",
"onTicketMainMessageCreated",
"afterTicketMainMessageCreated",
//ticket actions
"onTicketCreate",
"afterTicketCreated",
"onTicketClose",
"afterTicketClosed",
"onTicketReopen",
"afterTicketReopened",
"onTicketDelete",
"afterTicketDeleted",
"onTicketMove",
"afterTicketMoved",
"onTicketClaim",
"afterTicketClaimed",
"onTicketUnclaim",
"afterTicketUnclaimed",
"onTicketPin",
"afterTicketPinned",
"onTicketUnpin",
"afterTicketUnpinned",
"onTicketUserAdd",
"afterTicketUserAdded",
"onTicketUserRemove",
"afterTicketUserRemoved",
"onTicketRename",
"afterTicketRenamed",
"onTicketsClear",
"afterTicketsCleared",
//roles
"onRoleLoad",
"afterRolesLoaded",
"onRoleUpdate",
"afterRolesUpdated",
//blacklist
"onBlacklistLoad",
"afterBlacklistLoaded",
//transcripts
"onTranscriptCompilerLoad",
"afterTranscriptCompilersLoaded",
"onTranscriptHistoryLoad",
"afterTranscriptHistoryLoaded",
//transcript creation
"onTranscriptCreate",
"afterTranscriptCreated",
"onTranscriptInit",
"afterTranscriptInitiated",
"onTranscriptCompile",
"afterTranscriptCompiled",
"onTranscriptReady",
"afterTranscriptReady",
//builders
"onButtonBuilderLoad",
"afterButtonBuildersLoaded",
"onDropdownBuilderLoad",
"afterDropdownBuildersLoaded",
"onFileBuilderLoad",
"afterFileBuildersLoaded",
"onEmbedBuilderLoad",
"afterEmbedBuildersLoaded",
"onMessageBuilderLoad",
"afterMessageBuildersLoaded",
"onModalBuilderLoad",
"afterModalBuildersLoaded",
//responders
"onCommandResponderLoad",
"afterCommandRespondersLoaded",
"onButtonResponderLoad",
"afterButtonRespondersLoaded",
"onDropdownResponderLoad",
"afterDropdownRespondersLoaded",
"onModalResponderLoad",
"afterModalRespondersLoaded",
//actions
"onActionLoad",
"afterActionsLoaded",
//verifybars
"onVerifyBarLoad",
"afterVerifyBarsLoaded",
//permissions
"onPermissionLoad",
"afterPermissionsLoaded",
//posts
"onPostLoad",
"afterPostsLoaded",
"onPostInit",
"afterPostsInitiated",
//cooldowns
"onCooldownLoad",
"afterCooldownsLoaded",
"onCooldownInit",
"afterCooldownsInitiated",
//help menu
"onHelpMenuCategoryLoad",
"afterHelpMenuCategoriesLoaded",
"onHelpMenuComponentLoad",
"afterHelpMenuComponentsLoaded",
//stats
"onStatScopeLoad",
"afterStatScopesLoaded",
"onStatLoad",
"afterStatsLoaded",
"onStatInit",
"afterStatsInitiated",
//code
"onCodeLoad",
"afterCodeLoaded",
"onCodeExecute",
"afterCodeExecuted",
//livestatus
"onLiveStatusSourceLoad",
"afterLiveStatusSourcesLoaded",
//startscreen
"onStartScreenLoad",
"afterStartScreensLoaded",
"onStartScreenRender",
"afterStartScreensRendered"
]
eventList.forEach((event) => openticket.events.add(new api.ODEvent(event)))
}
+16
View File
@@ -0,0 +1,16 @@
import {openticket, api, utilities} from "../../index"
export const loadAllFlags = async () => {
openticket.flags.add(new api.ODFlag("openticket:no-migration","No Migration","Disable Open Ticket data migration on update!","--no-migration",["-nm"]))
openticket.flags.add(new api.ODFlag("openticket:dev-config","Developer Config","Use the configs in /devconfig instead of /config!","--dev-config",["-dc"]))
openticket.flags.add(new api.ODFlag("openticket:dev-database","Developer Database","Use the databases in /devdatabase instead of /database!","--dev-database",["-nd"]))
openticket.flags.add(new api.ODFlag("openticket:debug","Debug Mode","Couldn't you find the error? Try to check this out!","--debug",["-d"]))
openticket.flags.add(new api.ODFlag("openticket:crash","Crash On Error","Crash the bot on an unknown error!","--crash",["-cr"]))
openticket.flags.add(new api.ODFlag("openticket:no-transcripts","No HTML Transcripts","Disable uploading HTML transcripts (for debugging)","--no-transcripts",["-nt"]))
openticket.flags.add(new api.ODFlag("openticket:no-checker","No Config Checker","Disable the Config Checker (for debugging)","--no-checker",["-nc"]))
openticket.flags.add(new api.ODFlag("openticket:checker","Full Config Checker","Render the Config Checker with extra details!","--checker",["-c"]))
openticket.flags.add(new api.ODFlag("openticket:no-easter","No Easter Eggs","Disable little Open Ticket easter eggs hidden in the bot!","--no-easter",["-ne"]))
openticket.flags.add(new api.ODFlag("openticket:no-plugins","No Plugins","Disable all Open Ticket plugins!","--no-plugins",["-np"]))
openticket.flags.add(new api.ODFlag("openticket:soft-plugins","Soft Plugins","Don't crash the bot when a plugin crashes!","--soft-plugins",["-sp"]))
openticket.flags.add(new api.ODFlag("openticket:force-slash-update","Force Slash Update","Force update all slash commands.","--force-slash",["-fs"]))
}
+263
View File
@@ -0,0 +1,263 @@
import {openticket, api, utilities} from "../../index"
const lang = openticket.languages
export const loadAllHelpMenuCategories = async () => {
const helpmenu = openticket.helpmenu
helpmenu.add(new api.ODHelpMenuCategory("openticket:general",5,utilities.emojiTitle("📎","General Commands"))) //TODO TRANSLATION!!!
helpmenu.add(new api.ODHelpMenuCategory("openticket:ticket-basic",4,utilities.emojiTitle("🎫","Basic Ticket Commands"))) //TODO TRANSLATION!!!
helpmenu.add(new api.ODHelpMenuCategory("openticket:ticket-advanced",4,utilities.emojiTitle("💡","Advanced Ticket Commands"))) //TODO TRANSLATION!!!
helpmenu.add(new api.ODHelpMenuCategory("openticket:ticket-user",3,utilities.emojiTitle("👤","User Ticket Commands"))) //TODO TRANSLATION!!!
helpmenu.add(new api.ODHelpMenuCategory("openticket:admin",2,utilities.emojiTitle("🚨","Admin Commands"))) //TODO TRANSLATION!!!
helpmenu.add(new api.ODHelpMenuCategory("openticket:advanced",1,utilities.emojiTitle("🚧","Advanced Commands"))) //TODO TRANSLATION!!!
helpmenu.add(new api.ODHelpMenuCategory("openticket:extra",0,utilities.emojiTitle("✨","Extra Commands"))) //TODO TRANSLATION!!!
}
export const loadAllHelpMenuComponents = async () => {
const helpmenu = openticket.helpmenu
const generalConfig = openticket.configs.get("openticket:general")
if (!generalConfig) return
const prefix = generalConfig.data.prefix
const enableDeleteWithoutTranscript = generalConfig.data.system.enableDeleteWithoutTranscript
const allowedCommands: string[] = []
for (const key in generalConfig.data.system.permissions){
if (generalConfig.data.system.permissions[key] != "none") allowedCommands.push(key)
}
const general = helpmenu.get("openticket:general")
if (general){
if (allowedCommands.includes("help")) general.add(new api.ODHelpMenuCommandComponent("openticket:help",1,{
textName:prefix+"help",
textDescription:lang.getTranslation("helpMenu.help"),
slashName:"/help",
slashDescription:lang.getTranslation("helpMenu.help")
}))
if (allowedCommands.includes("ticket")) general.add(new api.ODHelpMenuCommandComponent("openticket:ticket",0,{
slashName:"/ticket",
slashDescription:lang.getTranslation("commands.ticket"),
slashOptions:[{name:"id",optional:false}]
}))
}
const ticketBasic = helpmenu.get("openticket:ticket-basic")
if (ticketBasic){
if (allowedCommands.includes("close")) ticketBasic.add(new api.ODHelpMenuCommandComponent("openticket:close",10,{
textName:prefix+"close",
textDescription:lang.getTranslation("helpMenu.close"),
slashName:"/close",
slashDescription:lang.getTranslation("helpMenu.close"),
textOptions:[{name:"reason",optional:true}],
slashOptions:[{name:"reason",optional:true}]
}))
if (enableDeleteWithoutTranscript){
if (allowedCommands.includes("delete")) ticketBasic.add(new api.ODHelpMenuCommandComponent("openticket:delete",9,{
textName:prefix+"delete",
textDescription:lang.getTranslation("helpMenu.delete"),
slashName:"/delete",
slashDescription:lang.getTranslation("helpMenu.delete"),
textOptions:[{name:"reason",optional:true}],
slashOptions:[{name:"notranscript",optional:true},{name:"reason",optional:true}]
}))
}else{
if (allowedCommands.includes("delete")) ticketBasic.add(new api.ODHelpMenuCommandComponent("openticket:delete",9,{
textName:prefix+"delete",
textDescription:lang.getTranslation("helpMenu.delete"),
slashName:"/delete",
slashDescription:lang.getTranslation("helpMenu.delete"),
textOptions:[{name:"reason",optional:true}],
slashOptions:[{name:"reason",optional:true}]
}))
}
if (allowedCommands.includes("reopen")) ticketBasic.add(new api.ODHelpMenuCommandComponent("openticket:reopen",8,{
textName:prefix+"reopen",
textDescription:lang.getTranslation("helpMenu.reopen"),
slashName:"/reopen",
slashDescription:lang.getTranslation("helpMenu.reopen"),
textOptions:[{name:"reason",optional:true}],
slashOptions:[{name:"reason",optional:true}]
}))
}
const ticketAdvanced = helpmenu.get("openticket:ticket-advanced")
if (ticketAdvanced){
if (allowedCommands.includes("pin")) ticketAdvanced.add(new api.ODHelpMenuCommandComponent("openticket:pin",5,{
textName:prefix+"pin",
textDescription:lang.getTranslation("helpMenu.pin"),
slashName:"/pin",
slashDescription:lang.getTranslation("helpMenu.pin"),
textOptions:[{name:"reason",optional:true}],
slashOptions:[{name:"reason",optional:true}]
}))
if (allowedCommands.includes("unpin")) ticketAdvanced.add(new api.ODHelpMenuCommandComponent("openticket:unpin",4,{
textName:prefix+"unpin",
textDescription:lang.getTranslation("helpMenu.unpin"),
slashName:"/unpin",
slashDescription:lang.getTranslation("helpMenu.unpin"),
textOptions:[{name:"reason",optional:true}],
slashOptions:[{name:"reason",optional:true}]
}))
if (allowedCommands.includes("move")) ticketAdvanced.add(new api.ODHelpMenuCommandComponent("openticket:move",3,{
textName:prefix+"move",
textDescription:lang.getTranslation("helpMenu.move"),
slashName:"/move",
slashDescription:lang.getTranslation("helpMenu.move"),
textOptions:[{name:"id",optional:false},{name:"reason",optional:true}],
slashOptions:[{name:"id",optional:false},{name:"reason",optional:true}]
}))
if (allowedCommands.includes("rename")) ticketAdvanced.add(new api.ODHelpMenuCommandComponent("openticket:rename",2,{
textName:prefix+"rename",
textDescription:lang.getTranslation("helpMenu.rename"),
slashName:"/rename",
slashDescription:lang.getTranslation("helpMenu.rename"),
textOptions:[{name:"name",optional:false},{name:"reason",optional:true}],
slashOptions:[{name:"name",optional:false},{name:"reason",optional:true}]
}))
}
const ticketUser = helpmenu.get("openticket:ticket-channel")
if (ticketUser){
if (allowedCommands.includes("claim")) ticketUser.add(new api.ODHelpMenuCommandComponent("openticket:claim",7,{
textName:prefix+"claim",
textDescription:lang.getTranslation("helpMenu.claim"),
slashName:"/claim",
slashDescription:lang.getTranslation("helpMenu.claim"),
textOptions:[{name:"user",optional:true},{name:"reason",optional:true}],
slashOptions:[{name:"user",optional:true},{name:"reason",optional:true}]
}))
if (allowedCommands.includes("unclaim")) ticketUser.add(new api.ODHelpMenuCommandComponent("openticket:unclaim",6,{
textName:prefix+"unclaim",
textDescription:lang.getTranslation("helpMenu.unclaim"),
slashName:"/unclaim",
slashDescription:lang.getTranslation("helpMenu.unclaim"),
textOptions:[{name:"reason",optional:true}],
slashOptions:[{name:"reason",optional:true}]
}))
if (allowedCommands.includes("add")) ticketUser.add(new api.ODHelpMenuCommandComponent("openticket:add",1,{
textName:prefix+"add",
textDescription:lang.getTranslation("helpMenu.add"),
slashName:"/add",
slashDescription:lang.getTranslation("helpMenu.add"),
textOptions:[{name:"user",optional:false},{name:"reason",optional:true}],
slashOptions:[{name:"user",optional:false},{name:"reason",optional:true}]
}))
if (allowedCommands.includes("remove")) ticketUser.add(new api.ODHelpMenuCommandComponent("openticket:remove",0,{
textName:prefix+"remove",
textDescription:lang.getTranslation("helpMenu.remove"),
slashName:"/remove",
slashDescription:lang.getTranslation("helpMenu.remove"),
textOptions:[{name:"user",optional:false},{name:"reason",optional:true}],
slashOptions:[{name:"user",optional:false},{name:"reason",optional:true}]
}))
}
const admin = helpmenu.get("openticket:admin")
if (admin){
if (allowedCommands.includes("panel")) admin.add(new api.ODHelpMenuCommandComponent("openticket:panel",4,{
textName:prefix+"panel",
textDescription:lang.getTranslation("helpMenu.panel"),
slashName:"/panel",
slashDescription:lang.getTranslation("helpMenu.panel"),
textOptions:[{name:"id",optional:false}],
slashOptions:[{name:"id",optional:false}]
}))
if (allowedCommands.includes("blacklist")) admin.add(new api.ODHelpMenuCommandComponent("openticket:blacklist-view",3,{
textName:prefix+"blacklist view",
textDescription:lang.getTranslation("commands.blacklistView"),
slashName:"/blacklist view",
slashDescription:lang.getTranslation("commands.blacklistView")
}))
if (allowedCommands.includes("blacklist")) admin.add(new api.ODHelpMenuCommandComponent("openticket:blacklist-add",2,{
textName:prefix+"blacklist add",
textDescription:lang.getTranslation("commands.blacklistAdd"),
slashName:"/blacklist add",
slashDescription:lang.getTranslation("commands.blacklistAdd"),
textOptions:[{name:"user",optional:false},{name:"reason",optional:true}],
slashOptions:[{name:"user",optional:false},{name:"reason",optional:true}]
}))
if (allowedCommands.includes("blacklist")) admin.add(new api.ODHelpMenuCommandComponent("openticket:blacklist-remove",1,{
textName:prefix+"blacklist remove",
textDescription:lang.getTranslation("commands.blacklistRemove"),
slashName:"/blacklist remove",
slashDescription:lang.getTranslation("commands.blacklistRemove"),
textOptions:[{name:"user",optional:false},{name:"reason",optional:true}],
slashOptions:[{name:"user",optional:false},{name:"reason",optional:true}]
}))
if (allowedCommands.includes("blacklist")) admin.add(new api.ODHelpMenuCommandComponent("openticket:blacklist-get",0,{
textName:prefix+"blacklist get",
textDescription:lang.getTranslation("commands.blacklistGet"),
slashName:"/blacklist get",
slashDescription:lang.getTranslation("commands.blacklistGet"),
textOptions:[{name:"user",optional:false}],
slashOptions:[{name:"user",optional:false}]
}))
}
const advanced = helpmenu.get("openticket:advanced")
if (advanced){
if (allowedCommands.includes("stats")) advanced.add(new api.ODHelpMenuCommandComponent("openticket:stats-global",5,{
textName:prefix+"stats global",
textDescription:lang.getTranslation("commands.statsGlobal"),
slashName:"/stats global",
slashDescription:lang.getTranslation("commands.statsGlobal")
}))
if (allowedCommands.includes("stats")) advanced.add(new api.ODHelpMenuCommandComponent("openticket:stats-ticket",4,{
textName:prefix+"stats ticket",
textDescription:lang.getTranslation("commands.statsTicket"),
slashName:"/stats ticket",
slashDescription:lang.getTranslation("commands.statsTicket"),
textOptions:[{name:"ticket",optional:false}],
slashOptions:[{name:"ticket",optional:false}]
}))
if (allowedCommands.includes("stats")) advanced.add(new api.ODHelpMenuCommandComponent("openticket:stats-user",2,{
textName:prefix+"stats user",
textDescription:lang.getTranslation("commands.statsUser"),
slashName:"/stats user",
slashDescription:lang.getTranslation("commands.statsUser"),
textOptions:[{name:"user",optional:false}],
slashOptions:[{name:"user",optional:false}]
}))
if (allowedCommands.includes("stats")) advanced.add(new api.ODHelpMenuCommandComponent("openticket:stats-reset",2,{
textName:prefix+"stats reset",
textDescription:lang.getTranslation("commands.statsReset"),
slashName:"/stats reset",
slashDescription:lang.getTranslation("commands.statsReset"),
textOptions:[{name:"reason",optional:true}],
slashOptions:[{name:"reason",optional:true}]
}))
if (allowedCommands.includes("autoclose")) advanced.add(new api.ODHelpMenuCommandComponent("openticket:autoclose-disable",1,{
textName:prefix+"autoclose disable",
textDescription:lang.getTranslation("commands.autocloseDisable"),
slashName:"/autoclose disable",
slashDescription:lang.getTranslation("commands.autocloseDisable"),
textOptions:[{name:"reason",optional:true}],
slashOptions:[{name:"reason",optional:true}]
}))
if (allowedCommands.includes("autoclose")) advanced.add(new api.ODHelpMenuCommandComponent("openticket:autoclose-enable",0,{
textName:prefix+"autoclose enable",
textDescription:lang.getTranslation("commands.autocloseEnable"),
slashName:"/autoclose enable",
slashDescription:lang.getTranslation("commands.autocloseEnable"),
textOptions:[{name:"time",optional:false},{name:"reason",optional:true}],
slashOptions:[{name:"time",optional:false},{name:"reason",optional:true}]
}))
if (allowedCommands.includes("autodelete")) advanced.add(new api.ODHelpMenuCommandComponent("openticket:autodelete-disable",1,{
textName:prefix+"autodelete disable",
textDescription:lang.getTranslation("commands.autodeleteDisable"),
slashName:"/autodelete disable",
slashDescription:lang.getTranslation("commands.autodeleteDisable"),
textOptions:[{name:"reason",optional:true}],
slashOptions:[{name:"reason",optional:true}]
}))
if (allowedCommands.includes("autodelete")) advanced.add(new api.ODHelpMenuCommandComponent("openticket:autodelete-enable",0,{
textName:prefix+"autodelete enable",
textDescription:lang.getTranslation("commands.autodeleteEnable"),
slashName:"/autodelete enable",
slashDescription:lang.getTranslation("commands.autodeleteEnable"),
textOptions:[{name:"time",optional:false},{name:"reason",optional:true}],
slashOptions:[{name:"time",optional:false},{name:"reason",optional:true}]
}))
}
}
+15
View File
@@ -0,0 +1,15 @@
import {openticket, api, utilities} from "../../index"
export const loadAllLanguages = async () => {
openticket.languages.add(new api.ODLanguage("openticket:custom","custom.json"))
openticket.languages.add(new api.ODLanguage("openticket:english","english.json"))
openticket.languages.add(new api.ODLanguage("openticket:dutch","dutch.json"))
openticket.languages.add(new api.ODLanguage("openticket:portuguese","portuguese.json"))
openticket.languages.add(new api.ODLanguage("openticket:czech","czech.json"))
/** How to add more languages?
* - Add the language to the list above
* - Add the language to the "languageList" in the "ODDefaultsManager" class
* - Add the language to the list in the "ODLanguageManagerIds_Default" interface
*/
}
+6
View File
@@ -0,0 +1,6 @@
import {openticket, api, utilities} from "../../index"
export const loadAllLiveStatusSources = async () => {
//DEFAULT DJDJ DEV
openticket.livestatus.add(new api.ODLiveStatusUrlSource("openticket:default-djdj-dev","https://apis.dj-dj.be/status/openticket.json"))
}
+82
View File
@@ -0,0 +1,82 @@
import {openticket, api, utilities} from "../../index"
import * as discord from "discord.js"
export const loadAllPermissions = async () => {
const generalConfig = openticket.configs.get("openticket:general")
if (!generalConfig) return
const mainServer = openticket.client.mainServer
if (!mainServer) return
//DEVELOPER & OWNER
const developer = (await openticket.client.client.application.fetch()).owner
if (developer instanceof discord.User){
openticket.permissions.add(new api.ODPermission("openticket:developer-"+developer.id,"global-user","developer",developer))
}else if (developer instanceof discord.Team){
developer.members.forEach((member) => {
openticket.permissions.add(new api.ODPermission("openticket:developer-"+member.user.id,"global-user","developer",member.user))
})
}
const owner = (await mainServer.members.fetch(mainServer.ownerId)).user
openticket.permissions.add(new api.ODPermission("openticket:owner-"+owner.id,"global-user","owner",owner))
//GLOBAL ADMINS
generalConfig.data.globalAdmins.forEach(async (admin) => {
const role = await mainServer.roles.fetch(admin)
if (!role) return openticket.log("Unable to register permission for global admin!","error",[
{key:"roleid",value:admin}
])
openticket.permissions.add(new api.ODPermission("openticket:global-admin-"+admin,"global-role","admin",role))
})
//TICKET ADMINS
openticket.tickets.getAll().forEach(async (ticket) => {
try {
const channel = await openticket.client.fetchGuildTextChannel(mainServer,ticket.id.value)
if (!channel) return
const admins = ticket.option.exists("openticket:admins") ? ticket.option.get("openticket:admins").value : []
const readAdmins = ticket.option.exists("openticket:admins-readonly") ? ticket.option.get("openticket:admins-readonly").value : []
admins.concat(readAdmins).forEach(async (admin) => {
const role = await mainServer.roles.fetch(admin)
if (!role) return openticket.log("Unable to register permission for ticket admin!","error",[
{key:"roleid",value:admin}
])
openticket.permissions.add(new api.ODPermission("openticket:ticket-admin_"+ticket.id.value+"_"+admin,"channel-role","support",role,channel))
})
}catch(err){
process.emit("uncaughtException",err)
openticket.log("Ticket Admin Loading Permissions Error (see above)","error")
}
})
}
export const addTicketPermissions = async (ticket:api.ODTicket) => {
const mainServer = openticket.client.mainServer
if (!mainServer) return
const channel = await openticket.client.fetchGuildTextChannel(mainServer,ticket.id.value)
if (!channel) return
const admins = ticket.option.exists("openticket:admins") ? ticket.option.get("openticket:admins").value : []
const readAdmins = ticket.option.exists("openticket:admins-readonly") ? ticket.option.get("openticket:admins-readonly").value : []
admins.concat(readAdmins).forEach(async (admin) => {
const role = await mainServer.roles.fetch(admin)
if (!role) return openticket.log("Unable to register permission for ticket admin!","error",[
{key:"roleid",value:admin}
])
openticket.permissions.add(new api.ODPermission("openticket:ticket-admin_"+ticket.id.value+"_"+admin,"channel-role","support",role,channel))
})
}
export const removeTicketPermissions = async (ticket:api.ODTicket) => {
const admins = ticket.option.exists("openticket:admins") ? ticket.option.get("openticket:admins").value : []
const readAdmins = ticket.option.exists("openticket:admins-readonly") ? ticket.option.get("openticket:admins-readonly").value : []
admins.concat(readAdmins).forEach(async (admin) => {
openticket.permissions.remove("openticket:ticket-admin_"+ticket.id.value+"_"+admin)
})
}
+14
View File
@@ -0,0 +1,14 @@
import {openticket, api, utilities} from "../../index"
export const loadAllPosts = async () => {
const generalConfig = openticket.configs.get("openticket:general")
if (!generalConfig) return
const transcriptConfig = openticket.configs.get("openticket:transcripts")
if (!transcriptConfig) return
//LOGS CHANNEL
if (generalConfig.data.system.logs.enabled) openticket.posts.add(new api.ODPost("openticket:logs",generalConfig.data.system.logs.channel))
//TRANSCRIPTS CHANNEL
if (transcriptConfig.data.general.enabled && transcriptConfig.data.general.enableChannel) openticket.posts.add(new api.ODPost("openticket:transcripts",transcriptConfig.data.general.channel))
}
+54
View File
@@ -0,0 +1,54 @@
import {openticket, api, utilities} from "../../index"
import ansis from "ansis"
export const loadAllStartScreenComponents = async () => {
/**
"openticket:flags":ODStartScreenFlagsCategoryComponent,
"openticket:plugins":ODStartScreenPluginsCategoryComponent,
"openticket:livestatus":ODStartScreenLiveStatusCategoryComponent,
*/
//LOGO
openticket.startscreen.add(new api.ODStartScreenLogoComponent("openticket:logo",1000,[
" ██████╗ ██████╗ ███████╗███╗ ██╗ ████████╗██╗ ██████╗██╗ ██╗███████╗████████╗ ",
" ██╔═══██╗██╔══██╗██╔════╝████╗ ██║ ╚══██╔══╝██║██╔════╝██║ ██╔╝██╔════╝╚══██╔══╝ ",
" ██║ ██║██████╔╝█████╗ ██╔██╗ ██║ ██║ ██║██║ █████╔╝ █████╗ ██║ ",
" ██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║ ██║ ██║██║ ██╔═██╗ ██╔══╝ ██║ ",
" ╚██████╔╝██║ ███████╗██║ ╚████║ ██║ ██║╚██████╗██║ ██╗███████╗ ██║ ",
" ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═╝ "
],true,false))
//HEADER
const currentLanguageMetadata = openticket.languages.getLanguageMetadata()
openticket.startscreen.add(new api.ODStartScreenHeaderComponent("openticket:header",999,[
{key:"Version",value:openticket.versions.get("openticket:version").toString()},
{key:"Support",value:"https://discord.dj-dj.be"},
{key:"Language",value:(currentLanguageMetadata ? currentLanguageMetadata.language : "Unknown")}
]," - ",{
align:"center",
width:openticket.startscreen.get("openticket:logo")
}))
//FLAGS
openticket.startscreen.add(new api.ODStartScreenFlagsCategoryComponent("openticket:flags",4,openticket.flags.getAll()))
//PLUGINS
openticket.startscreen.add(new api.ODStartScreenPluginsCategoryComponent("openticket:plugins",3,openticket.plugins.getAll(),openticket.plugins.unknownCrashedPlugins))
//STATS
openticket.startscreen.add(new api.ODStartScreenPropertiesCategoryComponent("openticket:stats",2,"startup info",[
{key:"status",value:ansis.bold(openticket.client.activity.getStatusType())+openticket.client.activity.text+" ("+openticket.client.activity.status+")"},
{key:"options",value:"loaded "+ansis.bold(openticket.options.getLength().toString())+" options!"},
{key:"panels",value:"loaded "+ansis.bold(openticket.panels.getLength().toString())+" panels!"},
{key:"tickets",value:"loaded "+ansis.bold(openticket.tickets.getLength().toString())+" tickets!"},
{key:"roles",value:"loaded "+ansis.bold(openticket.roles.getLength().toString())+" roles!"},
{key:"help",value:ansis.bold(openticket.configs.get("openticket:general").data.prefix+"help")+" or "+ansis.bold("/help")}
]))
//LIVESTATUS
openticket.startscreen.add(new api.ODStartScreenLiveStatusCategoryComponent("openticket:livestatus",1,openticket.livestatus))
//LOGS
openticket.startscreen.add(new api.ODStartScreenLogCategoryComponent("openticket:logs",0))
}
+133
View File
@@ -0,0 +1,133 @@
import {openticket, api, utilities} from "../../index"
import * as discord from "discord.js"
const stats = openticket.stats
const lang = openticket.languages
export const loadAllStatScopes = async () => {
stats.add(new api.ODStatGlobalScope("openticket:global",utilities.emojiTitle("📊",lang.getTranslation("stats.scopes.global"))))
stats.add(new api.ODStatGlobalScope("openticket:system",utilities.emojiTitle("⚙️",lang.getTranslation("stats.scopes.system"))))
stats.add(new api.ODStatScope("openticket:user",utilities.emojiTitle("📊",lang.getTranslation("stats.scopes.user"))))
stats.add(new api.ODStatScope("openticket:ticket",utilities.emojiTitle("📊",lang.getTranslation("stats.scopes.ticket"))))
stats.add(new api.ODStatScope("openticket:participants",utilities.emojiTitle("👥",lang.getTranslation("stats.scopes.participants"))))
}
export const loadAllStats = async () => {
const generalConfig = openticket.configs.get("openticket:general")
if (!generalConfig) return
const global = stats.get("openticket:global")
if (global){
global.add(new api.ODBasicStat("openticket:tickets-created",10,lang.getTranslation("stats.properties.ticketsCreated"),0))
global.add(new api.ODBasicStat("openticket:tickets-closed",9,lang.getTranslation("stats.properties.ticketsClosed"),0))
global.add(new api.ODBasicStat("openticket:tickets-deleted",8,lang.getTranslation("stats.properties.ticketsDeleted"),0))
global.add(new api.ODBasicStat("openticket:tickets-reopened",7,lang.getTranslation("stats.properties.ticketsReopened"),0))
global.add(new api.ODBasicStat("openticket:tickets-autoclosed",6,lang.getTranslation("stats.properties.ticketsAutoclosed"),0))
global.add(new api.ODBasicStat("openticket:tickets-autodeleted",5,"Tickets Autodeleted",0)) //TODO TRANSLATION!!!
global.add(new api.ODBasicStat("openticket:tickets-claimed",4,lang.getTranslation("stats.properties.ticketsClaimed"),0))
global.add(new api.ODBasicStat("openticket:tickets-pinned",3,lang.getTranslation("stats.properties.ticketsPinned"),0))
global.add(new api.ODBasicStat("openticket:tickets-moved",2,lang.getTranslation("stats.properties.ticketsMoved"),0))
global.add(new api.ODBasicStat("openticket:users-blacklisted",1,lang.getTranslation("stats.properties.usersBlacklisted"),0))
global.add(new api.ODBasicStat("openticket:transcripts-created",0,lang.getTranslation("stats.properties.transcriptsCreated"),0))
}
const system = stats.get("openticket:system")
if (system){
system.add(new api.ODDynamicStat("openticket:startup-date",1,() => {
return lang.getTranslation("params.uppercase.startupDate")+": "+discord.time(new Date(),"f")
}))
system.add(new api.ODDynamicStat("openticket:version",0,() => {
return lang.getTranslation("params.uppercase.version")+": `"+openticket.versions.get("openticket:version").toString()+"`"
}))
}
const user = stats.get("openticket:user")
if (user){
user.add(new api.ODDynamicStat("openticket:name",11,async (scopeId,guild,channel,user) => {
return lang.getTranslation("params.uppercase.name")+": "+discord.userMention(scopeId)
}))
user.add(new api.ODDynamicStat("openticket:role",10,async (scopeId,guild,channel,user) => {
try{
const scopeMember = await guild.members.fetch(scopeId)
if (!scopeMember) return ""
const permissions = await openticket.permissions.getPermissions(scopeMember.user,channel,guild)
if (permissions.type == "developer") return lang.getTranslation("params.uppercase.role")+": 💻 `Developer`" //TODO TRANSLATION!!!
if (permissions.type == "owner") return lang.getTranslation("params.uppercase.role")+": 👑 `Server Owner`" //TODO TRANSLATION!!!
if (permissions.type == "admin") return lang.getTranslation("params.uppercase.role")+": 💼 `Server Admin`" //TODO TRANSLATION!!!
if (permissions.type == "moderator") return lang.getTranslation("params.uppercase.role")+": 🚔 `Moderator Team`" //TODO TRANSLATION!!!
if (permissions.type == "support") return lang.getTranslation("params.uppercase.role")+": 💬 `Support Team`" //TODO TRANSLATION!!!
else return lang.getTranslation("params.uppercase.role")+": 👤 `Member`" //TODO TRANSLATION!!!
}catch{
return ""
}
}))
user.add(new api.ODBasicStat("openticket:tickets-created",8,lang.getTranslation("stats.properties.ticketsCreated"),0))
user.add(new api.ODBasicStat("openticket:tickets-closed",7,lang.getTranslation("stats.properties.ticketsClosed"),0))
user.add(new api.ODBasicStat("openticket:tickets-deleted",6,lang.getTranslation("stats.properties.ticketsDeleted"),0))
user.add(new api.ODBasicStat("openticket:tickets-reopened",5,lang.getTranslation("stats.properties.ticketsReopened"),0))
user.add(new api.ODBasicStat("openticket:tickets-claimed",4,lang.getTranslation("stats.properties.ticketsClaimed"),0))
user.add(new api.ODBasicStat("openticket:tickets-pinned",3,lang.getTranslation("stats.properties.ticketsPinned"),0))
user.add(new api.ODBasicStat("openticket:tickets-moved",2,lang.getTranslation("stats.properties.ticketsMoved"),0))
user.add(new api.ODBasicStat("openticket:users-blacklisted",1,lang.getTranslation("stats.properties.usersBlacklisted"),0))
user.add(new api.ODBasicStat("openticket:transcripts-created",0,lang.getTranslation("stats.properties.transcriptsCreated"),0))
}
const ticket = stats.get("openticket:ticket")
if (ticket){
ticket.add(new api.ODDynamicStat("openticket:name",5,async (scopeId,guild,channel,user) => {
return lang.getTranslation("params.uppercase.ticket")+": "+discord.channelMention(scopeId)
}))
ticket.add(new api.ODDynamicStat("openticket:status",4,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
if (!ticket) return ""
const closed = ticket.exists("openticket:closed") ? ticket.get("openticket:closed").value : false
return closed ? lang.getTranslation("params.uppercase.status")+": 🔒 `Closed`" : lang.getTranslation("params.uppercase.status")+": 🔓 `Open`" //TODO TRANSLATION!!!
}))
ticket.add(new api.ODDynamicStat("openticket:claimed",3,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
if (!ticket) return ""
const claimed = ticket.exists("openticket:claimed") ? ticket.get("openticket:claimed").value : false
return claimed ? lang.getTranslation("params.uppercase.claimed")+": 🟢 `Yes`" : lang.getTranslation("params.uppercase.claimed")+": 🔴 `No`"
}))
ticket.add(new api.ODDynamicStat("openticket:pinned",2,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
if (!ticket) return ""
const pinned = ticket.exists("openticket:pinned") ? ticket.get("openticket:pinned").value : false
return pinned ? lang.getTranslation("params.uppercase.pinned")+": 🟢 `Yes`" : lang.getTranslation("params.uppercase.pinned")+": 🔴 `No`"
}))
ticket.add(new api.ODDynamicStat("openticket:creation-date",1,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
if (!ticket) return ""
const rawDate = ticket.get("openticket:opened-on").value ?? new Date().getTime()
return lang.getTranslation("params.uppercase.creationDate")+": "+discord.time(new Date(rawDate),"f")
}))
ticket.add(new api.ODDynamicStat("openticket:creator",0,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
if (!ticket) return ""
const creator = ticket.get("openticket:opened-by").value
return lang.getTranslation("params.uppercase.creator")+": "+ (creator ? discord.userMention(creator) : "`unknown`")
}))
}
const participants = stats.get("openticket:participants")
if (participants){
participants.add(new api.ODDynamicStat("openticket:participants",0,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
if (!ticket) return ""
const participants = ticket.exists("openticket:participants") ? ticket.get("openticket:participants").value : []
return participants.map((p) => {
return (p.type == "role") ? discord.roleMention(p.id) : discord.userMention(p.id)
}).join("\n")
}))
}
}
+12
View File
@@ -0,0 +1,12 @@
import {openticket, api, utilities} from "../../index"
export const loadAllBlacklistedUsers = async () => {
const userDatabase = openticket.databases.get("openticket:users")
if (!userDatabase) return
const users = userDatabase.getCategory("openticket:blacklist") ?? []
users.forEach((user) => {
if (typeof user.value != "string") return
openticket.blacklist.add(new api.ODBlacklist(user.key,user.value))
})
}
+107
View File
@@ -0,0 +1,107 @@
import {openticket, api, utilities} from "../../index"
export const loadAllOptions = async () => {
const optionConfig = openticket.configs.get("openticket:options")
if (!optionConfig) return
optionConfig.data.forEach((option) => {
if (option.type == "ticket"){
const loadedOption = loadTicketOption(option)
openticket.options.add(loadedOption)
openticket.options.suffix.add(loadTicketOptionSuffix(loadedOption))
}else if (option.type == "website"){
openticket.options.add(loadWebsiteOption(option))
}else if (option.type == "role"){
openticket.options.add(loadRoleOption(option))
}
})
}
export const loadTicketOption = (option:api.ODJsonConfig_DefaultOptionTicketType): api.ODTicketOption => {
return new api.ODTicketOption(option.id,[
new api.ODOptionData("openticket:name",option.name),
new api.ODOptionData("openticket:description",option.description),
new api.ODOptionData("openticket:button-emoji",option.button.emoji),
new api.ODOptionData("openticket:button-label",option.button.label),
new api.ODOptionData("openticket:button-color",option.button.color),
new api.ODOptionData("openticket:admins",option.ticketAdmins),
new api.ODOptionData("openticket:admins-readonly",option.readonlyAdmins),
new api.ODOptionData("openticket:allow-blacklisted-users",option.allowCreationByBlacklistedUsers),
new api.ODOptionData("openticket:questions",option.questions),
new api.ODOptionData("openticket:channel-prefix",option.channel.prefix),
new api.ODOptionData("openticket:channel-suffix",option.channel.suffix),
new api.ODOptionData("openticket:channel-category",option.channel.category),
new api.ODOptionData("openticket:channel-category-closed",option.channel.closedCategory),
new api.ODOptionData("openticket:channel-category-backup",option.channel.backupCategory),
new api.ODOptionData("openticket:channel-categories-claimed",option.channel.claimedCategory),
new api.ODOptionData("openticket:channel-description",option.channel.description),
new api.ODOptionData("openticket:dm-message-enabled",option.dmMessage.enabled),
new api.ODOptionData("openticket:dm-message-text",option.dmMessage.text),
new api.ODOptionData("openticket:dm-message-embed",option.dmMessage.embed),
new api.ODOptionData("openticket:ticket-message-enabled",option.ticketMessage.enabled),
new api.ODOptionData("openticket:ticket-message-text",option.ticketMessage.text),
new api.ODOptionData("openticket:ticket-message-embed",option.ticketMessage.embed),
new api.ODOptionData("openticket:ticket-message-ping",option.ticketMessage.ping),
new api.ODOptionData("openticket:autoclose-enable-hours",option.autoclose.enableInactiveHours),
new api.ODOptionData("openticket:autoclose-enable-leave",option.autoclose.enableUserLeave),
new api.ODOptionData("openticket:autoclose-disable-claim",option.autoclose.disableOnClaim),
new api.ODOptionData("openticket:autoclose-hours",option.autoclose.inactiveHours),
new api.ODOptionData("openticket:autodelete-enable-days",option.autodelete.enableInactiveDays),
new api.ODOptionData("openticket:autodelete-enable-leave",option.autodelete.enableUserLeave),
new api.ODOptionData("openticket:autodelete-disable-claim",option.autodelete.disableOnClaim),
new api.ODOptionData("openticket:autodelete-days",option.autodelete.inactiveDays),
new api.ODOptionData("openticket:cooldown-enabled",option.cooldown.enabled),
new api.ODOptionData("openticket:cooldown-minutes",option.cooldown.cooldownMinutes),
new api.ODOptionData("openticket:limits-enabled",option.limits.enabled),
new api.ODOptionData("openticket:limits-maximum-global",option.limits.globalMaximum),
new api.ODOptionData("openticket:limits-maximum-user",option.limits.userMaximum)
])
}
export const loadWebsiteOption = (opt:api.ODJsonConfig_DefaultOptionWebsiteType): api.ODWebsiteOption => {
return new api.ODWebsiteOption(opt.id,[
new api.ODOptionData("openticket:name",opt.name),
new api.ODOptionData("openticket:description",opt.description),
new api.ODOptionData("openticket:button-emoji",opt.button.emoji),
new api.ODOptionData("openticket:button-label",opt.button.label),
new api.ODOptionData("openticket:url",opt.url)
])
}
export const loadRoleOption = (opt:api.ODJsonConfig_DefaultOptionRoleType): api.ODRoleOption => {
return new api.ODRoleOption(opt.id,[
new api.ODOptionData("openticket:name",opt.name),
new api.ODOptionData("openticket:description",opt.description),
new api.ODOptionData("openticket:button-emoji",opt.button.emoji),
new api.ODOptionData("openticket:button-label",opt.button.label),
new api.ODOptionData("openticket:button-color",opt.button.color),
new api.ODOptionData("openticket:roles",opt.roles),
new api.ODOptionData("openticket:mode",opt.mode),
new api.ODOptionData("openticket:remove-roles-on-add",opt.removeRolesOnAdd),
new api.ODOptionData("openticket:add-on-join",opt.addOnMemberJoin)
])
}
export const loadTicketOptionSuffix = (option:api.ODTicketOption): api.ODOptionSuffix => {
const mode = option.get("openticket:channel-suffix").value
const globalDatabase = openticket.databases.get("openticket:global")
if (mode == "user-name") return new api.ODOptionUserNameSuffix(option.id.value,option)
else if (mode == "random-number") return new api.ODOptionRandomNumberSuffix(option.id.value,option,globalDatabase)
else if (mode == "random-hex") return new api.ODOptionRandomHexSuffix(option.id.value,option,globalDatabase)
else if (mode == "counter-fixed") return new api.ODOptionCounterFixedSuffix(option.id.value,option,globalDatabase)
else if (mode == "counter-dynamic") return new api.ODOptionCounterDynamicSuffix(option.id.value,option,globalDatabase)
else return new api.ODOptionUserIdSuffix(option.id.value,option)
}
+165
View File
@@ -0,0 +1,165 @@
import {openticket, api, utilities} from "../../index"
import * as discord from "discord.js"
export const loadAllPanels = async () => {
const panelConfig = openticket.configs.get("openticket:panels")
if (!panelConfig) return
panelConfig.data.forEach((panel) => {
openticket.panels.add(loadPanel(panel))
})
}
export const loadPanel = (panel:api.ODJsonConfig_DefaultPanelType) => {
return new api.ODPanel(panel.id,[
new api.ODPanelData("openticket:name",panel.name),
new api.ODPanelData("openticket:options",panel.options),
new api.ODPanelData("openticket:dropdown",panel.dropdown),
new api.ODPanelData("openticket:text",panel.text),
new api.ODPanelData("openticket:embed",panel.embed),
new api.ODPanelData("openticket:dropdown-placeholder",panel.settings.dropdownPlaceholder),
new api.ODPanelData("openticket:enable-max-tickets-warning-text",panel.settings.enableMaxTicketsWarningInText),
new api.ODPanelData("openticket:enable-max-tickets-warning-embed",panel.settings.enableMaxTicketsWarningInEmbed),
new api.ODPanelData("openticket:describe-options-layout",panel.settings.describeOptionsLayout),
new api.ODPanelData("openticket:describe-options-custom-title",panel.settings.describeOptionsCustomTitle),
new api.ODPanelData("openticket:describe-options-in-text",panel.settings.describeOptionsInText),
new api.ODPanelData("openticket:describe-options-in-embed-fields",panel.settings.describeOptionsInEmbedFields),
new api.ODPanelData("openticket:describe-options-in-embed-description",panel.settings.describeOptionsInEmbedDescription),
])
}
export function describePanelOptions(mode:"fields",panel:api.ODPanel): {name:string,value:string}[]
export function describePanelOptions(mode:"text",panel:api.ODPanel): string
export function describePanelOptions(mode:"fields"|"text", panel:api.ODPanel): {name:string,value:string}[]|string {
const layout = panel.get("openticket:describe-options-layout").value
const dropdownMode = panel.get("openticket:dropdown").value
const options: api.ODOption[] = []
let hasTicket = false
let hasWebsite = false
let hasRole = false
let ticketOnly = true
let websiteOnly = true
let roleOnly = true
panel.get("openticket:options").value.forEach((id) => {
const opt = openticket.options.get(id)
if (opt){
if (opt instanceof api.ODTicketOption){
options.push(opt)
hasTicket = true
roleOnly = false
websiteOnly = false
}else if (!dropdownMode && opt instanceof api.ODWebsiteOption){
options.push(opt)
hasWebsite = true
ticketOnly = false
roleOnly = false
}else if (!dropdownMode && opt instanceof api.ODRoleOption){
options.push(opt)
hasRole = true
ticketOnly = false
websiteOnly = false
}
}
})
const autotitle = (hasTicket && ticketOnly) ? "Select your ticket:" : ((hasRole && roleOnly) ? "Select your role:" : "Select your option:")
const title = (panel.get("openticket:describe-options-custom-title").value.length < 1) ? "__"+autotitle+"__\n" : "__"+panel.get("openticket:describe-options-custom-title").value+"__\n"
if (mode == "fields") return options.map((opt) => {
if (opt instanceof api.ODTicketOption){
//ticket option
const emoji = opt.exists("openticket:button-emoji") ? opt.get("openticket:button-emoji").value : ""
const name = opt.exists("openticket:name") ? opt.get("openticket:name").value : "`<unnamed-ticket>`"
let description = opt.exists("openticket:description") ? opt.get("openticket:description").value : "`<no-description>`"
if (layout == "normal" || layout == "detailed"){
if (opt.exists("openticket:cooldown-enabled") && opt.get("openticket:cooldown-enabled").value) description = description + "\nCooldown: `"+opt.get("openticket:cooldown-minutes").value+" min`"
if (opt.exists("openticket:limits-enabled") && opt.get("openticket:limits-enabled").value) description = description + "\nMax Tickets: `"+opt.get("openticket:limits-maximum-user").value+"`"
}
if (layout == "detailed"){
if (opt.exists("openticket:admins")) description = description + "\nAdmins: "+opt.get("openticket:admins").value.map((admin) => discord.roleMention(admin)).join(", ")
}
return {name:utilities.emojiTitle(emoji,name),value:description}
}else if (opt instanceof api.ODWebsiteOption){
//website option
const emoji = opt.exists("openticket:button-emoji") ? opt.get("openticket:button-emoji").value : ""
const name = opt.exists("openticket:name") ? opt.get("openticket:name").value : "`<unnamed-website>`"
let description = opt.exists("openticket:description") ? opt.get("openticket:description").value : "`<no-description>`"
return {name:utilities.emojiTitle(emoji,name),value:description}
}else if (opt instanceof api.ODRoleOption){
//role option
const emoji = opt.exists("openticket:button-emoji") ? opt.get("openticket:button-emoji").value : ""
const name = opt.exists("openticket:name") ? opt.get("openticket:name").value : "`<unnamed-role>`"
let description = opt.exists("openticket:description") ? opt.get("openticket:description").value : "`<no-description>`"
if (layout == "normal" || layout == "detailed"){
if (opt.exists("openticket:roles")) description = description + "\nRoles: "+opt.get("openticket:roles").value.map((admin) => discord.roleMention(admin)).join(", ")
}
return {name:utilities.emojiTitle(emoji,name),value:description}
}else{
//auto-generated plugin option
const emoji = opt.get("openticket:button-emoji") as api.ODOptionData<string>|null
const name = opt.get("openticket:name") as api.ODOptionData<string>|null
const description = opt.get("openticket:description") as api.ODOptionData<string>|null
return {name:utilities.emojiTitle((emoji ? emoji.value : ""),(name ? name.value : "`"+opt.id+"`")),value:(description ? description.value : "`<no-description>`")}
}
})
else if (mode == "text") return title+options.map((opt) => {
if (opt instanceof api.ODTicketOption){
//ticket option
const emoji = opt.exists("openticket:button-emoji") ? opt.get("openticket:button-emoji").value : ""
const name = opt.exists("openticket:name") ? opt.get("openticket:name").value : "`<unnamed-ticket>`"
let description = opt.exists("openticket:description") ? opt.get("openticket:description").value : "`<no-description>`"
if (layout == "normal" || layout == "detailed"){
if (opt.exists("openticket:cooldown-enabled") && opt.get("openticket:cooldown-enabled").value) description = description + "\nCooldown: `"+opt.get("openticket:cooldown-minutes").value+" min`"
if (opt.exists("openticket:limits-enabled") && opt.get("openticket:limits-enabled").value) description = description + "\nMax Tickets: `"+opt.get("openticket:limits-maximum-user").value+"`"
}
if (layout == "detailed"){
if (opt.exists("openticket:admins")) description = description + "\nAdmins: "+opt.get("openticket:admins").value.map((admin) => discord.roleMention(admin)).join(", ")
}
if (layout == "simple") return "**"+utilities.emojiTitle(emoji,name)+":** "+description
else return "**"+utilities.emojiTitle(emoji,name)+"**\n"+description
}else if (opt instanceof api.ODWebsiteOption){
//website option
const emoji = opt.exists("openticket:button-emoji") ? opt.get("openticket:button-emoji").value : ""
const name = opt.exists("openticket:name") ? opt.get("openticket:name").value : "`<unnamed-website>`"
let description = opt.exists("openticket:description") ? opt.get("openticket:description").value : "`<no-description>`"
if (layout == "simple") return "**"+utilities.emojiTitle(emoji,name)+":** "+description
else return "**"+utilities.emojiTitle(emoji,name)+"**\n"+description
}else if (opt instanceof api.ODRoleOption){
//role option
const emoji = opt.exists("openticket:button-emoji") ? opt.get("openticket:button-emoji").value : ""
const name = opt.exists("openticket:name") ? opt.get("openticket:name").value : "`<unnamed-role>`"
let description = opt.exists("openticket:description") ? opt.get("openticket:description").value : "`<no-description>`"
if (layout == "normal" || layout == "detailed"){
if (opt.exists("openticket:roles")) description = description + "\nRoles: "+opt.get("openticket:roles").value.map((admin) => discord.roleMention(admin)).join(", ")
}
if (layout == "simple") return "**"+utilities.emojiTitle(emoji,name)+":** "+description
else return "**"+utilities.emojiTitle(emoji,name)+"**\n"+description
}else{
//auto-generated plugin option
const emoji = opt.get("openticket:button-emoji") as api.ODOptionData<string>|null
const name = opt.get("openticket:name") as api.ODOptionData<string>|null
const description = opt.get("openticket:description") as api.ODOptionData<string>|null
if (layout == "simple") return "**"+utilities.emojiTitle((emoji ? emoji.value : ""),(name ? name.value : "`"+opt.id+"`"))+":** "+(description ? description.value : "`<no-description>`")
else return "**"+utilities.emojiTitle((emoji ? emoji.value : ""),(name ? name.value : "`"+opt.id+"`"))+"**\n"+(description ? description.value : "`<no-description>`")
}
}).join("\n\n")
else throw new api.ODSystemError("Unknown panel generation mode, choose 'text' or 'fields'")
}
+38
View File
@@ -0,0 +1,38 @@
import {openticket, api, utilities} from "../../index"
export const loadAllQuestions = async () => {
const questionConfig = openticket.configs.get("openticket:questions")
if (!questionConfig) return
questionConfig.data.forEach((question) => {
if (question.type == "short"){
openticket.questions.add(loadShortQuestion(question))
}else if (question.type == "paragraph"){
openticket.questions.add(loadParagraphQuestion(question))
}
})
}
export const loadShortQuestion = (option:api.ODJsonConfig_DefaultShortQuestionType) => {
return new api.ODShortQuestion(option.id,[
new api.ODQuestionData("openticket:name",option.name),
new api.ODQuestionData("openticket:required",option.required),
new api.ODQuestionData("openticket:placeholder",option.placeholder),
new api.ODQuestionData("openticket:length-enabled",option.length.enabled),
new api.ODQuestionData("openticket:length-min",option.length.min),
new api.ODQuestionData("openticket:length-max",option.length.max),
])
}
export const loadParagraphQuestion = (option:api.ODJsonConfig_DefaultParagraphQuestionType) => {
return new api.ODParagraphQuestion(option.id,[
new api.ODQuestionData("openticket:name",option.name),
new api.ODQuestionData("openticket:required",option.required),
new api.ODQuestionData("openticket:placeholder",option.placeholder),
new api.ODQuestionData("openticket:length-enabled",option.length.enabled),
new api.ODQuestionData("openticket:length-min",option.length.min),
new api.ODQuestionData("openticket:length-max",option.length.max),
])
}
+18
View File
@@ -0,0 +1,18 @@
import {openticket, api, utilities} from "../../index"
export const loadAllRoles = async () => {
openticket.options.getAll().forEach((opt) => {
if (opt instanceof api.ODRoleOption){
openticket.roles.add(loadRole(opt))
}
})
}
export const loadRole = (option:api.ODRoleOption) => {
return new api.ODRole(option.id,[
new api.ODRoleData("openticket:roles",option.get("openticket:roles").value),
new api.ODRoleData("openticket:mode",option.get("openticket:mode").value),
new api.ODRoleData("openticket:remove-roles-on-add",option.get("openticket:remove-roles-on-add").value),
new api.ODRoleData("openticket:add-on-join",option.get("openticket:add-on-join").value)
])
}
+35
View File
@@ -0,0 +1,35 @@
import {openticket, api, utilities} from "../../index"
const optionDatabase = openticket.databases.get("openticket:options")
export const loadAllTickets = async () => {
const ticketDatabase = openticket.databases.get("openticket:tickets")
if (!ticketDatabase) return
const tickets = ticketDatabase.getCategory("openticket:ticket")
if (!tickets) return
tickets.forEach((ticket) => {
try {
openticket.tickets.add(loadTicket(ticket.value))
}catch (err){
process.emit("uncaughtException",new api.ODSystemError("Failed to load ticket from database! => id: "+ticket.key+"\n ===> "+err))
}
})
}
export const loadTicket = (ticket:api.ODTicketJson) => {
const backupOption = optionDatabase.exists("openticket:used-option",ticket.option) ? api.ODTicketOption.fromJson(optionDatabase.get("openticket:used-option",ticket.option) as api.ODOptionJson) : null
const configOption = openticket.options.get(ticket.option)
//check if option is of type "ticket"
if (configOption && !(configOption instanceof api.ODTicketOption)) throw new api.ODSystemError("Unable to load ticket because option is not of 'ticket' type!")
//manage backup option
if (configOption) optionDatabase.set("openticket:used-option",configOption.id.value,configOption.toJson(openticket.versions.get("openticket:version")))
else if (backupOption) openticket.options.add(backupOption)
else throw new api.ODSystemError("Unable to use backup option! Normal option not found in config!")
//load ticket & option
const option = (configOption ?? backupOption) as api.ODTicketOption
return api.ODTicket.fromJson(ticket,option)
}
+456
View File
@@ -0,0 +1,456 @@
import {openticket, api, utilities} from "../../index"
import * as discord from "discord.js"
const collector = openticket.transcripts.collector
const messages = openticket.builders.messages
const transcriptConfig = openticket.configs.get("openticket:transcripts")
const textConfig = transcriptConfig.data.textTranscriptStyle
export const replaceHtmlTranscriptMentions = async (text:string) => {
const mainServer = openticket.client.mainServer
if (!mainServer) throw new api.ODSystemError("Unknown mainServer! => Required for mention replacement in Html Transcripts!")
const usertext = await utilities.asyncReplace(text,/<@([0-9]+)>/g,async (match,id) => {
const member = await openticket.client.fetchGuildMember(mainServer,id)
return (member ? "<@"+(member.user.displayName).replace(/\s/g,"&nbsp;")+"> " : id) //replace with html spaces => BUG: whitespace CSS isn't "pre-wrap"
})
const channeltext = await utilities.asyncReplace(usertext,/<#([0-9]+)>/g,async (match,id) => {
const channel = await openticket.client.fetchGuildChannel(mainServer,id)
return (channel ? "<#"+channel.name.replace(/\s/g,"&nbsp;")+"> " : id) //replace with html spaces => BUG: whitespace CSS isn't "pre-wrap"
})
const roletext = await utilities.asyncReplace(channeltext,/<@&([0-9]+)>/g,async (match,id) => {
const role = await openticket.client.fetchGuildRole(mainServer,id)
let text = role ? role.name.replace(/\s/g,"&nbsp;") : id
let color = role ? ((role.hexColor == "#000000") ? "regular" : role.hexColor) : "regular" //when hex color is #000000 => render as default
return "<@&"+text+"::"+color+"> "
})
const defaultroletext = await utilities.asyncReplace(roletext,/@(everyone|here)/g,async (match,id) => {
return "<@&"+id+"::regular> "
})
return defaultroletext
}
export const loadAllTranscriptCompilers = async () => {
//TEXT COMPILER
openticket.transcripts.add(new api.ODTranscriptCompiler<{contents:string}>("openticket:text-compiler",undefined,async (ticket,channel,user) => {
//COMPILE
const rawMessages = await collector.collectAllMessages(ticket)
if (!rawMessages) return {ticket,channel,user,success:false,errorReason:"Unable to collect messages!",messages:null,data:null}
const messages = await collector.convertMessagesToTranscriptData(rawMessages)
const finalMessages: string[] = []
finalMessages.push("=============== MESSAGES ===============")
messages.filter((msg) => textConfig.includeBotMessages || !msg.author.tag).forEach((msg) => {
const timestamp = utilities.dateString(new Date(msg.timestamp))
const edited = (msg.edited ? " (edited)" : "")
const authorId = (textConfig.includeIds ? " ("+msg.author.id+")" : "")
const msgId = (textConfig.includeIds ? " ("+msg.id+")" : "")
if (textConfig.layout == "simple"){
//SIMPLE LAYOUT
const header = "["+timestamp+" | "+msg.author.displayname+authorId+"]"+edited+msgId
const embeds = (textConfig.includeEmbeds) ? "\nEmbeds: "+msg.embeds.length : ""
const files = (textConfig.includeFiles) ? "\nFiles: "+msg.files.length : ""
const content = (msg.content) ? msg.content : ("<content is empty>"+embeds+files)
finalMessages.push(header+"\n "+content.split("\n").join("\n "))
}else if (textConfig.layout == "normal"){
//NORMAL LAYOUT
const header = "["+timestamp+" | "+msg.author.displayname+authorId+"]"+edited+msgId
const embeds = (textConfig.includeEmbeds && msg.embeds.length > 0) ? "\n"+msg.embeds.map((embed) => {
return "==== (EMBED) "+(embed.title ?? "<no-title>")+" ====\n"+(embed.description ?? "<no-description>")
}) : ""
const files = (textConfig.includeFiles && msg.files.length > 0) ? "\n"+msg.files.map((file) => {
return "==== (FILE) "+(file.name)+" ====\nSize: "+(file.size+" "+file.unit)+"\nUrl: "+file.url
}) : ""
const content = (msg.content) ? msg.content : ""
finalMessages.push(header+"\n "+(content+embeds+files).split("\n").join("\n "))
}else if (textConfig.layout == "detailed"){
//ADVANCED LAYOUT
const header = "["+timestamp+" | "+msg.author.displayname+authorId+"]"+edited+msgId
const embeds = (textConfig.includeEmbeds && msg.embeds.length > 0) ? "\n"+msg.embeds.map((embed) => {
return "\n==== (EMBED) "+(embed.title ?? "<no-title>")+" ====\n"+(embed.description ?? "<no-description>")+(embed.fields.length > 0 ? "\n\n== (FIELDS) ==\n"+embed.fields.map((field) => field.name+": "+field.value).join("\n") : "")
}) : ""
const files = (textConfig.includeFiles && msg.files.length > 0) ? "\n"+msg.files.map((file) => {
return "\n==== (FILE) "+(file.name)+" ====\nSize: "+(file.size+" "+file.unit)+"\nUrl: "+file.url+"\nAlt: "+(file.alt ?? "/")
}) : ""
const reactions = (msg.reactions.filter((r) => !r.custom).length > 0) ? "\n==== (REACTIONS) ====\n"+msg.reactions.filter((r) => !r.custom).map((r) => r.amount+" "+r.emoji).join(" - ") : ""
const content = (msg.content) ? msg.content : ""
finalMessages.push(header+"\n "+(content+embeds+files+reactions).split("\n").join("\n "))
}
})
const finalStats: string[] = []
const creationDate = ticket.get("openticket:opened-on").value
const closeDate = ticket.get("openticket:closed-on").value
const claimDate = ticket.get("openticket:claimed-on").value
const pinDate = ticket.get("openticket:pinned-on").value
const creator = await openticket.tickets.getTicketUser(ticket,"creator")
const closer = await openticket.tickets.getTicketUser(ticket,"closer")
const claimer = await openticket.tickets.getTicketUser(ticket,"claimer")
const pinner = await openticket.tickets.getTicketUser(ticket,"pinner")
if (textConfig.includeStats){
finalStats.push("=============== STATS ===============")
if (textConfig.layout == "simple"){
//SIMPLE LAYOUT
if (creationDate) finalStats.push("Created On: "+utilities.dateString(new Date(creationDate)))
if (creator) finalStats.push("Created By: "+creator.displayName)
finalStats.push("\n")
}else if (textConfig.layout == "normal"){
//NORMAL LAYOUT
if (creationDate) finalStats.push("Created On: "+utilities.dateString(new Date(creationDate)))
if (creator) finalStats.push("Created By: "+creator.displayName)
finalStats.push("")
if (closer) finalStats.push("Closed By: "+closer.displayName)
if (claimer) finalStats.push("Claimed By: "+claimer.displayName)
if (pinner) finalStats.push("Pinned By: "+pinner.displayName)
finalStats.push("Deleted By: "+user.displayName)
finalStats.push("\n")
}else if (textConfig.layout == "detailed"){
//ADVANCED LAYOUT
if (creationDate) finalStats.push("Created On: "+utilities.dateString(new Date(creationDate)))
if (creator) finalStats.push("Created By: "+creator.displayName)
finalStats.push("")
if (closeDate) finalStats.push("Closed On: "+utilities.dateString(new Date(closeDate)))
if (closer) finalStats.push("Closed By: "+closer.displayName)
finalStats.push("")
if (claimDate) finalStats.push("Claimed On: "+utilities.dateString(new Date(claimDate)))
if (claimer) finalStats.push("Claimed By: "+claimer.displayName)
finalStats.push("")
if (pinDate) finalStats.push("Pinned On: "+utilities.dateString(new Date(pinDate)))
if (pinner) finalStats.push("Pinned By: "+pinner.displayName)
finalStats.push("")
finalStats.push("Deleted On: "+utilities.dateString(new Date()))
finalStats.push("Deleted By: "+user.displayName)
finalStats.push("\n")
}
}
const final: string[] = []
final.push(...finalStats)
final.push(finalMessages.join("\n\n"))
return {ticket,channel,user,success:true,errorReason:null,messages,data:{contents:final.join("\n")}}
},async (result) => {
//READY
return {
channelMessage:await messages.getSafe("openticket:transcript-text-ready").build("channel",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:text-compiler")}),
creatorDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("creator-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:text-compiler")}),
participantDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("participant-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:text-compiler")}),
activeAdminDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("active-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:text-compiler")}),
everyAdminDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("every-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:text-compiler")})
}
}))
//HTML COMPILER
openticket.transcripts.add(new api.ODTranscriptCompiler<{url:string}>("openticket:html-compiler",async (ticket,channel,user) => {
//INIT
const req = new api.ODHTTPGetRequest("https://apis.dj-dj.be/transcripts/status.json",false)
const res = await req.run()
if (!res || res.status != 200 || !res.body){
return {success:false,errorReason:"HTML Transcripts are currently unavailable!",pendingMessage:null}
}
try{
const data = JSON.parse(res.body)
if (!data || data["v2"] != "online") return {success:false,errorReason:"HTML Transcripts are currently unavailable due to maintenance!",pendingMessage:null}
}catch{
return {success:false,errorReason:"HTML Transcripts are currently unavailable due to JSON parse error!",pendingMessage:null}
}
return {success:true,errorReason:null,pendingMessage:await messages.getSafe("openticket:transcript-html-progress").build("channel",{guild:channel.guild,channel,user,ticket,compiler:openticket.transcripts.get("openticket:html-compiler"),remaining:16000})}
},async (ticket,channel,user) => {
//COMPILE
const rawMessages = await collector.collectAllMessages(ticket)
if (!rawMessages) return {ticket,channel,user,success:false,errorReason:"Unable to collect messages!",messages:null,data:null}
const messages = await collector.convertMessagesToTranscriptData(rawMessages)
const htmlMessages: api.ODTranscriptHtmlV2Data["messages"] = []
for (const msg of messages){
const components: api.ODTranscriptHtmlV2Data["messages"][0]["components"] = []
msg.components.forEach((component) => {
if (component.components[0].type == "dropdown"){
//row contains dropdown
components.push({
type:"dropdown",
placeholder:component.components[0].placeholder ?? "Nothing Selected",
options:component.components[0].options.map((opt) => {
return {
id:opt.id,
label:opt.label ?? false,
description:opt.description ?? false,
icon:(opt.emoji && !opt.emoji.custom) ? opt.emoji.emoji : false
}
}),
})
}else if (component.components[0].type == "button"){
//row contains buttons
components.push({
type:"buttons",
buttons:component.components.map((button) => {
button = button as api.ODTranscriptButtonComponentData
return {
disabled:button.disabled,
type:(button.mode == "button") ? "interaction" : "url",
color:button.color,
id:button.id ?? false,
label:button.label ?? false,
icon:(button.emoji) ? button.emoji.emoji : false,
url:button.url ?? false
}
}),
})
}
})
components.push({
type:"reactions",
reactions:msg.reactions.map((reaction) => {
return {
amount:reaction.amount,
emoji:reaction.emoji,
type:(reaction.custom && reaction.animated) ? "gif" : (reaction.custom ? "image" : "svg")
}
})
})
const embeds: api.ODTranscriptHtmlV2Data["messages"][0]["embeds"] = []
for (const embed of msg.embeds){
embeds.push({
title:embed.title ? await replaceHtmlTranscriptMentions(embed.title) : false,
color:embed.color,
description:embed.description ? await replaceHtmlTranscriptMentions(embed.description) : false,
image:embed.image ?? false,
thumbnail:embed.thumbnail ?? false,
url:embed.url ?? false,
authorimg:embed.authorimg ?? false,
authortext:embed.authortext ?? false,
footerimg:embed.footerimg ?? false,
footertext:embed.footertext ?? false,
fields:embed.fields
})
}
htmlMessages.push({
author:{
id:msg.author.id,
name:msg.author.displayname,
pfp:msg.author.pfp,
bot:msg.author.tag == "app",
system:msg.author.tag == "system",
verifiedBot:msg.author.tag == "verified",
color:msg.author.color
},
edited:msg.edited,
timestamp:msg.timestamp,
important:msg.type == "important",
type:"normal",
content:msg.content ? await replaceHtmlTranscriptMentions(msg.content) : false,
embeds,
attachments:msg.files.map((file) => {
return {
type:"FILE",
fileType:file.type,
name:file.name,
size:file.size+" "+file.unit,
url:file.url
}
}),
components,
reply:{
type:(msg.reply) ? (msg.reply.type == "interaction" ? "command" : "reply") : false,
user:(msg.reply) ? {
id:msg.reply.user.id,
name:msg.reply.user.displayname,
pfp:msg.reply.user.pfp,
bot:msg.reply.user.tag == "app",
system:msg.reply.user.tag == "system",
verifiedBot:msg.reply.user.tag == "verified",
color:msg.reply.user.color
} : undefined,
replyOptions:(msg.reply && msg.reply.type == "message") ? {
guildId:msg.reply.guild,
channelId:msg.reply.channel,
messageId:msg.reply.id,
content:(msg.reply.content ?? "<embed>")?.substring(0,80)
} : undefined,
commandOptions:(msg.reply && msg.reply.type == "interaction") ? {
interactionId:"<outdated>",
interactionName:msg.reply.name
} : undefined
}
})
}
const htmlComponents: api.ODTranscriptHtmlV2Data["ticket"]["components"] = {
messages:messages.length,
embeds:0,
files:0,
interactions:{
buttons:0, //unused
dropdowns:0, //unused
total:0
},
reactions:0,
attachments:{
gifs:0, //unused
images:0, //unused
stickers:0, //unused
invites:0 //unused
}
}
messages.forEach((msg) => {
htmlComponents.embeds += msg.embeds.length
htmlComponents.files += msg.files.length
htmlComponents.reactions += msg.reactions.length
msg.components.forEach((row) => {
htmlComponents.interactions.total += row.components.length
})
})
const dsb = transcriptConfig.data.htmlTranscriptStyle.background
const dsh = transcriptConfig.data.htmlTranscriptStyle.header
const dss = transcriptConfig.data.htmlTranscriptStyle.stats
const dsf = transcriptConfig.data.htmlTranscriptStyle.favicon
const creator = await openticket.tickets.getTicketUser(ticket,"creator")
const claimer = await openticket.tickets.getTicketUser(ticket,"claimer")
const closer = await openticket.tickets.getTicketUser(ticket,"closer")
const htmlFinal: api.ODTranscriptHtmlV2Data = {
version:"2",
otversion:openticket.versions.get("openticket:version").toString(true),
bot:{
name:openticket.client.client.user.displayName,
id:openticket.client.client.user.id,
pfp:openticket.client.client.user.displayAvatarURL({extension:"png"}),
},
language:openticket.languages.getLanguageMetadata()?.language ?? "english",
style:{
background:{
backgroundData:(dsb.backgroundImage == "") ? dsb.backgroundColor : dsb.backgroundImage,
backgroundModus:(dsb.backgroundImage == "") ? "color" : "image",
enableCustomBackground:dsb.enableCustomBackground,
},
header:{
backgroundColor:dsh.backgroundColor || "#202225",
decoColor:dsh.decoColor || "#f8ba00",
textColor:dsh.textColor || "#ffffff",
enableCustomHeader:dsh.enableCustomHeader
},
stats:{
backgroundColor:dss.backgroundColor || "#202225",
keyTextColor:dss.keyTextColor || "#737373",
valueTextColor:dss.valueTextColor || "#ffffff",
hideBackgroundColor:dss.hideBackgroundColor || "#40444a",
hideTextColor:dss.hideTextColor || "#ffffff",
enableCustomStats:dss.enableCustomStats
},
favicon:{
imageUrl:dsf.imageUrl,
enableCustomFavicon:dsf.enableCustomFavicon
}
},
ticket:{
name:channel.name,
id:channel.id,
guildname:channel.guild.name,
guildid:channel.guild.id,
guildinvite:"",
creatorname:(creator ? creator.displayName : "<unknown>"),
creatorid:(creator ? creator.id : "<unknown>"),
creatorpfp:(creator ? creator.displayAvatarURL() : "https://transcripts.dj-dj.be/favicon.png"),
//closer is ticket deleter (small bug)
closedbyname:user.displayName,
closedbyid:user.id,
closedbypfp:user.displayAvatarURL(),
//claiming is currently unused
claimedname:(claimer ? claimer.displayName : "<not-claimed>"),
claimedid:(claimer ? claimer.id : "<not-claimed>"),
claimedpfp:(claimer ? claimer.displayAvatarURL() : "https://transcripts.dj-dj.be/favicon.png"),
closedtime:new Date().getTime(),
openedtime:ticket.get("openticket:opened-on").value ?? new Date().getTime(),
//role colors are currently unused
roleColors:[],
components:htmlComponents
},
messages:htmlMessages,
//premium is implemented, but currently unused
premium:{
enabled:false,
premiumToken:"",
customCredits:{
enable:false,
replaceText:"Powered By Open Ticket!",
replaceURL:"https://openticket.dj-dj.be",
enableReportBug:true
},
customHeaderUrl:{
enabled:false,
url:"https://openticket.dj-dj.be",
text:"Hello!"
},
customTranscriptUrl:{
enabled:false,
name:"test-server"
},
customFavicon:{
enabled:dsf.enableCustomFavicon,
image:(dsf.imageUrl) ? dsf.imageUrl : "https://transcripts.dj-dj.be/favicon.png"
},
additionalFlags:[]
}
}
const req = new api.ODHTTPPostRequest("https://apis.dj-dj.be/transcripts/upload?auth=openticketTRANSCRIPT1234&version=2",true,{
body:JSON.stringify(htmlFinal)
})
const res = await req.run()
if (!res || res.status != 200 || !res.body){
if (res.status == 429) return {ticket,channel,user,success:false,errorReason:"Failed to upload HTML Transcripts due to Ratelimt! Try again in a few minutes!",messages,data:null}
else return {ticket,channel,user,success:false,errorReason:"Failed to upload HTML Transcripts!",messages,data:null}
}
try{
var data: api.ODTranscriptHtmlV2Response = JSON.parse(res.body)
if (!data || data["status"] != "success") return {ticket,channel,user,success:false,errorReason:"Failed to upload HTML Transcripts! (Status: Error)",messages,data:null}
}catch{
return {ticket,channel,user,success:false,errorReason:"Failed to upload HTML Transcripts due to JSON parse error!",messages,data:null}
}
const url = "https://transcripts.dj-dj.be/v2/"+data.time+"_"+data.id+".html"
return {ticket,channel,user,success:true,errorReason:null,messages,data:{url}}
},async (result) => {
//READY
await utilities.timer(16000) //wait until transcript is ready
return {
channelMessage:await messages.getSafe("openticket:transcript-html-ready").build("channel",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:html-compiler")}),
creatorDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("creator-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:html-compiler")}),
participantDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("participant-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:html-compiler")}),
activeAdminDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("active-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:html-compiler")}),
everyAdminDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("every-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:html-compiler")})
}
}))
}
export const loadTranscriptHistory = async () => {
//UNIMPLEMENTED (made for html transcripts v3 update)
}