languages/config improvements & bug fixes
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
//@ts-check
|
||||
const fs = require("fs")
|
||||
const ts = require("typescript")
|
||||
const nodepath = require('path')
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"guillee3",
|
||||
"translators":["guillee3"],
|
||||
"lastedited":"21/08/2024",
|
||||
"language":"Catalan"
|
||||
"language":"Catalan",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"DJj123dj",
|
||||
"translators":["DJj123dj"],
|
||||
"lastedited":"21/08/2024",
|
||||
"language":"Custom"
|
||||
"language":"Custom",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"spyeye_",
|
||||
"translators":["spyeye_"],
|
||||
"lastedited":"21/08/2024",
|
||||
"language":"Czech"
|
||||
"language":"Czech",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"DJj123dj",
|
||||
"translators":["DJj123dj"],
|
||||
"lastedited":"21/08/2024",
|
||||
"language":"Dutch"
|
||||
"language":"Dutch",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"DJj123dj",
|
||||
"translators":["DJj123dj"],
|
||||
"lastedited":"21/08/2024",
|
||||
"language":"English"
|
||||
"language":"English",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"benzorich",
|
||||
"translators":["benzorich"],
|
||||
"lastedited":"22/08/2024",
|
||||
"language":"German"
|
||||
"language":"German",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"Kornel0706",
|
||||
"translators":["Kornel0706"],
|
||||
"lastedited":"22/08/2024",
|
||||
"language":"Hungarian"
|
||||
"language":"Hungarian",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"erxg",
|
||||
"translators":["erxg"],
|
||||
"lastedited":"25/08/2024",
|
||||
"language":"Indonesian"
|
||||
"language":"Indonesian",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"quiradon",
|
||||
"translators":["quiradon"],
|
||||
"lastedited":"20/08/2024",
|
||||
"language":"Portuguese"
|
||||
"language":"Portuguese",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"SankeDev",
|
||||
"translators":["SankeDev"],
|
||||
"lastedited":"27/08/2024",
|
||||
"language":"Romanian"
|
||||
"language":"Romanian",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"Redactado & Josuens",
|
||||
"translators":["Redactado","Josuens"],
|
||||
"lastedited":"22/08/2024",
|
||||
"language":"Spanish"
|
||||
"language":"Spanish",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"_TRANSLATION":{
|
||||
"otversion":"v4.0.0",
|
||||
"translator":"Anderskiy",
|
||||
"translators":["Anderskiy"],
|
||||
"lastedited":"31/08/2024",
|
||||
"language":"Ukrainian"
|
||||
"language":"Ukrainian",
|
||||
"automated":false
|
||||
},
|
||||
"checker":{
|
||||
"system":{
|
||||
|
||||
@@ -882,7 +882,7 @@ const blacklistEmbeds = () => {
|
||||
const {user} = params
|
||||
|
||||
const renderedUsers: string[] = []
|
||||
openticket.blacklist.getAll().forEach((blacklist) => renderedUsers.push(discord.userMention(blacklist.id.value)+" - "+(blacklist.reason ? blacklist.reason : "/")))
|
||||
openticket.blacklist.forEach((blacklist,id) => {renderedUsers.push(discord.userMention(id.value)+" - "+(blacklist.reason ? blacklist.reason : "/"))})
|
||||
|
||||
instance.setAuthor(user.displayName,user.displayAvatarURL())
|
||||
instance.setColor(generalConfig.data.mainColor)
|
||||
|
||||
@@ -370,6 +370,12 @@ export class ODManager<DataType extends ODManagerData> extends ODManagerChangeHe
|
||||
getIds(): ODId[] {
|
||||
return this.#data.map((d) => d.id)
|
||||
}
|
||||
/**Run an iterator over all data in this manager. This method also supports async-await behaviour!*/
|
||||
async forEach(cb:(data:DataType,id:ODId) => ODPromiseVoid): Promise<void> {
|
||||
for (const data of this.getAll()){
|
||||
await cb(data,data.id)
|
||||
}
|
||||
}
|
||||
/**Use the open ticket debugger in this manager for logs*/
|
||||
useDebug(debug?:ODDebugger, debugname?:string){
|
||||
this.#debug = debug
|
||||
|
||||
@@ -65,7 +65,7 @@ export class ODCheckerManager extends ODManager<ODChecker> {
|
||||
if (!res.valid) isValid = false
|
||||
})
|
||||
|
||||
this.functions.getAll().forEach((func) => {
|
||||
this.functions.forEach((func) => {
|
||||
const res = func.func(this,this.functions)
|
||||
final.push(...res.messages)
|
||||
|
||||
@@ -1209,7 +1209,7 @@ export class ODCheckerCustomStructure_EmojiString extends ODCheckerStringStructu
|
||||
}else if (!allowCustomDiscordEmoji && /<a?:[^:]*:[0-9]+>/.test(value)){
|
||||
checker.createMessage("openticket:emoji-custom","error",`This emoji can't be a custom discord emoji!`,lt,null,[],this.id,(this.options.docs ?? null))
|
||||
return false
|
||||
}else if (!/^(?:(?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])|(?:<a?:[^:]*:[0-9]+>))*$/.test(value)){
|
||||
}else if (!/^(?:\p{Emoji}|\p{Emoji_Component}|(?:<a?:[^:]*:[0-9]+>))*$/u.test(value)){
|
||||
checker.createMessage("openticket:emoji-invalid","error","This is an invalid emoji!",lt,null,[],this.id,(this.options.docs ?? null))
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ export class ODClientActivityManager {
|
||||
this.status = status
|
||||
}
|
||||
|
||||
/**When initiating the status, the bot starts updating the status using `discord.js`. Returns if succesfull or not. */
|
||||
/**When initiating the status, the bot starts updating the status using `discord.js`. Returns `true` when successfull. */
|
||||
initStatus(): boolean {
|
||||
if (this.initiated || !this.manager.ready) return false
|
||||
this.#updateClientActivity(this.type,this.text)
|
||||
@@ -496,7 +496,7 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
|
||||
const existing: {cmd:ODSlashCommand, requiresUpdate:boolean}[] = []
|
||||
const nonExisting: ODSlashCommand[] = []
|
||||
|
||||
this.getAll().forEach((cmd) => {
|
||||
this.forEach((cmd) => {
|
||||
if (guildId && cmd.guildId != guildId) return
|
||||
const result = cmds.find((cmddata) => cmddata.name == cmd.name)
|
||||
if (result){
|
||||
@@ -977,7 +977,7 @@ export class ODTextCommandManager extends ODManager<ODTextCommand> {
|
||||
|
||||
//filter commands for correct prefix
|
||||
const validPrefixCommands: {cmd:ODTextCommand,newContent:string}[] = []
|
||||
this.getAll().forEach((cmd) => {
|
||||
this.forEach((cmd) => {
|
||||
if (msg.content.startsWith(cmd.builder.prefix)) validPrefixCommands.push({
|
||||
cmd:cmd,
|
||||
newContent:msg.content.substring(cmd.builder.prefix.length)
|
||||
|
||||
@@ -86,15 +86,46 @@ export class ODConfig extends ODManagerData {
|
||||
* const config = new api.ODJsonConfig("plugin-config","test.json","./plugins/testplugin/")
|
||||
*/
|
||||
export class ODJsonConfig extends ODConfig {
|
||||
/**An array of listeners to run when the config gets reloaded. These are not executed on the initial loading. */
|
||||
#reloadListeners: Function[] = []
|
||||
|
||||
constructor(id:ODValidId, file:string, customPath?:string){
|
||||
super(id)
|
||||
try {
|
||||
this.file = (file.endsWith(".json")) ? file : file+".json"
|
||||
this.path = customPath ? nodepath.join("./",customPath,this.file) : nodepath.join("./config/",this.file)
|
||||
this.file = (file.endsWith(".json")) ? file : file+".json"
|
||||
this.path = customPath ? nodepath.join("./",customPath,this.file) : nodepath.join("./config/",this.file)
|
||||
|
||||
if (!fs.existsSync(this.path)) throw new ODSystemError("Unable to parse config \""+nodepath.join("./",this.path)+"\", the file doesn't exist!")
|
||||
try{
|
||||
this.data = JSON.parse(fs.readFileSync(this.path).toString())
|
||||
}catch(err){
|
||||
process.emit("uncaughtException",err)
|
||||
throw new ODSystemError("Config \""+nodepath.join("./",customPath ?? "./config/",file)+"\" doesn't exist!")
|
||||
throw new ODSystemError("Unable to parse config \""+nodepath.join("./",this.path)+"\"!")
|
||||
}
|
||||
}
|
||||
|
||||
/**Reload the JSON file. Be aware that this doesn't update classes that used individual parts of the config data! */
|
||||
reload(){
|
||||
if (!fs.existsSync(this.path)) throw new ODSystemError("Unable to reload config \""+nodepath.join("./",this.path)+"\", the file doesn't exist!")
|
||||
try{
|
||||
this.data = JSON.parse(fs.readFileSync(this.path).toString())
|
||||
this.#reloadListeners.forEach((cb) => {
|
||||
try{
|
||||
cb()
|
||||
}catch(err){
|
||||
process.emit("uncaughtException",err)
|
||||
}
|
||||
})
|
||||
}catch(err){
|
||||
process.emit("uncaughtException",err)
|
||||
throw new ODSystemError("Unable to reload config \""+nodepath.join("./",this.path)+"\"!")
|
||||
}
|
||||
}
|
||||
/**Listen for a reload of this JSON file! */
|
||||
onReload(cb:Function){
|
||||
this.#reloadListeners.push(cb)
|
||||
}
|
||||
/**Remove all reload listeners. Not recommended! */
|
||||
removeAllReloadListeners(){
|
||||
this.#reloadListeners = []
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ export class ODCounterCooldown extends ODCooldown<{value:number}> {
|
||||
async init(){
|
||||
if (this.ready) return
|
||||
setInterval(() => {
|
||||
this.data.getAll().forEach((cooldown) => {
|
||||
this.data.forEach((cooldown) => {
|
||||
cooldown.data.value = cooldown.data.value - this.decrement
|
||||
if (cooldown.data.value <= this.cancelLimit){
|
||||
cooldown.active = false
|
||||
@@ -217,7 +217,7 @@ export class ODIncrementalCounterCooldown extends ODCooldown<{value:number}> {
|
||||
async init(){
|
||||
if (this.ready) return
|
||||
setInterval(() => {
|
||||
this.data.getAll().forEach((cooldown) => {
|
||||
this.data.forEach((cooldown) => {
|
||||
cooldown.data.value = cooldown.data.value - this.decrement
|
||||
if (cooldown.data.value <= this.cancelLimit){
|
||||
cooldown.active = false
|
||||
|
||||
@@ -66,7 +66,7 @@ export class ODFlagManager extends ODManager<ODFlag> {
|
||||
|
||||
/**Set all flags to their `process.argv` value. */
|
||||
init(){
|
||||
this.getAll().forEach((flag) => {
|
||||
this.forEach((flag) => {
|
||||
flag.detectProcessParams(false)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,28 +6,33 @@ import nodepath from "path"
|
||||
import { ODDebugger } from "./console"
|
||||
import fs from "fs"
|
||||
|
||||
export interface ODLanguageMetadata {
|
||||
otversion:string,
|
||||
language:string,
|
||||
translators:string[],
|
||||
lastedited:string,
|
||||
automated:boolean
|
||||
}
|
||||
|
||||
export class ODLanguage extends ODManagerData {
|
||||
/**The name of the file with `.json` extension. */
|
||||
file: string
|
||||
/**The path to the file relative to the main directory. */
|
||||
path: string
|
||||
data: any
|
||||
metadata: {
|
||||
otversion:string,
|
||||
language:string,
|
||||
translator:string,
|
||||
lastedited:string
|
||||
}|null = null
|
||||
metadata: ODLanguageMetadata|null = null
|
||||
|
||||
constructor(id:ODValidId, file:string, customPath?:string){
|
||||
super(id)
|
||||
this.file = (file.endsWith(".json")) ? file : file+".json"
|
||||
this.path = customPath ? nodepath.join("./",customPath,this.file) : nodepath.join("./languages/",this.file)
|
||||
|
||||
if (!fs.existsSync(this.path)) throw new ODSystemError("Unable to parse language \""+nodepath.join("./",this.path)+"\", the file doesn't exist!")
|
||||
try{
|
||||
this.file = (file.endsWith(".json")) ? file : file+".json"
|
||||
this.path = customPath ? nodepath.join("./",customPath,this.file) : nodepath.join("./languages/",this.file)
|
||||
this.data = JSON.parse(fs.readFileSync(this.path).toString())
|
||||
}catch(err){
|
||||
process.emit("uncaughtException",err)
|
||||
throw new ODSystemError("Language \""+nodepath.join("./",customPath ?? "./languages/",file)+"\" doesn't exist!")
|
||||
throw new ODSystemError("Unable to parse language \""+nodepath.join("./",this.path)+"\"!")
|
||||
}
|
||||
if (this.data["_TRANSLATION"]) this.metadata = this.data["_TRANSLATION"]
|
||||
}
|
||||
@@ -36,27 +41,41 @@ export class ODLanguage extends ODManagerData {
|
||||
export class ODLanguageManager extends ODManager<ODLanguage> {
|
||||
current: ODLanguage|null = null
|
||||
backup: ODLanguage|null = null
|
||||
#debug: ODDebugger
|
||||
|
||||
constructor(debug:ODDebugger, presets:boolean){
|
||||
super(debug,"language")
|
||||
if (presets) this.add(new ODLanguage("english","english.json"))
|
||||
this.current = presets ? new ODLanguage("english","english.json") : null
|
||||
this.backup = presets ? new ODLanguage("english","english.json") : null
|
||||
this.#debug = debug
|
||||
}
|
||||
|
||||
setCurrentLanguage(id:ODValidId){
|
||||
this.current = this.get(id)
|
||||
const languageId = this.current?.id.value ?? "<unknown-id>"
|
||||
const languageAutomated = this.current?.metadata?.automated.toString() ?? "<unknown-metadata>"
|
||||
this.#debug.debug("Selected current language",[
|
||||
{key:"id",value:languageId},
|
||||
{key:"automated",value:languageAutomated},
|
||||
])
|
||||
}
|
||||
getCurrentLanguage(){
|
||||
return (this.current) ? this.current : null
|
||||
}
|
||||
setBackupLanguage(id:ODValidId){
|
||||
this.backup = this.get(id)
|
||||
const languageId = this.backup?.id.value ?? "<unknown-id>"
|
||||
const languageAutomated = this.backup?.metadata?.automated.toString() ?? "<unknown-metadata>"
|
||||
this.#debug.debug("Selected backup language",[
|
||||
{key:"id",value:languageId},
|
||||
{key:"automated",value:languageAutomated},
|
||||
])
|
||||
}
|
||||
getBackupLanguage(){
|
||||
return (this.backup) ? this.backup : null
|
||||
}
|
||||
getLanguageMetadata(frombackup?:boolean){
|
||||
getLanguageMetadata(frombackup?:boolean): ODLanguageMetadata|null {
|
||||
if (frombackup) return (this.backup) ? this.backup.metadata : null
|
||||
return (this.current) ? this.current.metadata : null
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ const preloadMigrationContext = async () => {
|
||||
|
||||
const unloadMigrationContext = async () => {
|
||||
openticket.debug.visible = false
|
||||
openticket.databases.getAll().forEach((database) => openticket.databases.remove(database.id))
|
||||
openticket.configs.getAll().forEach((config) => openticket.configs.remove(config.id))
|
||||
openticket.flags.getAll().forEach((flag) => openticket.flags.remove(flag.id))
|
||||
openticket.databases.forEach((database,id) => {openticket.databases.remove(id)})
|
||||
openticket.configs.forEach((config,id) => {openticket.configs.remove(id)})
|
||||
openticket.flags.forEach((flag,id) => {openticket.flags.remove(id)})
|
||||
openticket.debug.debug("-- MIGRATION CONTEXT END --")
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ const loadAllVersionMigrations = async (lastVersion:api.ODVersion) => {
|
||||
const saveAllVersionsToDatabase = async () => {
|
||||
const globalDatabase = openticket.databases.get("openticket:global")
|
||||
|
||||
openticket.versions.getAll().forEach((version) => {
|
||||
globalDatabase.set("openticket:last-version",version.id.value,version.toString())
|
||||
openticket.versions.forEach((version,id) => {
|
||||
globalDatabase.set("openticket:last-version",id.value,version.toString())
|
||||
})
|
||||
}
|
||||
@@ -135,9 +135,9 @@ export const loadDatabaseCleanersCode = async () => {
|
||||
//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)
|
||||
openticket.options.forEach((option,id) => {
|
||||
if (optionDatabase.exists("openticket:used-option",id.value) && !openticket.tickets.getAll().some((ticket) => ticket.id.value == id.value)){
|
||||
optionDatabase.delete("openticket:used-option",id.value)
|
||||
}
|
||||
})
|
||||
}))
|
||||
@@ -331,9 +331,9 @@ export const loadDatabaseSaversCode = async () => {
|
||||
}
|
||||
|
||||
//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.options.forEach((option,id) => {
|
||||
if (optionDatabase.exists("openticket:used-option",id.value) && !openticket.tickets.getAll().some((ticket) => ticket.id.value == id.value)){
|
||||
optionDatabase.delete("openticket:used-option",id.value)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {openticket, api, utilities} from "../../index"
|
||||
|
||||
export const loadAllCooldowns = async () => {
|
||||
openticket.options.getAll().forEach((option) => {
|
||||
openticket.options.forEach((option) => {
|
||||
if (!(option instanceof api.ODTicketOption)) return
|
||||
loadTicketOptionCooldown(option)
|
||||
})
|
||||
|
||||
@@ -2,8 +2,8 @@ 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: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"]))
|
||||
|
||||
@@ -30,7 +30,7 @@ export const loadAllPermissions = async () => {
|
||||
})
|
||||
|
||||
//TICKET ADMINS
|
||||
openticket.tickets.getAll().forEach(async (ticket) => {
|
||||
openticket.tickets.forEach(async (ticket) => {
|
||||
try {
|
||||
const channel = await openticket.client.fetchGuildTextChannel(mainServer,ticket.id.value)
|
||||
if (!channel) return
|
||||
|
||||
@@ -15,6 +15,42 @@ export const loadAllOptions = async () => {
|
||||
openticket.options.add(loadRoleOption(option))
|
||||
}
|
||||
})
|
||||
|
||||
//update options on config reload
|
||||
optionConfig.onReload(async () => {
|
||||
//clear previous options
|
||||
openticket.options.forEach((data,id) => {openticket.options.remove(id)})
|
||||
|
||||
//add new options
|
||||
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))
|
||||
}
|
||||
})
|
||||
|
||||
//update options in tickets
|
||||
openticket.tickets.forEach((ticket) => {
|
||||
const optionId = ticket.option.id
|
||||
const option = openticket.options.get(optionId)
|
||||
if (option && option instanceof api.ODTicketOption) ticket.option = option
|
||||
else{
|
||||
openticket.log("Unable to move ticket to unexisting option due to config reload!","warning",[
|
||||
{key:"channelid",value:ticket.id.value},
|
||||
{key:"option",value:optionId.value}
|
||||
])
|
||||
}
|
||||
})
|
||||
|
||||
//update roles on config reload
|
||||
openticket.roles.forEach((data,id) => {openticket.roles.remove(id)})
|
||||
await (await import("./roleLoader.js")).loadAllRoles()
|
||||
})
|
||||
}
|
||||
|
||||
export const loadTicketOption = (option:api.ODJsonConfig_DefaultOptionTicketType): api.ODTicketOption => {
|
||||
|
||||
@@ -8,6 +8,17 @@ export const loadAllPanels = async () => {
|
||||
panelConfig.data.forEach((panel) => {
|
||||
openticket.panels.add(loadPanel(panel))
|
||||
})
|
||||
|
||||
//update panels on config reload
|
||||
panelConfig.onReload(async () => {
|
||||
//clear previous panels
|
||||
openticket.panels.forEach((data,id) => {openticket.panels.remove(id)})
|
||||
|
||||
//add new panels
|
||||
panelConfig.data.forEach((panel) => {
|
||||
openticket.panels.add(loadPanel(panel))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const loadPanel = (panel:api.ODJsonConfig_DefaultPanelType) => {
|
||||
|
||||
@@ -11,6 +11,21 @@ export const loadAllQuestions = async () => {
|
||||
openticket.questions.add(loadParagraphQuestion(question))
|
||||
}
|
||||
})
|
||||
|
||||
//update questions on config reload
|
||||
questionConfig.onReload(() => {
|
||||
//clear previous questions
|
||||
openticket.questions.forEach((data,id) => {openticket.questions.remove(id)})
|
||||
|
||||
//add new questions
|
||||
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) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {openticket, api, utilities} from "../../index"
|
||||
|
||||
export const loadAllRoles = async () => {
|
||||
openticket.options.getAll().forEach((opt) => {
|
||||
openticket.options.forEach((opt) => {
|
||||
if (opt instanceof api.ODRoleOption){
|
||||
openticket.roles.add(loadRole(opt))
|
||||
}
|
||||
|
||||
@@ -732,6 +732,10 @@ const main = async () => {
|
||||
await openticket.events.get("onStartScreenRender").emit([openticket.startscreen])
|
||||
if (openticket.defaults.getDefault("startScreenRendering")){
|
||||
await openticket.startscreen.renderAllComponents()
|
||||
if (openticket.languages.getLanguageMetadata(false)?.automated){
|
||||
openticket.log("You are currently using a language which has been translated by Google Translate!","warning")
|
||||
openticket.log("Please help us improve the translation by contributing to our project!","warning")
|
||||
}
|
||||
|
||||
await openticket.events.get("afterStartScreensRendered").emit([openticket.startscreen])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user